-
public class F64ArrayA strided n-dimensional array stored in a DoubleArray.
The term strided means that unlike regular DoubleArray the elements of an F64Array can be at arbitrary index intervals (strides) from each other. For example
data = [0, 1, 2, 3, 4, 5] offset = 1 shape = [2] strides = [3]corresponds to a 1-D array with elements
[1, 4]Due to instantiation contracts, the actual instance of this exact class will always be non-flat, i.e. have at least two dimensions. One-dimensional array will be F64FlatArray (or possibly a descendant of that), and zero-dimensional (singleton) arrays are not allowed.
Method tags:
"in-place": this operation will modify the array
"copying": this operation creates a copy fully independent from the original array
"viewer": this operation creates a new array which shares data with the original one; modifications to one will be seen through the other, and no copying is performed
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classF64Array.Viewerpublic classF64Array.Companion
-
Field Summary
Fields Modifier and Type Field Description private final IntegernDimprivate final Integerlengthprivate final Integersizeprivate final BooleanisFlattenableprivate final F64Array.ViewerVprivate final DoubleArraydataprivate final Integeroffsetprivate final IntArraystridesprivate final IntArrayshape
-
Method Summary
Modifier and Type Method Description final Doubleget(Integer indices)Generic getter. Doubleget(Integer pos)final Doubleget(Integer r, Integer c)final Doubleget(Integer d, Integer r, Integer c)final Unitset(Integer indices, Double value)Generic setter. Unitset(Integer pos, Double value)final Unitset(Integer r, Integer c, Double value)final Unitset(Integer d, Integer r, Integer c, Double value)Sequence<F64Array>along(Integer axis)Returns a sequence of views along the specified axis. F64Arrayview(Integer index, Integer axis)Returns a view of this array along the specified axis. F64Arraycopy()Returns a copy of this array. UnitcopyTo(F64Array other)Copies elements in this array to other array. F64Arrayreshape(Integer shape)Reshapes this array. final F64Arrayappend(F64Array other, Integer axis)Appends this array to another array. F64FlatArrayflatten()Flattens the array into a 1D view in O(1) time. final F64Arrayslice(Integer from, Integer to, Integer step, Integer axis)Creates a sliced view of this array in O(1) time. Booleancontains(Double other)Unitfill(Double init)Fills this array with a given init value. Unitreorder(IntArray indices, Integer axis)Applies a given permutation of indices to the elements in the array. Doubledot(ShortArray other)Computes a dot product between two vectors. Doubledot(IntArray other)Computes a dot product between two vectors. final Doubledot(DoubleArray other)Computes a dot product between two vectors. Doubledot(F64Array other)Computes a dot product between two vectors. final Doublemean()Computes the mean of the elements. Doublesd()Computes the unbiased standard deviation of the elements. Doublesum()Returns the sum of the elements. UnitcumSum()Computes cumulative sum of the elements. Doublemax()Returns the maximum element. IntegerargMax()Returns the index of the maximum element. Doublemin()Returns the minimum element. IntegerargMin()Returns the index of the minimum element. UnittransformInPlace(Function1<Double, Double> op)Replaces each element x of this array with op(x) for the given unary operation op. F64Arraytransform(Function1<Double, Double> op)A copying version of transformInPlace. <T extends Any> Tfold(T initial, Function2<T, Double, T> op)Folds the array using the provided initial value and the folding operation op. Doublereduce(Function2<Double, Double, Double> op)Reduces the array using the provided reduction operation op. UnitcombineInPlace(F64Array other, Function2<Double, Double, Double> op)Apply the binary operation op in-place. F64Arraycombine(F64Array other, Function2<Double, Double, Double> op)Apply the binary operation op and return a new array. UnitexpInPlace()Replaces each element x of this array with its exponent exp(x). F64Arrayexp()A copying version of expInPlace. Unitexpm1InPlace()Replaces each element x of this array with exp(x) - 1. F64Arrayexpm1()A copying version of expm1InPlace. UnitlogInPlace()Replaces each element x of this array with its natural logarithm log(x). F64Arraylog()A copying version of logInPlace. Unitlog1pInPlace()Replaces each element x of this array with log(1 + x). F64Arraylog1p()A copying version of log1pInPlace. final Unitrescale()Rescales the elements so that the sum is 1.0. final UnitlogRescale()Rescales the elements so that the sum of their exponents is 1.0. DoublelogSumExp()Computes
in a numerically stable way.log(Σ_x exp(x))UnitlogAddExpAssign(F64Array other)Plus-assign for values stored as logarithms. F64ArraylogAddExp(F64Array other)Computes elementwise
in a numerically stable way.log(exp(this[*i]) + exp(other[*i]))final F64ArrayunaryPlus()F64ArrayunaryMinus()UnitplusAssign(F64Array other)UnitplusAssign(Double update)F64Arrayplus(F64Array other)final F64Arrayplus(Double update)UnitminusAssign(F64Array other)UnitminusAssign(Double update)F64Arrayminus(F64Array other)final F64Arrayminus(Double update)UnittimesAssign(F64Array other)UnittimesAssign(Double update)F64Arraytimes(F64Array other)final F64Arraytimes(Double update)UnitdivAssign(F64Array other)UnitdivAssign(Double update)F64Arraydiv(F64Array other)final F64Arraydiv(Double update)ObjecttoArray()Converts this array to a conventional Kotlin structure. Array<?>toGenericArray()Converts this array to an Array. DoubleArraytoDoubleArray()Converts this vector to a DoubleArray. StringtoString(Integer maxDisplay, DecimalFormat format)Creates a String representation of the given array. StringtoString()Booleanequals(Object other)IntegerhashCode()final IntegergetNDim()Number of axes in this array. final IntegergetLength()Number of elements along the first axis. final IntegergetSize()final BooleangetIsFlattenable()Returns trueif this array can be flattened using flatten.final F64Array.ViewergetV()A broadcasted viewer for this array. final DoubleArraygetData()Raw data array. final IntegergetOffset()Offset of the first vector element in the raw data array. final IntArraygetStrides()Indexing steps along each axis. final IntArraygetShape()Number of elements along each axis. -
-
Method Detail
-
get
final Double get(Integer indices)
Generic getter.
Note that it could be at least 1.5x slower than specialized versions for 1, 2 or 3 dimensions.
-
set
final Unit set(Integer indices, Double value)
Generic setter.
Note that it could be at least 1.5x slower than specialized versions for 1, 2 or 3 dimensions.
-
along
Sequence<F64Array> along(Integer axis)
Returns a sequence of views along the specified axis.
For example, for a 2D array
axis = 0means "for each row", andaxis = 1"for each column".The array must have at least two dimensions.
Viewer method.
-
view
F64Array view(Integer index, Integer axis)
Returns a view of this array along the specified axis.
The array must have at least two dimensions. Consider using V with easier syntax.
Viewer method.
-
copyTo
Unit copyTo(F64Array other)
Copies elements in this array to other array.
In-place method for other and copying method for this.
-
reshape
F64Array reshape(Integer shape)
Reshapes this array.
The original and the new array contain the same elements in the same order, if both are enumerated row-major.
For example, F64Array.of(1.0, 2.0, 3.0, 4.0, 5.0, 6.0).reshape(2, 3) produces a 2x3 matrix: [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]
Only supported for flattenable arrays.
Viewer method.
-
append
final F64Array append(F64Array other, Integer axis)
Appends this array to another array.
- Parameters:
axis- the axis along which the arrays are appended.
-
flatten
F64FlatArray flatten()
Flattens the array into a 1D view in O(1) time.
Only implemented for flattenable arrays.
Viewer method.
-
slice
final F64Array slice(Integer from, Integer to, Integer step, Integer axis)
Creates a sliced view of this array in O(1) time.
- Parameters:
from- the first index of the slice (inclusive).to- the last index of the slice (exclusive).step- indexing step.axis- to slice along.
-
reorder
Unit reorder(IntArray indices, Integer axis)
Applies a given permutation of indices to the elements in the array.
In-place method.
-
dot
Double dot(ShortArray other)
Computes a dot product between two vectors.
Only implemented for flat arrays.
-
dot
Double dot(IntArray other)
Computes a dot product between two vectors.
Only implemented for flat arrays.
-
dot
final Double dot(DoubleArray other)
Computes a dot product between two vectors.
Only implemented for flat arrays. Optimized for dense arrays.
-
dot
Double dot(F64Array other)
Computes a dot product between two vectors.
Only implemented for flat arrays. Optimized for dense arrays.
-
cumSum
Unit cumSum()
Computes cumulative sum of the elements.
In-place method. Only implemented for flat arrays.
-
max
Double max()
Returns the maximum element.
If any of array elements is NaN, the result is undefined but will be one of the array elements.
Optimized for dense arrays.
-
argMax
Integer argMax()
Returns the index of the maximum element.
If any of array elements is NaN, the result is undefined but will be a valid index.
Only implemented for flat arrays.
-
min
Double min()
Returns the minimum element.
If any of array elements is NaN, the result is undefined but will be one of the array elements.
Optimized for dense arrays.
-
argMin
Integer argMin()
Returns the index of the minimum element.
If any of array elements is NaN, the result is undefined but will be a valid index.
Only implemented for flat arrays.
-
transformInPlace
Unit transformInPlace(Function1<Double, Double> op)
Replaces each element x of this array with op(x) for the given unary operation op.
If you need to apply one of the
exp,expm1,log,log1p, use the appropriate specialized method instead (see the list below); these will generally be much more efficient.In-place method.
- Parameters:
op- the unary operation to be applied.
-
transform
F64Array transform(Function1<Double, Double> op)
A copying version of transformInPlace.
If you need to apply one of the
exp,expm1,log,log1p, use the appropriate specialized method instead (see the list below); these will generally be much more efficient.Copying method.
- Parameters:
op- the unary operation to be applied.
-
fold
<T extends Any> T fold(T initial, Function2<T, Double, T> op)
Folds the array using the provided initial value and the folding operation op.
Equivalent to the following pseudo-code:
var res = initial for (value in array) res = op(res, value) return resIf you need to fold using one of the
plus,max, orminwith standard initial values, use the appropriate specialized method instead (see the list below); these will generally be much more efficient.- Parameters:
initial- the starting value of the fold.op- the folding binary operation.
-
reduce
Double reduce(Function2<Double, Double, Double> op)
Reduces the array using the provided reduction operation op.
Equivalent to the following pseudo-code:
var res = first_element for (value in remaining_elements) res = op(res, value) return resIf you need to reduce using one of the
plus,max, ormin, use the appropriate specialized method instead (see the list below); these will generally be much more efficient.- Parameters:
op- the binary reduction operation.
-
combineInPlace
Unit combineInPlace(F64Array other, Function2<Double, Double, Double> op)
Apply the binary operation op in-place.
If you need to apply an arithmetic operation (including logAddExp), use the appropriate specialized method instead (see the list below); these will generally be more efficient.
In-place method.
- Parameters:
other- the array to combine with.op- the binary operation.
-
combine
F64Array combine(F64Array other, Function2<Double, Double, Double> op)
Apply the binary operation op and return a new array.
If you need to apply an arithmetic operation (including logAddExp), use the appropriate specialized method instead (see the list below); these will generally be more efficient.
Copying method.
- Parameters:
other- the array to combine with.op- the binary operation.
-
expInPlace
Unit expInPlace()
Replaces each element x of this array with its exponent exp(x).
In-place method. Optimized for dense arrays.
-
exp
F64Array exp()
A copying version of expInPlace.
Copying method. Optimized for dense arrays.
-
expm1InPlace
Unit expm1InPlace()
Replaces each element x of this array with exp(x) - 1.
In-place method. Optimized for dense arrays.
-
expm1
F64Array expm1()
A copying version of expm1InPlace.
Copying method. Optimized for dense arrays.
-
logInPlace
Unit logInPlace()
Replaces each element x of this array with its natural logarithm log(x).
In-place method. Optimized for dense arrays.
-
log
F64Array log()
A copying version of logInPlace.
Copying method. Optimized for dense arrays.
-
log1pInPlace
Unit log1pInPlace()
Replaces each element x of this array with log(1 + x).
In-place method. Optimized for dense arrays.
-
log1p
F64Array log1p()
A copying version of log1pInPlace.
Copying method. Optimized for dense arrays.
-
logRescale
final Unit logRescale()
Rescales the elements so that the sum of their exponents is 1.0.
In-place method.
-
logAddExpAssign
Unit logAddExpAssign(F64Array other)
Plus-assign for values stored as logarithms.
In other words, the same as invoking
this[*i] = log(exp(this[*i]) + exp(other[*i]))for every valid i.
In-place method.
-
logAddExp
F64Array logAddExp(F64Array other)
Computes elementwise
log(exp(this[*i]) + exp(other[*i]))in a numerically stable way.
Copying method.
-
unaryMinus
F64Array unaryMinus()
-
plusAssign
Unit plusAssign(F64Array other)
-
plusAssign
Unit plusAssign(Double update)
-
minusAssign
Unit minusAssign(F64Array other)
-
minusAssign
Unit minusAssign(Double update)
-
timesAssign
Unit timesAssign(F64Array other)
-
timesAssign
Unit timesAssign(Double update)
-
toArray
Object toArray()
Converts this array to a conventional Kotlin structure.
For example, a vector will be converted to a DoubleArray, a matrix will become
Array<DoubleArray>etc.Copying method.
-
toGenericArray
Array<?> toGenericArray()
Converts this array to an Array.
For example, a matrix will become
Array<DoubleArray>etc.Copying method. Not implemented for flat arrays.
-
toDoubleArray
DoubleArray toDoubleArray()
Converts this vector to a DoubleArray.
Copying method. Only implemented for flat arrays.
-
toString
String toString(Integer maxDisplay, DecimalFormat format)
Creates a String representation of the given array.
At most maxDisplay elements are printed for each dimension.
-
getIsFlattenable
final Boolean getIsFlattenable()
Returns
trueif this array can be flattened using flatten.Flattenable array's elements are laid out with a constant stride. This allows using simple loops when iterating. Calling flatten on a non-flattenable array will produce an IllegalStateException.
A particular case of a flattenable array is a dense array whose elements occupy a contiguous block of memory. Large dense arrays employ native SIMD optimizations, see F64LargeDenseArray.
-
getV
final F64Array.Viewer getV()
A broadcasted viewer for this array.
The main difference between a... and a.V... is that the array's getter/setter methods deal with scalar Double values, while the viewer's methods deal with F64Arrays. Another difference is that the viewer's methods can skip dimensions by providing _I object instead of an index.
Consider a matrix (2D array)
a. Then the following invocations have the following effect: a4 // fails, since it doesn't reference a scalar a4, 2 // returns a Double a.V4 // returns 4th row a.V_I, 2 // returns 2nd column a.V4, 2 // fails, since it doesn't reference an array
-
getData
final DoubleArray getData()
Raw data array.
-
getStrides
final IntArray getStrides()
Indexing steps along each axis.
-
-
-
-