SequenceExtensions
Provides LINQ extensions methods for Sequence and Element.
public static class SequenceExtensions
Inheritance Object → SequenceExtensions
Methods
ToSequence(IEnumerable<Element>)
Builds a Sequence object from the set of elements.
public static Sequence ToSequence(IEnumerable<Element> elements)
Parameters
elements
IEnumerable<Element>
Set of elements composing the sequence. Must be in uninterrupted order.
Returns
ToSequence(IEnumerable<Element>, Rational, Rational, Nullable<Rational>)
Builds a Sequence object from the set of elements. Fills the gaps within [fillFrom, fillTo[ with .
public static Sequence ToSequence(IEnumerable<Element> elements, Rational fillFrom, Rational fillTo, Nullable<Rational> fillWith)
Parameters
elements
IEnumerable<Element>
Partial set of elements composing the sequence. Must be ordered, but can have gaps.
fillFrom
Rational
Left inclusive endpoint of the filling interval.
fillTo
Rational
Right exclusive endpoint of the filling interval.
fillWith
Nullable<Rational>
The value filled in. Defaults to
Returns
Cut(IEnumerable<Element>, Rational, Rational, Boolean, Boolean)
Returns a cut of the sequence for a smaller support.
Optimized for minimal allocations
public static IEnumerable<Element> Cut(IEnumerable<Element> elements, Rational cutStart, Rational cutEnd, bool isStartIncluded, bool isEndIncluded)
Parameters
elements
IEnumerable<Element>
cutStart
Rational
Left endpoint of the new support.
cutEnd
Rational
Right endpoint of the new support.
isStartIncluded
Boolean
If true, the support is left-closed.
isEndIncluded
Boolean
If true, the support is right-closed.
Returns
Exceptions
ArgumentException
Thrown if the new support is not a subset of the current one.
Fill(IEnumerable<Element>, Rational, Rational, Boolean, Boolean, Nullable<Rational>)
Fills the gaps of the set of elements within fillFrom
and fillTo
with the given value, defaults to .
public static IEnumerable<Element> Fill(IEnumerable<Element> elements, Rational fillFrom, Rational fillTo, bool isFromIncluded, bool isToIncluded, Nullable<Rational> fillWith)
Parameters
elements
IEnumerable<Element>
The set of elements. Must be in order.
fillFrom
Rational
Left endpoint of the filling interval.
fillTo
Rational
Right endpoint of the filling interval.
isFromIncluded
Boolean
If true, left endpoint is inclusive.
isToIncluded
Boolean
If true, right endpoint is inclusive.
fillWith
Nullable<Rational>
The value filled in. Defaults to
Returns
Merge(IReadOnlyList<Element>, Boolean, ComputationSettings)
Applies merge, whenever possible, to a set of elements. The result is the minimal set, in number of elements, to represent the same information.
public static List<Element> Merge(IReadOnlyList<Element> elements, bool doSort, ComputationSettings settings)
Parameters
elements
IReadOnlyList<Element>
The elements to merge.
doSort
Boolean
If true, the elements are sorted before attempting to merge.
settings
ComputationSettings
Settings to forward to SortElements, if used.
Returns
List<Element>
A set where no further merges are possible.
MergeAsEnumerable(IEnumerable<Element>)
Applies merge, whenever possible, to a set of elements. The result is the minimal set, in number of elements, to represent the same information.
Optimized for minimal allocations
public static IEnumerable<Element> MergeAsEnumerable(IEnumerable<Element> elements)
Parameters
elements
IEnumerable<Element>
The elements to merge, must be sorted
Returns
IEnumerable<Element>
A set where no further merges are possible.
GetElementAt(IEnumerable<Element>, Rational)
Returns the Element that describes the sequence in time
.
This method is implemented using a linear search,
public static Element GetElementAt(IEnumerable<Element> elements, Rational time)
Parameters
elements
IEnumerable<Element>
time
Rational
Time of the sample.
Returns
Element
The describing the sequence at .
Exceptions
ArgumentException
Thrown if the given time is out of sequence support.
GetSegmentBefore(IEnumerable<Element>, Rational)
Returns the Segment that describes the sequence before time
.
This method is implemented using a linear search,
public static Segment GetSegmentBefore(IEnumerable<Element> elements, Rational time)
Parameters
elements
IEnumerable<Element>
time
Rational
Time of the sample.
Returns
Segment
The describing the sequence before .
Exceptions
ArgumentException
Thrown if the given time is out of sequence support.
GetSegmentAfter(IEnumerable<Element>, Rational)
Returns the Segment that describes the sequence after time
.
This method is implemented using a linear search,
public static Segment GetSegmentAfter(IEnumerable<Element> elements, Rational time)
Parameters
elements
IEnumerable<Element>
time
Rational
Time of the sample.
Returns
Segment
The describing the sequence after .
Exceptions
ArgumentException
Thrown if the given time is out of sequence support.
AreInTimeOrder(IEnumerable<Element>)
Checks if time order is respected, i.e. they are ordered first by start, then by end.
public static bool AreInTimeOrder(IEnumerable<Element> elements)
Parameters
elements
IEnumerable<Element>
Returns
AreInTimeSequence(IEnumerable<Element>)
Checks if the elements form a sequence. In addition to AreInTimeOrder(IEnumerable<Element>) it requires non-overlapping, but it allows gaps.
public static bool AreInTimeSequence(IEnumerable<Element> elements)
Parameters
elements
IEnumerable<Element>
Returns
AreUninterruptedSequence(IEnumerable<Element>)
Checks if the elements form a uninterrupted sequence.
public static bool AreUninterruptedSequence(IEnumerable<Element> elements)
Parameters
elements
IEnumerable<Element>
Returns
SortElements(IReadOnlyList<Element>, ComputationSettings)
Sorts the elements in time order.
public static IReadOnlyList<Element> SortElements(IReadOnlyList<Element> elements, ComputationSettings settings)
Parameters
elements
IReadOnlyList<Element>
settings
ComputationSettings
Returns
EnumerateBreakpoints(Sequence)
Enumerates a Sequence as a series of breakpoints.
Does not attempt merging.
public static IEnumerable<ValueTuple<Segment, Point, Segment>> EnumerateBreakpoints(Sequence sequence)
Parameters
sequence
Sequence
Returns
IEnumerable<ValueTuple<Segment, Point, Segment>>
EnumerateBreakpoints(IEnumerable<Element>)
Enumerates a set of Elements as a series of breakpoints.
Does not attempt merging.
public static IEnumerable<ValueTuple<Segment, Point, Segment>> EnumerateBreakpoints(IEnumerable<Element> elements)
Parameters
elements
IEnumerable<Element>
The elements to enumerate, must be sorted.
Returns
IEnumerable<ValueTuple<Segment, Point, Segment>>
GetBreakpointValues(ValueTuple<Segment, Point, Segment>)
Enumerates the left-limit, the value and right-limit at the breakpoint.
public static IEnumerable<Rational> GetBreakpointValues(ValueTuple<Segment, Point, Segment> breakpoint)
Parameters
breakpoint
ValueTuple<Segment, Point, Segment>
Returns
GetBreakpointsValues(IEnumerable<ValueTuple<Segment, Point, Segment>>)
Enumerates, for each breakpoint, the left-limit, the value and right-limit at the breakpoint.
public static IEnumerable<Rational> GetBreakpointsValues(IEnumerable<ValueTuple<Segment, Point, Segment>> breakpoints)
Parameters
breakpoints
IEnumerable<ValueTuple<Segment, Point, Segment>>
Returns
IsContinuous(IEnumerable<Element>)
True if there is no discontinuity within the sequence.
public static bool IsContinuous(IEnumerable<Element> elements)
Parameters
elements
IEnumerable<Element>
Returns
IsLeftContinuous(IEnumerable<Element>)
True if there is no left-discontinuity within the sequence.
public static bool IsLeftContinuous(IEnumerable<Element> elements)
Parameters
elements
IEnumerable<Element>
Returns
IsRightContinuous(IEnumerable<Element>)
True if there is no right-discontinuity within the sequence.
public static bool IsRightContinuous(IEnumerable<Element> elements)
Parameters
elements
IEnumerable<Element>
Returns
IsNonNegative(IEnumerable<Element>)
True if the sequence is non-negative, i.e. for any .
public static bool IsNonNegative(IEnumerable<Element> elements)
Parameters
elements
IEnumerable<Element>
Returns
IsNonDecreasing(IEnumerable<Element>)
True if for any , .
public static bool IsNonDecreasing(IEnumerable<Element> elements)
Parameters
elements
IEnumerable<Element>
Returns
IsIncreasing(IEnumerable<Element>)
True if for any , .
public static bool IsIncreasing(IEnumerable<Element> elements)
Parameters
elements
IEnumerable<Element>
Returns
IsFinite(IEnumerable<Element>)
True if for any , .
public static bool IsFinite(IEnumerable<Element> elements)
Parameters
elements
IEnumerable<Element>
Returns
IsMinusInfinite(IEnumerable<Element>)
True if for any , .
public static bool IsMinusInfinite(IEnumerable<Element> elements)
Parameters
elements
IEnumerable<Element>
Returns
IsPlusInfinite(IEnumerable<Element>)
True if for any , .
public static bool IsPlusInfinite(IEnumerable<Element> elements)
Parameters
elements
IEnumerable<Element>
Returns
SupValue(IEnumerable<Element>)
If the sequence is upper-bounded, i.e., exists such that for any , returns . Otherwise, returns .
public static Rational SupValue(IEnumerable<Element> elements)
Parameters
elements
IEnumerable<Element>
Returns
InfValue(IEnumerable<Element>)
If the sequence is lower-bounded, i.e., exists such that for any , returns . Otherwise, returns .
public static Rational InfValue(IEnumerable<Element> elements)
Parameters
elements
IEnumerable<Element>
Returns
ToLeftContinuous(IEnumerable<Element>)
Computes a left-continuous version of this sequence.
public static IEnumerable<Element> ToLeftContinuous(IEnumerable<Element> elements)
Parameters
elements
IEnumerable<Element>
Returns
ToRightContinuous(IEnumerable<Element>)
Computes a right-continuous version of this sequence.
public static IEnumerable<Element> ToRightContinuous(IEnumerable<Element> elements)
Parameters
elements
IEnumerable<Element>
Returns
LowerPseudoInverse(IEnumerable<Element>, Boolean)
Computes the lower pseudo-inverse function, .
The result of this operation is left-continuous, thus is revertible, i.e. , only if is left-continuous. See [DNC18] § 3.2.1
public static IEnumerable<Element> LowerPseudoInverse(IEnumerable<Element> elements, bool startFromZero)
Parameters
elements
IEnumerable<Element>
startFromZero
Boolean
If true, it is assumed that be defined from .
Returns
Exceptions
ArgumentException
If the curve is not non-decreasing.
ArgumentException
If the collection is empty.
UpperPseudoInverse(IEnumerable<Element>, Boolean)
Computes the upper pseudo-inverse function, .
The result of this operation is right-continuous, thus is revertible, i.e. , only if is right-continuous. See [DNC18] § 3.2.1
public static IEnumerable<Element> UpperPseudoInverse(IEnumerable<Element> elements, bool startFromZero)
Parameters
elements
IEnumerable<Element>
startFromZero
Boolean
If true, it is assumed that be defined from .
Returns
Exceptions
ArgumentException
If the curve is not non-decreasing.
ArgumentException
If the collection is empty.
LowerEnvelope(IReadOnlyList<Element>, ComputationSettings)
Computes the lower envelope of the set of elements given. complexity.
Used for convolution
public static List<Element> LowerEnvelope(IReadOnlyList<Element> elements, ComputationSettings settings)
Parameters
elements
IReadOnlyList<Element>
settings
ComputationSettings
Returns
LowerEnvelope(IReadOnlyList<Sequence>, ComputationSettings)
Computes the lower envelope of the set of sequences given.
Used for partitioned convolution.
public static IReadOnlyList<Element> LowerEnvelope(IReadOnlyList<Sequence> sequences, ComputationSettings settings)
Parameters
sequences
IReadOnlyList<Sequence>
settings
ComputationSettings
Returns
UpperEnvelope(IReadOnlyList<Element>, ComputationSettings)
Computes the upper envelope of the set of elements given. complexity.
Used for deconvolution
public static List<Element> UpperEnvelope(IReadOnlyList<Element> elements, ComputationSettings settings)
Parameters
elements
IReadOnlyList<Element>
settings
ComputationSettings
Returns
UpperEnvelope(IReadOnlyList<Sequence>, ComputationSettings)
Computes the lower envelope of the set of sequences given.
public static IReadOnlyList<Element> UpperEnvelope(IReadOnlyList<Sequence> sequences, ComputationSettings settings)
Parameters
sequences
IReadOnlyList<Sequence>
settings
ComputationSettings