Karya, built on 2020-11-26T21:03:17 (patch 23b5be2d53a9e8e7d6136cda5aae2849abe5cded)

Util.TimeVector

Description

Generic functions over vectors of Samples.

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

# Documentation

with_ptr :: Storable a => Storable.Vector a -> (Ptr a -> Int -> IO b) -> IO b Source #

index :: V.Vector v a => v a -> Int -> a Source #

head :: V.Vector v a => v a -> Maybe a Source #

last :: V.Vector v a => v a -> Maybe a Source #

uncons :: V.Vector v a => v a -> Maybe (a, v a) Source #

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

Construct a TimeVector from a list.

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

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].

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

to_pair :: Sample y -> (X, y) Source #

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_leftd, 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_after :: V.Vector v (Sample y) => X -> v (Sample y) -> v (Sample y) Source #

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_x :: V.Vector v (Sample y) => (X -> X) -> v (Sample y) -> v (Sample y) Source #

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

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

A map that can return error msgs.

Arguments

 :: 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.

sig_op_poly :: y1 -> y2 -> (y1 -> y2 -> y3) -> Boxed y1 -> Boxed y2 -> Boxed y3 Source #

Polymorphic variant of sig_op.

The signature is specialized to Boxed since you might as well use sig_op for Unboxed vectors.

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.

data Sample y Source #

Constructors

 Sample Fieldssx :: !X sy :: !y

#### Instances

Instances details
 Eq y => Eq (Sample y) # Instance detailsDefined in Util.TimeVectorStorable Methods(==) :: Sample y -> Sample y -> Bool #(/=) :: Sample y -> Sample y -> Bool # Show y => Show (Sample y) # Instance detailsDefined in Util.TimeVectorStorable MethodsshowsPrec :: Int -> Sample y -> ShowS #show :: Sample y -> String #showList :: [Sample y] -> ShowS # # Instance detailsDefined in Util.TimeVectorStorable MethodspeekElemOff :: 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 () #peek :: Ptr (Sample Double) -> IO (Sample Double) #poke :: Ptr (Sample Double) -> Sample Double -> IO () # # Instance detailsDefined in Util.TimeVectorStorable MethodspeekElemOff :: 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 () #peek :: Ptr (Sample Double) -> IO (Sample Double) #poke :: Ptr (Sample Double) -> Sample Double -> IO () # # Instance detailsDefined in Util.TimeVectorStorable MethodstoJSONList :: [Sample Double] -> Value # # Instance detailsDefined in Util.TimeVectorStorable Methods # Instance detailsDefined in Util.TimeVector Methodspretty :: Sample y -> Text Source #format :: Sample y -> Doc Source #formatList :: [Sample y] -> Doc Source # Serialize y => Serialize (Sample y) # Instance detailsDefined in Util.TimeVectorStorable Methodsget :: Get (Sample y) Source #

toList :: V.Vector v a => v a -> [a] #

O(n) Convert a vector to a list

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

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

foldl' :: V.Vector v b => (a -> b -> a) -> a -> v b -> a #

O(n) Left fold with strict accumulator

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

null :: V.Vector v a => v a -> Bool #

O(1) Test whether a vector is empty

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

O(1) Yield the length of the vector

# Orphan instances

 # Instance details Methodspretty :: Sample y -> Text Source #format :: Sample y -> Doc Source #formatList :: [Sample y] -> Doc Source #