Package org.apache.sis.math
Class LinearlyDerivedVector
- All Implemented Interfaces:
Serializable
,Iterable<Number>
,Collection<Number>
,List<Number>
,RandomAccess
,SequencedCollection<Number>
A vector derived from another vector by application of a scale factor and an offset.
This is used for example when data in a netCDF file are packed as integer values.
Several methods in this implementation requires a bijective relationship between this
and base
.
This is mostly the case if coefficients are finite and scale
is non-zero, as asserted at construction time.
- Since:
- 1.0
- Version:
- 1.1
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Vector
The vector on which this vector is derived from.private final double
The offset to apply after the scale factor.private final double
The scale factor to apply.private static final long
For cross-version compatibility.Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
ConstructorsConstructorDescriptionLinearlyDerivedVector
(Vector base, double scale, double offset) Creates a new vector of derived data. -
Method Summary
Modifier and TypeMethodDescriptionprivate Number
Applies the linear relationship on the given value.private NumberRange
<?> convert
(NumberRange<?> range) Converts the given range.(package private) final Vector
createConcatenate
(Vector toAppend) Returns the concatenation of this vector with the given one.(package private) final Vector
createTransform
(double s, double t) Concatenates the given transformation with the current transform.double
doubleValue
(int index) Returns the value at the given index as adouble
.double[]
Copies all values in an array of double precision floating point numbers.(package private) boolean
Optimization ofequals
method for the case where the other object is anotherLinearlyDerivedVector
using the same linear relationship.boolean
Optimization ofequals
method for the case where the other object is anotherLinearlyDerivedVector
using the same linear relationship.void
Sets a range of elements to the given number.get
(int index) Returns the number at the given index as aDouble
.Returns the type of values resulting from the linear conversion applied by this vector.increment
(double tolerance) Returns the increment between all consecutive values if this increment is constant, ornull
otherwise.(package private) final int
indexOf
(int toSearch, int index, boolean equality) Returns the index of a search based one values at given indices (see javadoc in parent class for details).private Number
Applies the inverse linear function on the given value.boolean
Returnstrue
if this vector is empty or contains onlyNaN
values.boolean
Returnstrue
if this vector contains only integer values.boolean
isNaN
(int index) Returnstrue
if the value at the given index isnull
orNaN
.boolean
Double-precision values are not guaranteed to be convertible to single-precision floating point type.pick
(int... indices) Returns a view which contains the values of this vector at the given indexes.NumberRange
<?> range()
Returns the minimal and maximal values found in this vector.(package private) final NumberRange
<?> range
(IntSupplier indices, int n) Computes the range of values at the indices provided by the given supplier.int[]
repetitions
(int... candidates) Detects repetition patterns in the values contained in this vector.Sets the number at the given index.int
size()
Returns the number of elements in this vector.stringValue
(int index) Returns a string representation of the value at the given index.subSampling
(int first, int step, int length) Returns a view which contain the values of this vector in a given index range.Methods inherited from class org.apache.sis.math.Vector
backingVector, buffer, byteValue, compress, concatenate, copy, create, create, createForDecimal, createSequence, createSequence, createSubSampling, floatValue, floatValues, hashCode, intValue, isUnsigned, longValue, repeat, reverse, shortValue, subList, subtract, toBacking, toString, transform, warning
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.List
addAll, addFirst, addLast, contains, containsAll, getFirst, getLast, isEmpty, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, sort, spliterator, toArray, toArray
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
base
The vector on which this vector is derived from. -
scale
private final double scaleThe scale factor to apply. -
offset
private final double offsetThe offset to apply after the scale factor.
-
-
Constructor Details
-
LinearlyDerivedVector
LinearlyDerivedVector(Vector base, double scale, double offset) Creates a new vector of derived data.
-
-
Method Details
-
getElementType
Returns the type of values resulting from the linear conversion applied by this vector. Note that it does not means that this vector can store all values of that type.- Specified by:
getElementType
in classVector
- Returns:
- the type of elements in this vector.
- See Also:
-
isSinglePrecision
public boolean isSinglePrecision()Double-precision values are not guaranteed to be convertible to single-precision floating point type.- Overrides:
isSinglePrecision
in classVector
- Returns:
- whether values in this vector can be casted to
float
primitive type. - See Also:
-
isInteger
public boolean isInteger()Returnstrue
if this vector contains only integer values. This implementation delegates to the base vector if coefficients are integers, or scans all values otherwise. -
size
public int size()Returns the number of elements in this vector. This is taken directly from the base vector. -
isEmptyOrNaN
public boolean isEmptyOrNaN()Returnstrue
if this vector is empty or contains onlyNaN
values. The implementation delegates to the base vector since linear relationship does not change whether values are NaN.- Overrides:
isEmptyOrNaN
in classVector
- Returns:
- whether this vector is empty or contains only
NaN
values.
-
isNaN
public boolean isNaN(int index) Returnstrue
if the value at the given index isnull
orNaN
. The implementation delegates to the base vector since linear relationship does not change whether a value is NaN. -
doubleValue
public double doubleValue(int index) Returns the value at the given index as adouble
. This method is invoked by all othersfooValue()
.- Specified by:
doubleValue
in classVector
- Parameters:
index
- the index in the [0 … size-1] range.- Returns:
- the value at the given index.
- See Also:
-
stringValue
Returns a string representation of the value at the given index. This implementation uses thedouble
representation.- Specified by:
stringValue
in classVector
- Parameters:
index
- the index in the [0 … size-1] range.- Returns:
- a string representation of the value at the given index (may be
null
). - See Also:
-
get
Returns the number at the given index as aDouble
. -
set
Sets the number at the given index. This action is likely to loose precision if the base vector stores values using integer primitive type. -
fill
Sets a range of elements to the given number. This action is likely to loose precision if the base vector stores values using integer primitive type. -
indexOf
final int indexOf(int toSearch, int index, boolean equality) Returns the index of a search based one values at given indices (see javadoc in parent class for details). This implementation forwards to backing vector on the assumption that thethis
↔︎base
relationship is bijective.- Overrides:
indexOf
in classVector
- Parameters:
toSearch
- index of the value to search.index
- index of the first value where to start the search.equality
- whether we search the first equal value, or the first different value.- Returns:
- index of the value found, or the vector size if the value has not been found.
-
repetitions
public int[] repetitions(int... candidates) Detects repetition patterns in the values contained in this vector. This implementation forwards to backing vector on the assumption that thethis
↔︎base
relationship is bijective.- Overrides:
repetitions
in classVector
- Parameters:
candidates
- probable values, ornull
or an empty array if unknown. If non-empty, those values will be used for narrowing the search, which may improve performances. There is no guarantee that the values returned by this method will be among the given candidates.- Returns:
- the number of times that entities (numbers, or group of numbers) appears consecutively with identical values. If no such repetition is found, an empty array.
- See Also:
-
increment
Returns the increment between all consecutive values if this increment is constant, ornull
otherwise. This implementation converts the value computed by the backing vector on the assumption that thethis
↔︎base
relationship is a linear. -
convert
Applies the linear relationship on the given value.- Parameters:
value
- the number to convert, ornull
.- Returns:
- the converted number (may be
null
).
-
inverse
Applies the inverse linear function on the given value.- Parameters:
value
- the number to inverse convert, ornull
.- Returns:
- the inverse converted number (may be
null
).
-
convert
Converts the given range. This is used for delegating range calculation to the base vector on the assumption that is will be more efficient than iterating ourselves on all values.- Parameters:
range
- the range to convert, ornull
.- Returns:
- the converted range, or
null
if the given range was null.
-
range
Returns the minimal and maximal values found in this vector. This implementation delegates to the base vector (which may provide fast implementation) then convert the result. -
range
Computes the range of values at the indices provided by the given supplier. This implementation delegates to the base vector (which may provide fast implementation) then convert the result. -
subSampling
Returns a view which contain the values of this vector in a given index range. This implementation delegates to base vector and wraps again.- Overrides:
subSampling
in classVector
- Parameters:
first
- index of the first value in this vector to be included in the returned view.step
- the index increment between values in this vector to be included in the returned view. Can be positive, zero or negative.length
- the length of the view to be returned. Cannot be greater than the length of this vector, except if thestep
is zero.- Returns:
- a view of this vector containing values in the given index range.
-
pick
Returns a view which contains the values of this vector at the given indexes. This implementation delegates to base vector and wraps again. -
createConcatenate
Returns the concatenation of this vector with the given one. This implementation potentially delegate to base vector.- Overrides:
createConcatenate
in classVector
-
createTransform
Concatenates the given transformation with the current transform.- Overrides:
createTransform
in classVector
-
doubleValues
public double[] doubleValues()Copies all values in an array of double precision floating point numbers. We override this method for efficiency. We do not override thefloat
versions for accuracy reasons.- Overrides:
doubleValues
in classVector
- Returns:
- a copy of all floating point values in this vector.
- See Also:
-
equals
Optimization ofequals
method for the case where the other object is anotherLinearlyDerivedVector
using the same linear relationship. -
equals
Optimization ofequals
method for the case where the other object is anotherLinearlyDerivedVector
using the same linear relationship.- Overrides:
equals
in classVector
- Parameters:
lower
- index of the first value to compare in this vector, inclusive.upper
- index after the last value to compare in this vector.other
- the other vector to compare values with this vector. May bethis
.otherOffset
- index of the first element to compare in the other vector.- Returns:
- whether values over the specified range of the two vectors are equal.
-