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(this IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
Set of elements composing the sequence. Must be in uninterrupted order.
Returns
ToSequence(IEnumerable<Element>, Rational, Rational, Rational?)
Builds a Sequence object from the set of elements. Fills the gaps within [fillFrom, fillTo[ with .
public static Sequence ToSequence(this IEnumerable<Element> elements, Rational fillFrom, Rational fillTo, Rational? fillWith = null)
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 Rational?
The value filled in. Defaults to
Returns
Cut(IEnumerable<Element>, Rational, Rational, bool, bool)
Returns a cut of the sequence for a smaller support.
Optimized for minimal allocations
public static IEnumerable<Element> Cut(this IEnumerable<Element> elements, Rational cutStart, Rational cutEnd, bool isStartIncluded = true, bool isEndIncluded = false)
Parameters
elements IEnumerable<Element>
The elements to process.
cutStart Rational
Left endpoint of the new support.
cutEnd Rational
Right endpoint of the new support.
isStartIncluded bool
If true, the support is left-closed.
isEndIncluded bool
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, bool, bool, Rational?)
Fills the gaps of the set of elements within fillFrom and fillTo
with the given value, defaults to .
public static IEnumerable<Element> Fill(this IEnumerable<Element> elements, Rational fillFrom, Rational fillTo, bool isFromIncluded = true, bool isToIncluded = false, Rational? fillWith = null)
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 bool
If true, left endpoint is inclusive.
isToIncluded bool
If true, right endpoint is inclusive.
fillWith Rational?
The value filled in. Defaults to
Returns
IEnumerable<Element>
The result.
Merge(IReadOnlyList<Element>, bool, 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(this IReadOnlyList<Element> elements, bool doSort = false, ComputationSettings settings = null)
Parameters
elements IReadOnlyList<Element>
The elements to merge.
doSort bool
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(this 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(this IEnumerable<Element> elements, Rational time)
Parameters
elements IEnumerable<Element>
The elements to process.
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(this IEnumerable<Element> elements, Rational time)
Parameters
elements IEnumerable<Element>
The elements to process.
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(this IEnumerable<Element> elements, Rational time)
Parameters
elements IEnumerable<Element>
The elements to process.
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(this 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(this IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
Returns
AreUninterruptedSequence(IEnumerable<Element>)
Checks if the elements form a uninterrupted sequence.
public static bool AreUninterruptedSequence(this IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
Returns
SortElements(IReadOnlyList<Element>, ComputationSettings)
Sorts the elements in time order.
public static IReadOnlyList<Element> SortElements(this IReadOnlyList<Element> elements, ComputationSettings settings = null)
Parameters
elements IReadOnlyList<Element>
settings ComputationSettings
Returns
EnumerateBreakpoints(Sequence)
Enumerates a Sequence as a series of breakpoints.
Does not attempt merging.
public static IEnumerable<(Segment left, Point center, Segment right)> EnumerateBreakpoints(this Sequence sequence)
Parameters
sequence Sequence
The sequence to process.
Returns
IEnumerable<(Segment left, Point center, Segment right)>
EnumerateBreakpoints(IEnumerable<Element>)
Enumerates a set of Elements as a series of breakpoints.
Does not attempt merging.
public static IEnumerable<(Segment left, Point center, Segment right)> EnumerateBreakpoints(this IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
The elements to enumerate, must be sorted.
Returns
IEnumerable<(Segment left, Point center, Segment right)>
GetBreakpointBoundaryValues((Segment left, Point center, Segment right))
Enumerates the left-limit, the value and right-limit at the breakpoint.
public static IEnumerable<Rational> GetBreakpointBoundaryValues(this (Segment left, Point center, Segment right) breakpoint)
Parameters
breakpoint (Segment left, Point center, Segment right)
Returns
GetBreakpointsBoundaryValues(IEnumerable<(Segment left, Point center, Segment right)>)
Enumerates, for each breakpoint, the left-limit, the value and right-limit at the breakpoint.
public static IEnumerable<Rational> GetBreakpointsBoundaryValues(this IEnumerable<(Segment left, Point center, Segment right)> breakpoints)
Parameters
breakpoints IEnumerable<(Segment left, Point center, Segment right)>
Returns
GetElementsBoundaryValues(IEnumerable<Element>)
Enumerates for each point its value, and for each segment its right-limit at start and left-limit at end.
public static IEnumerable<Rational> GetElementsBoundaryValues(this IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
Returns
GetElementsBoundaryPairs(IEnumerable<Element>)
Enumerates for each point its time and value, and for each segment 1) its start time and right-limit at start, 2) its end time and left-limit at end.
The returned pairs are not points since, particularly for the pairs coming from segments, it is not given that the value is attained at that time.
public static IEnumerable<(Rational time, Rational value)> GetElementsBoundaryPairs(this IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
Returns
IEnumerable<(Rational time, Rational value)>
IsContinuous(IEnumerable<Element>)
True if there is no discontinuity within the sequence.
public static bool IsContinuous(this 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(this 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(this 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(this IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
Returns
IsNonDecreasing(IEnumerable<Element>)
True if for any , .
public static bool IsNonDecreasing(this IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
Returns
IsIncreasing(IEnumerable<Element>)
True if for any , .
public static bool IsIncreasing(this IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
Returns
IsFinite(IEnumerable<Element>)
True if for any , .
public static bool IsFinite(this IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
The elements to process.
Returns
bool
The result.
IsMinusInfinite(IEnumerable<Element>)
True if for any , .
public static bool IsMinusInfinite(this IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
The elements to process.
Returns
bool
The result.
IsPlusInfinite(IEnumerable<Element>)
True if for any , .
public static bool IsPlusInfinite(this IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
The elements to process.
Returns
bool
The result.
BreakpointSupValue((Segment left, Point center, Segment right))
If the sequence is upper-bounded around the breakpoint , i.e., exists such that for any , returns . Otherwise, returns .
public static Rational BreakpointSupValue(this (Segment left, Point center, Segment right) breakpoint)
Parameters
breakpoint (Segment left, Point center, Segment right)
Returns
SupValue(IEnumerable<Element>)
If the sequence is upper-bounded, i.e., exists such that for any , returns . Otherwise, returns .
public static Rational SupValue(this IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
Returns
SupArg(IEnumerable<Element>)
If the sequence is upper-bounded, i.e., exists such that for any , returns the first time around which gets close to (i.e., either it attains the value or has it as a limit). Otherwise, returns .
public static Rational SupArg(this IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
Returns
MaxValue(IEnumerable<Element>)
If the sequence has a maximum, i.e., exist and such that for any and , returns . Otherwise, returns null.
public static Rational? MaxValue(this IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
Returns
MaxValue(IReadOnlyCollection<Element>)
public static Rational? MaxValue(this IReadOnlyCollection<Element> elements)
Parameters
elements IReadOnlyCollection<Element>
Returns
MaxArg(IEnumerable<Element>)
If the sequence has a maximum, i.e., exist and such that for any and , returns . Otherwise, returns null.
public static Rational? MaxArg(this IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
Returns
MaxArg(IReadOnlyCollection<Element>)
public static Rational? MaxArg(this IReadOnlyCollection<Element> elements)
Parameters
elements IReadOnlyCollection<Element>
Returns
BreakpointInfValue((Segment left, Point center, Segment right))
If the sequence is upper-bounded around the breakpoint , i.e., exists such that for any , returns . Otherwise, returns .
public static Rational BreakpointInfValue(this (Segment left, Point center, Segment right) breakpoint)
Parameters
breakpoint (Segment left, Point center, Segment right)
Returns
InfValue(IEnumerable<Element>)
If the sequence is lower-bounded, i.e., exists such that for any , returns . Otherwise, returns .
public static Rational InfValue(this IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
Returns
InfArg(IEnumerable<Element>)
If the sequence is lower-bounded, i.e., exists such that for any , returns the first time around which gets close to (i.e., either it attains the value or has it as a limit). Otherwise, returns .
public static Rational InfArg(this IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
Returns
MinValue(IEnumerable<Element>)
If the sequence has a minimum, i.e., exist and such that for any and , returns . Otherwise, returns null.
public static Rational? MinValue(this IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
Returns
MinValue(IReadOnlyCollection<Element>)
public static Rational? MinValue(this IReadOnlyCollection<Element> elements)
Parameters
elements IReadOnlyCollection<Element>
Returns
MinArg(IEnumerable<Element>)
If the sequence has a minimum, i.e., exist and such that for any and , returns . Otherwise, returns null.
public static Rational? MinArg(this IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
Returns
MinArg(IReadOnlyCollection<Element>)
public static Rational? MinArg(this IReadOnlyCollection<Element> elements)
Parameters
elements IReadOnlyCollection<Element>
Returns
ToLeftContinuous(IEnumerable<Element>)
Computes a left-continuous version of this sequence.
public static IEnumerable<Element> ToLeftContinuous(this IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
Returns
ToRightContinuous(IEnumerable<Element>)
Computes a right-continuous version of this sequence.
public static IEnumerable<Element> ToRightContinuous(this IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
Returns
LowerPseudoInverse(IEnumerable<Element>, bool)
Computes the lower pseudo-inverse function, , where and .
The result of this operation is left-continuous, thus is revertible, i.e. , only if is left-continuous. See [DNC18] § 3.2.1 If there are jumps or plateaus at the endpoints, those may also be lost during pseudoinversion.
public static IEnumerable<Element> LowerPseudoInverse(this IEnumerable<Element> elements, bool startFromZero = false)
Parameters
elements IEnumerable<Element>
The elements to process.
startFromZero bool
If true, it is assumed that is defined from , rather than only in .
Returns
Exceptions
ArgumentException
If the elements are not non-decreasing.
ArgumentException
If the collection is empty.
UpperPseudoInverse(IEnumerable<Element>, bool)
Computes the upper pseudo-inverse function, , where and .
The result of this operation is right-continuous, thus is revertible, i.e. , only if is right-continuous. See [DNC18] § 3.2.1 If there are jumps or plateaus at the endpoints, those may also be lost during pseudoinversion.
public static IEnumerable<Element> UpperPseudoInverse(this IEnumerable<Element> elements, bool startFromZero = false)
Parameters
elements IEnumerable<Element>
The elements to process.
startFromZero bool
If true, it is assumed that is defined from , rather than only in .
Returns
Exceptions
ArgumentException
If the elements are 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(this IReadOnlyList<Element> elements, ComputationSettings settings = null)
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(this IReadOnlyList<Sequence> sequences, ComputationSettings settings = null)
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(this IReadOnlyList<Element> elements, ComputationSettings settings = null)
Parameters
elements IReadOnlyList<Element>
The elements to process.
settings ComputationSettings
Optional settings for the operation.
Returns
UpperEnvelope(IReadOnlyList<Sequence>, ComputationSettings)
Computes the lower envelope of the set of sequences given.
public static IReadOnlyList<Element> UpperEnvelope(this IReadOnlyList<Sequence> sequences, ComputationSettings settings = null)
Parameters
sequences IReadOnlyList<Sequence>
settings ComputationSettings