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>>
GetBreakpointBoundaryValues(ValueTuple<Segment, Point, Segment>)
Enumerates the left-limit, the value and right-limit at the breakpoint.
public static IEnumerable<Rational> GetBreakpointBoundaryValues(ValueTuple<Segment, Point, Segment> breakpoint)
Parameters
breakpoint ValueTuple<Segment, Point, Segment>
Returns
GetBreakpointsBoundaryValues(IEnumerable<ValueTuple<Segment, Point, Segment>>)
Enumerates, for each breakpoint, the left-limit, the value and right-limit at the breakpoint.
public static IEnumerable<Rational> GetBreakpointsBoundaryValues(IEnumerable<ValueTuple<Segment, Point, Segment>> breakpoints)
Parameters
breakpoints IEnumerable<ValueTuple<Segment, Point, Segment>>
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(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<ValueTuple<Rational, Rational>> GetElementsBoundaryPairs(IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
Returns
IEnumerable<ValueTuple<Rational, Rational>>
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
BreakpointSupValue(ValueTuple<Segment, Point, Segment>)
If the sequence is upper-bounded around the breakpoint , i.e., exists such that for any , returns . Otherwise, returns .
public static Rational BreakpointSupValue(ValueTuple<Segment, Point, Segment> breakpoint)
Parameters
breakpoint ValueTuple<Segment, Point, Segment>
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
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(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 Nullable<Rational> MaxValue(IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
Returns
MaxValue(IReadOnlyCollection<Element>)
public static Nullable<Rational> MaxValue(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 Nullable<Rational> MaxArg(IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
Returns
MaxArg(IReadOnlyCollection<Element>)
public static Nullable<Rational> MaxArg(IReadOnlyCollection<Element> elements)
Parameters
elements IReadOnlyCollection<Element>
Returns
BreakpointInfValue(ValueTuple<Segment, Point, Segment>)
If the sequence is upper-bounded around the breakpoint , i.e., exists such that for any , returns . Otherwise, returns .
public static Rational BreakpointInfValue(ValueTuple<Segment, Point, Segment> breakpoint)
Parameters
breakpoint ValueTuple<Segment, Point, Segment>
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
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(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 Nullable<Rational> MinValue(IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
Returns
MinValue(IReadOnlyCollection<Element>)
public static Nullable<Rational> MinValue(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 Nullable<Rational> MinArg(IEnumerable<Element> elements)
Parameters
elements IEnumerable<Element>
Returns
MinArg(IReadOnlyCollection<Element>)
public static Nullable<Rational> MinArg(IReadOnlyCollection<Element> elements)
Parameters
elements IReadOnlyCollection<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, , 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(IEnumerable<Element> elements, bool startFromZero)
Parameters
elements IEnumerable<Element>
startFromZero Boolean
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>, Boolean)
Computes the upper pseudo-inverse function, , where and .
The result of this operation is right-continuous, thus is revertible, i.e.