Safe Haskell | Safe-Inferred |
---|

Generic functions over vectors of `Sample`

s.

The samples should be sorted, though this is currently not enforced by the constructors. TODO fix that

By default, this defines a piecewise-constant function, where each sample maintains its value until the next one. However, samples can have coincident Xs, and this is used for a linear segment based implementation built on top of this.

## Synopsis

- type UnboxedY = Double
- type Unboxed = Storable.Vector (Sample UnboxedY)
- type Boxed y = Vector.Vector (Sample y)
- x_to_double :: X -> Double
- double_to_x :: Double -> X
- to_foreign_ptr :: Storable a => Storable.Vector a -> (ForeignPtr a, Int)
- with_ptr :: Storable a => Storable.Vector a -> (Ptr a -> Int -> IO b) -> IO b
- index :: V.Vector v a => v a -> Int -> a
- head :: V.Vector v a => v a -> Maybe a
- last :: V.Vector v a => v a -> Maybe a
- uncons :: V.Vector v a => v a -> Maybe (a, v a)
- from_pairs :: V.Vector v (Sample y) => [(X, y)] -> v (Sample y)
- to_pairs :: V.Vector v (Sample y) => v (Sample y) -> [(X, y)]
- set :: V.Vector v (Sample y) => Maybe y -> X -> y -> v (Sample y)
- constant :: V.Vector v (Sample y) => y -> v (Sample y)
- constant_val :: Unboxed -> Maybe UnboxedY
- to_pair :: Sample y -> (X, y)
- check :: V.Vector v (Sample y) => v (Sample y) -> [String]
- merge_right :: V.Vector v (Sample y) => [v (Sample y)] -> v (Sample y)
- merge_left :: V.Vector v (Sample y) => [v (Sample y)] -> v (Sample y)
- prepend :: V.Vector v (Sample y) => v (Sample y) -> v (Sample y) -> v (Sample y)
- at :: V.Vector v (Sample y) => X -> v (Sample y) -> Maybe y
- sample_at :: V.Vector v (Sample y) => X -> v (Sample y) -> Maybe (X, y)
- before :: V.Vector v (Sample y) => X -> v (Sample y) -> Maybe (Sample y)
- ascending :: V.Vector v (Sample y) => X -> v (Sample y) -> [Sample y]
- descending :: V.Vector v (Sample y) => X -> v (Sample y) -> [Sample y]
- shift :: V.Vector v (Sample y) => X -> v (Sample y) -> v (Sample y)
- drop_at_after :: V.Vector v (Sample y) => X -> v (Sample y) -> v (Sample y)
- drop_after :: V.Vector v (Sample y) => X -> v (Sample y) -> v (Sample y)
- drop_before :: V.Vector v (Sample y) => X -> v (Sample y) -> v (Sample y)
- drop_before_strict :: V.Vector v (Sample y) => X -> v (Sample y) -> v (Sample y)
- drop_before_at :: V.Vector v (Sample y) => X -> v (Sample y) -> v (Sample y)
- within :: V.Vector v (Sample y) => X -> X -> v (Sample y) -> v (Sample y)
- map_x :: V.Vector v (Sample y) => (X -> X) -> v (Sample y) -> v (Sample y)
- map_y :: V.Vector v (Sample y) => (y -> y) -> v (Sample y) -> v (Sample y)
- map_err :: V.Vector v a => (a -> Either err a) -> v a -> (v a, [err])
- sig_op :: V.Vector v (Sample y) => y -> (y -> y -> y) -> v (Sample y) -> v (Sample y) -> v (Sample y)
- sig_op_poly :: y1 -> y2 -> (y1 -> y2 -> y3) -> Boxed y1 -> Boxed y2 -> Boxed y3
- resample1 :: (V.Vector v1 (Sample y1), V.Vector v2 (Sample y2)) => y1 -> y2 -> Int -> Int -> Int -> Int -> v1 (Sample y1) -> v2 (Sample y2) -> Maybe (X, y1, y2, Int, Int)
- find_nonascending :: V.Vector v (Sample y) => v (Sample y) -> [(X, y)]
- unfoldr :: V.Vector v (Sample y) => (state -> Maybe ((X, y), state)) -> state -> v (Sample y)
- y_at :: CallStack.Stack => X -> Double -> X -> Double -> X -> Double
- x_at :: X -> Double -> X -> Double -> Double -> Maybe X
- highest_index :: V.Vector v (Sample y) => X -> v (Sample y) -> Int
- bsearch_below_1 :: V.Vector v (Sample y) => X -> v (Sample y) -> Int
- index_below :: V.Vector v (Sample y) => X -> v (Sample y) -> Int
- bsearch_above :: V.Vector v (Sample y) => X -> v (Sample y) -> Int
- bsearch_below :: V.Vector v (Sample y) => X -> v (Sample y) -> Int
- type X = RealTime.RealTime
- data Sample y = Sample {}
- toList :: V.Vector v a => v a -> [a]
- all :: V.Vector v a => (a -> Bool) -> v a -> Bool
- foldl' :: V.Vector v b => (a -> b -> a) -> a -> v b -> a
- drop :: V.Vector v a => Int -> v a -> v a
- take :: V.Vector v a => Int -> v a -> v a
- unsafeIndex :: V.Vector v a => v a -> Int -> a
- null :: V.Vector v a => v a -> Bool
- length :: V.Vector v a => v a -> Int

# Documentation

type Boxed y = Vector.Vector (Sample y) Source #

x_to_double :: X -> Double Source #

double_to_x :: Double -> X Source #

to_foreign_ptr :: Storable a => Storable.Vector a -> (ForeignPtr a, Int) Source #

from_pairs :: V.Vector v (Sample y) => [(X, y)] -> v (Sample y) Source #

Construct a TimeVector from a list.

set :: V.Vector v (Sample y) => Maybe y -> X -> y -> v (Sample y) Source #

Set the signal value, with a discontinuity. See NOTE [signal-discontinuity].

check :: V.Vector v (Sample y) => v (Sample y) -> [String] Source #

TimeVectors should be sorted by the X value. Return warnings for where that's not true.

merge_right :: V.Vector v (Sample y) => [v (Sample y)] -> v (Sample y) Source #

This is a merge where the vectors to the right will win in the case of overlap.

merge_left :: V.Vector v (Sample y) => [v (Sample y)] -> v (Sample y) Source #

This is a merge where the vectors to the left will win in the case of overlap.

prepend :: V.Vector v (Sample y) => v (Sample y) -> v (Sample y) -> v (Sample y) Source #

When signals are `merge_left`

d, the later one overrides the first one.
This is the other way: the first one will override the second.

at :: V.Vector v (Sample y) => X -> v (Sample y) -> Maybe y Source #

Same as `sample_at`

, except don't return the X.

sample_at :: V.Vector v (Sample y) => X -> v (Sample y) -> Maybe (X, y) Source #

Find the sample at or before X. Nothing if the X is before the first sample.

before :: V.Vector v (Sample y) => X -> v (Sample y) -> Maybe (Sample y) Source #

Find the sample before the given X.

ascending :: V.Vector v (Sample y) => X -> v (Sample y) -> [Sample y] Source #

Samples at and above the given time.

descending :: V.Vector v (Sample y) => X -> v (Sample y) -> [Sample y] Source #

Descending samples, starting below the time.

shift :: V.Vector v (Sample y) => X -> v (Sample y) -> v (Sample y) Source #

Shift the signal in time.

drop_at_after :: V.Vector v (Sample y) => X -> v (Sample y) -> v (Sample y) Source #

Truncate a signal so it doesn't include the given X - RealTime.eta. It's just a view of the old signal, so it doesn't allocate a new signal.

drop_before :: V.Vector v (Sample y) => X -> v (Sample y) -> v (Sample y) Source #

Like `drop_before_strict`

, except if there is no sample at `x`

, keep one
sample before it to preserve the value at `x`

. If there are multiple
samples at `x`

, drop all but the last one. This is because they indicate
a discontinuity, but if you don't care about the previous value, then you
don't need the discontinuity.

drop_before_strict :: V.Vector v (Sample y) => X -> v (Sample y) -> v (Sample y) Source #

The reverse of `drop_at_after`

: trim a signal's head up until, but not
including, the given X.

drop_before_at :: V.Vector v (Sample y) => X -> v (Sample y) -> v (Sample y) Source #

Like `drop_before_strict`

, but also drop samples at the X.

within :: V.Vector v (Sample y) => X -> X -> v (Sample y) -> v (Sample y) Source #

Return samples to set the value at start and until end. This means samples start <= t < end, along with one < start if necessary to set the initial value, and the end sample if start == end.

map_err :: V.Vector v a => (a -> Either err a) -> v a -> (v a, [err]) Source #

A map that can return error msgs.

:: V.Vector v (Sample y) | |

=> y | The implicit y value of a vector before its first sample. It should probably be the identity for the operator. |

-> (y -> y -> y) | |

-> v (Sample y) | |

-> v (Sample y) | |

-> v (Sample y) |

Combine two vectors with the given function. They will be resampled so they have samples at the same time.

resample1 :: (V.Vector v1 (Sample y1), V.Vector v2 (Sample y2)) => y1 -> y2 -> Int -> Int -> Int -> Int -> v1 (Sample y1) -> v2 (Sample y2) -> Maybe (X, y1, y2, Int, Int) Source #

find_nonascending :: V.Vector v (Sample y) => v (Sample y) -> [(X, y)] Source #

Find samples whose `sx`

is <= the previous X.

unfoldr :: V.Vector v (Sample y) => (state -> Maybe ((X, y), state)) -> state -> v (Sample y) Source #

y_at :: CallStack.Stack => X -> Double -> X -> Double -> X -> Double Source #

Given a line defined by the two points, find the y at the given x.
Crashes if called on a vertical line (y0==y1). Yeah, it's inconsistent
with `x_at`

.

x_at :: X -> Double -> X -> Double -> Double -> Maybe X Source #

Given a line defined by the two points, find the x at the given y.

highest_index :: V.Vector v (Sample y) => X -> v (Sample y) -> Int Source #

Binary search for the highest index of the given X. So the next value is
guaranteed to be >X, if it exists. Return -1 if `x`

is before
the first element. `RealTime.eta`

is added to `x`

, so a sample that's
almost the same will still be considered a match.

bsearch_below_1 :: V.Vector v (Sample y) => X -> v (Sample y) -> Int Source #

`bsearch_below`

, but if you use it with take, it includes the first
element ==x. TODO not sure how to explain it.

index_below :: V.Vector v (Sample y) => X -> v (Sample y) -> Int Source #

Search for the last index or -1 if the first sample is alreadyx.

bsearch_above :: V.Vector v (Sample y) => X -> v (Sample y) -> Int Source #

Binary search for the index of the first element that is >x, or one past the end of the vector.

bsearch_below :: V.Vector v (Sample y) => X -> v (Sample y) -> Int Source #

Binary search for the index of the first element ==x, or the last one <x. So it will be <=x, or one past the end of the vector. If you ues it with take, it's everything <x.

type X = RealTime.RealTime Source #

#### Instances

Storable (Sample Double) Source # | |

Defined in Util.TimeVectorStorable sizeOf :: Sample Double -> Int # alignment :: Sample Double -> Int # peekElemOff :: Ptr (Sample Double) -> Int -> IO (Sample Double) # pokeElemOff :: Ptr (Sample Double) -> Int -> Sample Double -> IO () # peekByteOff :: Ptr b -> Int -> IO (Sample Double) # pokeByteOff :: Ptr b -> Int -> Sample Double -> IO () # | |

Show y => Show (Sample y) Source # | |

CStorable (Sample Double) Source # | |

Defined in Util.TimeVectorStorable sizeOf :: Sample Double -> Int # alignment :: Sample Double -> Int # peekElemOff :: Ptr (Sample Double) -> Int -> IO (Sample Double) # pokeElemOff :: Ptr (Sample Double) -> Int -> Sample Double -> IO () # peekByteOff :: Ptr b -> Int -> IO (Sample Double) # pokeByteOff :: Ptr b -> Int -> Sample Double -> IO () # | |

Eq y => Eq (Sample y) Source # | |

Pretty.Pretty y => Pretty.Pretty (Sample y) Source # | |

Serialize y => Serialize (Sample y) Source # | |

FromJSON (Sample Double) Source # | |

ToJSON (Sample Double) Source # | |

all :: V.Vector v a => (a -> Bool) -> v a -> Bool #

*O(n)* Check if all elements satisfy the predicate.

#### Examples

`>>>`

`import qualified Data.Vector as V`

`>>>`

True`V.all even $ V.fromList [2, 4, 12]`

`>>>`

False`V.all even $ V.fromList [2, 4, 13]`

`>>>`

True`V.all even (V.empty :: V.Vector Int)`

drop :: V.Vector v a => Int -> v a -> v a #

*O(1)* Yield all but the first `n`

elements without copying. The vector may
contain less than `n`

elements, in which case an empty vector is returned.

take :: V.Vector v a => Int -> v a -> v a #

*O(1)* Yield the first `n`

elements without copying. The vector may
contain less than `n`

elements, in which case it is returned unchanged.

unsafeIndex :: V.Vector v a => v a -> Int -> a #

*O(1)* Unsafe indexing without bounds checking.