@FunctionalInterface public interface FloatSignalSource extends AbstractSignalSource, FloatSupplier
float
.
This basic interface is neutral with respect to whether values may change at arbitrary times or synchronously with respect to a clock, and to whether values are computed on the fly when demanded, or stored when available and then just retrieved.
FloatClockedSignalSource
Modifier and Type | Method and Description |
---|---|
default FloatSignalSource |
abs()
Returns a new signal source whose value is the absolute of the value of
this signal source.
|
default FloatSignalSource |
add(FloatSignalSource other)
Returns a new signal source whose value is the sum of the simultaneous
values of this and another signal source.
|
static FloatSignalSource |
choose(BooleanSignalSource condition,
FloatSignalSource inTrue,
FloatSignalSource inFalse)
Returns a new signal source whose value is that of either of two
given type-compatible signal sources, depending on the current
value of a condition signal source.
|
static <E extends Enum<E>> |
choose(EnumSignalSource<E> selector,
EnumMap<E,? extends FloatSignalSource> cases)
Returns a new signal source whose value is selected dynamically from a
range of cases indexed by
enum values. |
static <E extends Enum<E>> |
choose(EnumSignalSource<E> selector,
FloatSignalSource... cases)
Returns a new signal source whose value is selected dynamically from a
range of cases indexed by
enum values. |
static <E extends Enum<E>> |
choose(SignalSource<E> selector,
EnumMap<E,? extends FloatSignalSource> cases)
Returns a new signal source whose value is selected dynamically from a
range of cases indexed by
enum values. |
static FloatClockedSignalSource |
clock(FloatSignalSource output,
Process... processes) |
default Consumer<CompilationContext> |
compileDataFlow()
Returns a code generator for outputting the value of this entity.
|
default void |
compileMainSignalSource(CompilationContext context) |
static FloatSignalSource |
constant(float value)
Returns a signal source whose value is constant (never changes).
|
default BooleanSignalSource |
defined()
Returns a new signal source whose value is
true iff the value of
this signal source is a valid number. |
default FloatClockedSignalSource |
delayed(float... initialValues)
Returns a new signal source that mirror the values of this signal source
delayed by a given number of clock ticks.
|
default FloatClockedSignalSource |
delayed(float initialValue)
Returns a new signal source that mirrors the values of this
signal source delayed by one clock tick.
|
static FloatClockedSignalSource |
delayedFeedback(Function<? super FloatClockedSignalSource,? extends FloatSignalSource> loop,
float... initialValues) |
static FloatClockedSignalSource |
delayedFeedback(Function<? super FloatClockedSignalSource,? extends FloatSignalSource> loop,
float initialValue)
Returns a new signal source that receives its own delayed output as input.
|
default FloatSignalSource |
divide(FloatSignalSource other)
Returns a new signal source whose value is the quotient of the
simultaneous values of this and another signal source.
|
default BooleanSignalSource |
equal(FloatSignalSource other)
Returns a new signal source whose value is
true iff the value of
this signal source is equal to the simultaneous value of another signal
source. |
float |
getAsFloat()
Returns the current value of this signal source.
|
default Optional<Float> |
getConstantAsFloat()
Returns the constant value of this signal source, if applicable.
|
default Class<?> |
getValueClass()
Returns the type of values produced by this entity.
|
default FloatClockedSignalSource |
glidingAverage(int width)
Returns a signal source whose value at each clock index is the
average of values of this signal source at a fixed number of
preceding clock indices, including to the current one.
|
default FloatClockedSignalSource |
glidingStandardDeviation(int width)
Returns a signal source whose value at each clock index is the standard
deviation of values of this signal source at a fixed number of preceding
clock indices, including to the current one.
|
default FloatClockedSignalSource |
glidingSum(int width)
Returns a signal source whose value at each clock index is the
sum of values of this signal source at a fixed number of
preceding clock indices, including to the current one.
|
default FloatClockedSignalSource |
glidingVariance(int width)
Returns a signal source whose value at each clock index is the
variance of values of this signal source at a fixed number of
preceding clock indices, including to the current one.
|
default BooleanSignalSource |
greaterOrEqual(FloatSignalSource other)
Returns a new signal source whose value is
true iff the value of
this signal source is greater than or equal to the simultaneous value of
another signal source. |
default BooleanSignalSource |
greaterThan(FloatSignalSource other)
Returns a new signal source whose value is
true iff the value of
this signal source is greater than the simultaneous value of another signal
source. |
default BooleanSignalSource |
guard(FloatPredicate pred)
Returns a boolean signal source whose values are derived from the values
of this signal source by applying a unary predicate.
|
default boolean |
hasConstantAsFloat()
Checks whether this signal source has a constant value.
|
default FloatClockedSignalSource |
invariant() |
default BooleanSignalSource |
lessOrEqual(FloatSignalSource other)
Returns a new signal source whose value is
true iff the value of
this signal source is less than or equal to the simultaneous value of
another signal source. |
default BooleanSignalSource |
lessThan(FloatSignalSource other)
Returns a new signal source whose value is
true iff the value of
this signal source is less than the simultaneous value of another signal
source. |
default FloatSignalSource |
map(FloatUnaryOperator op)
Returns a signal source whose values are derived from the values of this
signal source by applying a unary function.
|
default FloatSignalSource |
max(FloatSignalSource other)
Returns a new signal source whose value is the maximum of the simultaneous
values of this and another signal source.
|
default FloatSignalSource |
min(FloatSignalSource other)
Returns a new signal source whose value is the minimum of the simultaneous
values of this and another signal source.
|
default FloatSignalSource |
modulo(FloatSignalSource other)
Returns a new signal source whose value is the division remainder of the
simultaneous values of this and another signal source.
|
default FloatSignalSource |
multiply(FloatSignalSource other)
Returns a new signal source whose value is the product of the simultaneous
values of this and another signal source.
|
default FloatSignalSource |
negate()
Returns a new signal source whose value is the negative of the value of
this signal source.
|
default BooleanSignalSource |
negative()
Returns a new signal source whose value is
true iff the value of
this signal source is a negative number. |
default BooleanSignalSource |
nonEqual(FloatSignalSource other)
Returns a new signal source whose value is
true iff the value of
this signal source is not equal to the simultaneous value of another
signal source. |
default BooleanSignalSource |
nonnegative()
Returns a new signal source whose value is
true iff the value of
this signal source is a nonnegative number. |
default BooleanSignalSource |
nonpositive()
Returns a new signal source whose value is
true iff the value of
this signal source is a nonpositive number. |
default BooleanSignalSource |
nonzero()
Returns a new signal source whose value is
true iff the value of
this signal source is not the number zero. |
default BooleanSignalSource |
notANumber()
Returns a new signal source whose value is
true iff the value of
this signal source is not a valid number. |
default BooleanSignalSource |
positive()
Returns a new signal source whose value is
true iff the value of
this signal source is a positive number. |
default FloatClockedSignalSource |
power(BinaryOperator<FloatSignalSource> op,
long n) |
default Process |
probe(Object key)
Returns a realtime event that, when fired, notifies the concerned observer
of the current value of this signal source.
|
default void |
publishStoredValueVariable(CompilationContext context) |
default BooleanSignalSource |
relateWith(FloatBiPredicate pred,
FloatSignalSource other)
Returns a boolean signal source whose values are derived from the
simultaneous values of this and another signal source by applying a binary
predicate.
|
default FloatClockedSignalSource |
sampleAndHold(BooleanSignalSource hold,
float initialValue)
Returns a new clocked signal source whose value at each clock tick is
either the current value of this signal source (sample mode), or
its own value at the previous clock tick (hold mode), depending on
the current value of a given boolean signal source.
|
default FloatSignalSource |
selectAffine(FloatSignalSource onOne,
FloatSignalSource onZero)
Deprecated.
FIXME
|
default FloatClockedSignalSource |
series()
Returns a signal source whose value at each clock index is the
sum of all values of this signal source at all clock indices up
to the current one.
|
default FloatSignalSource |
sqrt()
Returns a new signal source whose value is the square root of the value of
this signal source.
|
default FloatClockedSignalSource |
stored()
Returns a new signal source that stores snapshot values of this signal
source driven by a clock.
|
default FloatSignalSource |
subtract(FloatSignalSource other)
Returns a new signal source whose value is the difference of the
simultaneous values of this and another signal source.
|
default BooleanSignalSource |
zero()
Returns a new signal source whose value is
true iff the value of
this signal source is the number zero. |
default BooleanClockedSignalSource |
zeroCrossing()
Returns a signal source whose value at each clock index is
true if
the current value of this signal source has changed sign compared to its
value at the preceding clock index. |
default FloatSignalSource |
zipWith(FloatBinaryOperator op,
FloatSignalSource other)
Returns a signal source whose values are derived from the simultaneous
values of this and another signal source by applying a binary function.
|
compileDataFlowTo, hasDataFlowIO
float getAsFloat()
The value may be either computed on demand, or retrieved from storage.
Implementations of this method should have no side effect.
getAsFloat
in interface FloatSupplier
default Class<?> getValueClass()
For signals of primitive value type, the result will be the corresponding pseudoclass.
This implementation returns the primitive pseudoclass float.class
.
getValueClass
in interface CompilableDataFlow
Class.isPrimitive()
default Optional<Float> getConstantAsFloat()
Optional
containing the value of this signal
source if it is constant, or Optional.empty()
otherwise.default boolean hasConstantAsFloat()
true
iff the value of this signal source does not change
over timedefault Consumer<CompilationContext> compileDataFlow()
This implementation generates code to invoke this.getAsFloat()
.
compileDataFlow
in interface CompilableDataFlow
static FloatSignalSource constant(float value)
value
- the value of the new signal sourcedefault FloatSignalSource map(FloatUnaryOperator op)
The implementation yields a signal source that computes the derived
value by applying the given function every time its getAsFloat()
method is invoked. If the computation is costly and the
value reused often, it may be convenient to compute and store the value
proactively driven by a clock.
op
- the function to apply to each valuestored()
default FloatSignalSource zipWith(FloatBinaryOperator op, FloatSignalSource other)
The implementation yields a signal source that computes the derived
value by applying the given function every time its getAsFloat()
method is invoked. If the computation is costly and the
value reused often, it may be convenient to compute the value proactively
driven by a clock.
op
- the function to apply to each pair of valuesother
- the other signal source to considerstored()
default BooleanSignalSource guard(FloatPredicate pred)
The implementation yields a signal source that computes the derived
value by applying the given predicate every time its getAsFloat()
method is invoked. If the computation is costly and the
value reused often, it may be convenient to compute the value proactively
driven by a clock.
pred
- the predicate to apply to each valuestored()
default BooleanSignalSource relateWith(FloatBiPredicate pred, FloatSignalSource other)
The implementation yields a signal source that computes the derived
value by applying the given predicate every time its getAsFloat()
method is invoked. If the computation is costly and the
value reused often, it may be convenient to compute the value proactively
driven by a clock.
pred
- the predicate to apply to each valueother
- the other signal source to considerstored()
@Undocumented static FloatClockedSignalSource clock(FloatSignalSource output, Process... processes)
@Undocumented default FloatClockedSignalSource invariant()
default FloatClockedSignalSource stored()
The getAsFloat()
method of the returned signal
source is guaranteed to be extremely fast, both in interpreted
and compiled mode. The computational effort of the underlying
signal source is instead spent on the Process.step(RealtimeContext)
method of the
returned signal source, to be invoked at each clock tick.
If the underlying signal source is constant, the value is
forwarded when the Process.init()
method of the returned signal source is invoked, where as its
implementation of Process.step(RealtimeContext)
does nothing.
default FloatClockedSignalSource delayed(float initialValue)
initialValue
- the initial value to output for the first clock tickdefault FloatClockedSignalSource delayed(float... initialValues)
The length of the delay in clock ticks is specified implicitly by the number of initial values.
initialValues
- the initial values to output for the first clock ticksstatic FloatClockedSignalSource delayedFeedback(Function<? super FloatClockedSignalSource,? extends FloatSignalSource> loop, float initialValue)
The circular data flow is constructed by specifying a function that receives as its argument a delayed signal source that will be fed back from the source that it returns. The passed function is applied exactly once.
The output signal source is used both internally for the delayed feedback, and possibly externally by a consumer. Hence its value is stored implicitly in an intermediate variable in order to avoid duplicate computations.
loop
- the function that creates the output signal source, given its delayed feedbackinitialValue
- the initial value of the delayed feedback@SafeVarargs static FloatClockedSignalSource delayedFeedback(Function<? super FloatClockedSignalSource,? extends FloatSignalSource> loop, float... initialValues)
default Process probe(Object key)
key
- the key to associate the value of this signal source withRealtimeContext.getSignalProbe()
static FloatSignalSource choose(BooleanSignalSource condition, FloatSignalSource inTrue, FloatSignalSource inFalse)
At any point in time, choose(condition, x, y).getAsInt() ==
(this.getAsFloat() ? x : y).getAsInt()
holds.
condition
- the condition signal sourceinTrue
- the signal source to consider when the value of
the condition signal source is true
inFalse
- the signal source to consider when the value of
the condition signal source is false
default FloatSignalSource negate()
For a signal source that = this.negate()
, at any point
in time, that.getAsFloat() == -this.getAsFloat()
holds.
default FloatSignalSource add(FloatSignalSource other)
At any point in time, this.add(other).getAsFloat() ==
this.getAsFloat() + other.getAsFloat()
holds.
other
- the other signal source to considerdefault FloatSignalSource multiply(FloatSignalSource other)
At any point in time, this.multiply(other).getAsFloat() ==
this.getAsFloat() * other.getAsFloat()
holds.
other
- the other signal source to considerdefault FloatSignalSource subtract(FloatSignalSource other)
At any point in time, this.subtract(other).getAsFloat() ==
this.getAsFloat() - other.getAsFloat()
holds.
other
- the other signal source to considerdefault FloatSignalSource divide(FloatSignalSource other)
At any point in time, this.divide(other).getAsFloat() ==
this.getAsFloat() / other.getAsFloat()
holds.
other
- the other signal source to considerdefault FloatSignalSource modulo(FloatSignalSource other)
At any point in time, this.modulo(other).getAsFloat() ==
this.getAsFloat() % other.getAsFloat()
holds.
other
- the other signal source to considerdefault FloatSignalSource abs()
At any point in time, this.abs().getAsFloat() ==
Math.abs(this.getAsFloat())
holds.
default FloatSignalSource min(FloatSignalSource other)
At any point in time, this.min(other).getAsFloat() ==
Math.min(this.getAsFloat(), other.getAsFloat())
holds.
other
- the other signal source to considerdefault FloatSignalSource max(FloatSignalSource other)
At any point in time, this.max(other).getAsFloat() ==
Math.max(this.getAsFloat(), other.getAsFloat())
holds.
other
- the other signal source to considerdefault BooleanSignalSource positive()
true
iff the value of
this signal source is a positive number.
At any point in time, this.positive().getAsBoolean() ==
this.getAsFloat() > 0
holds.
default BooleanSignalSource negative()
true
iff the value of
this signal source is a negative number.
At any point in time, this.positive().getAsBoolean() ==
this.getAsFloat() < 0
holds.
default BooleanSignalSource nonpositive()
true
iff the value of
this signal source is a nonpositive number.
At any point in time, this.positive().getAsBoolean() ==
this.getAsFloat() <= 0
holds.
default BooleanSignalSource nonnegative()
true
iff the value of
this signal source is a nonnegative number.
At any point in time, this.positive().getAsBoolean() ==
this.getAsFloat() >= 0
holds.
default BooleanSignalSource zero()
true
iff the value of
this signal source is the number zero.
At any point in time, this.positive().getAsBoolean() ==
this.getAsFloat() == 0
holds.
default BooleanSignalSource nonzero()
true
iff the value of
this signal source is not the number zero.
At any point in time, this.positive().getAsBoolean() ==
this.getAsFloat() != 0
holds.
default BooleanSignalSource lessThan(FloatSignalSource other)
true
iff the value of
this signal source is less than the simultaneous value of another signal
source.
At any point in time, this.lessThan(other).getAsBoolean() ==
this.getAsFloat() < other.getAsFloat()
holds.
other
- the other signal source to considerdefault BooleanSignalSource greaterThan(FloatSignalSource other)
true
iff the value of
this signal source is greater than the simultaneous value of another signal
source.
At any point in time, this.lessThan(other).getAsBoolean() ==
this.getAsFloat() > other.getAsFloat()
holds.
other
- the other signal source to considerdefault BooleanSignalSource lessOrEqual(FloatSignalSource other)
true
iff the value of
this signal source is less than or equal to the simultaneous value of
another signal source.
At any point in time, this.lessOrEqua;(other).getAsBoolean() ==
this.getAsFloat() <= other.getAsFloat()
holds.
other
- the other signal source to considerdefault BooleanSignalSource greaterOrEqual(FloatSignalSource other)
true
iff the value of
this signal source is greater than or equal to the simultaneous value of
another signal source.
At any point in time, this.greaterOrEqual(other).getAsBoolean() ==
this.getAsFloat() >= other.getAsFloat()
holds.
other
- the other signal source to considerdefault BooleanSignalSource equal(FloatSignalSource other)
true
iff the value of
this signal source is equal to the simultaneous value of another signal
source.
At any point in time, this.equal(other).getAsBoolean() ==
this.getAsFloat() == other.getAsFloat()
holds.
other
- the other signal source to considerdefault BooleanSignalSource nonEqual(FloatSignalSource other)
true
iff the value of
this signal source is not equal to the simultaneous value of another
signal source.
At any point in time, this.nonEqual(other).getAsBoolean() ==
this.getAsFloat() != other.getAsFloat()
holds.
other
- the other signal source to considerdefault BooleanSignalSource defined()
true
iff the value of
this signal source is a valid number.
At any point in time, this.defined().getAsBoolean() ==
!Float.isNan(this.getAsFloat())
holds.
default BooleanSignalSource notANumber()
true
iff the value of
this signal source is not a valid number.
At any point in time, this.notANumber().getAsBoolean() ==
Float.isNan(this.getAsFloat())
holds.
default FloatSignalSource sqrt()
At any point in time, this.sqrt().getAsFloat() ==
(float)Math.sqrt(this.getAsFloat())
holds.
other
- the other signal source to considerdefault FloatClockedSignalSource series()
The sum is computed using Kahan's stable algorithm, which requires four additions per iteration.
default FloatClockedSignalSource glidingSum(int width)
The sum is computed using Kahan's stable algorithm, which requires five additions per iteration.
width
- the number of clock cycles to sum overNegativeArraySizeException
- if width <= 0
default FloatClockedSignalSource glidingAverage(int width)
The average is computed using Kahan's stable algorithm, which requires five additions and one division per iteration.
width
- the number of clock cycles to average overNegativeArraySizeException
- if width <= 0
default FloatClockedSignalSource glidingVariance(int width)
width
- the number of clock cycles to compute overNegativeArraySizeException
- if width <= 0
default FloatClockedSignalSource glidingStandardDeviation(int width)
width
- the number of clock cycles to compute overNegativeArraySizeException
- if width <= 0
default BooleanClockedSignalSource zeroCrossing()
true
if
the current value of this signal source has changed sign compared to its
value at the preceding clock index.
Corner cases, namly initial values, positive and negative zero, and NaNs, are handled robustly; they are not counted as sign changes.
@Deprecated default FloatSignalSource selectAffine(FloatSignalSource onOne, FloatSignalSource onZero)
At any point in time, selectAffine(s, a, b).getAsFloat() ==
s.getAsFloat() * a.getAsFloat() + (1 - s.getAsFloat()) *
b.getAsFloat()
holds.
static <E extends Enum<E>> FloatSignalSource choose(SignalSource<E> selector, EnumMap<E,? extends FloatSignalSource> cases)
enum
values.
At any point in time, choose(s, m).getAsFloat() ==
m.get(s.get()).getAsFloat()
holds.
The given map cases
is assumed to be immutable and to contain an
entry for every possible value of the enum
type E
.
E
- the type of enum
valuesselector
- the signal source that provides the enum
valuecases
- a map of enum
values to signal sources to select fromstatic <E extends Enum<E>> FloatSignalSource choose(EnumSignalSource<E> selector, EnumMap<E,? extends FloatSignalSource> cases)
enum
values.
At any point in time, choose(s, m).getAsFloat() ==
m.get(E.values()[s.getAsInt()]).getAsFloat()
holds.
The given map cases
is assumed to be immutable and to contain an
entry for every possible value of the enum
type E
.
E
- the type of enum
valuesselector
- the signal source that provides the ordinal number of the
enum
valuecases
- a map of enum
values to signal sources to select from@SafeVarargs static <E extends Enum<E>> FloatSignalSource choose(EnumSignalSource<E> selector, FloatSignalSource... cases)
enum
values.
At any point in time, choose(s, a).getAsFloat() ==
m[s.getAsInt()].getAsFloat()
holds.
The given array cases
is assumed to be immutable and to contain
an element for every possible value of the enum
type E
.
E
- the type of enum
valuesselector
- the signal source that provides the enum
valuecases
- an array signal sources to select from, in the definition
order of enum
elementsdefault FloatClockedSignalSource sampleAndHold(BooleanSignalSource hold, float initialValue)
hold
- a boolean signal source that, at each clock tick, selects hold
mode if its value ist true
, or sample mode if its value is false
initialValue
- the initial value to use if in hold mode at the first
clock tick@Undocumented default FloatClockedSignalSource power(BinaryOperator<FloatSignalSource> op, long n)
@Undocumented default void compileMainSignalSource(CompilationContext context)
@Undocumented default void publishStoredValueVariable(CompilationContext context)