- java.lang.Object
-
- org.tensorflow.ndarray.NdArrays
-
-
Constructor Summary
Constructors Constructor Description NdArrays()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static BooleanNdArrayofBooleans(Shape shape)Creates an N-dimensional array of booleans of the given shape.static ByteNdArrayofBytes(Shape shape)Creates an N-dimensional array of bytes of the given shape.static DoubleNdArrayofDoubles(Shape shape)Creates an N-dimensional array of doubles of the given shape.static FloatNdArrayofFloats(Shape shape)Creates an N-dimensional array of floats of the given shape.static IntNdArrayofInts(Shape shape)Creates an N-dimensional array of ints of the given shape.static LongNdArrayofLongs(Shape shape)Creates an N-dimensional array of longs of the given shape.static <T> NdArray<T>ofObjects(Class<T> clazz, Shape shape)Creates an N-dimensional array of the given shape.static ShortNdArrayofShorts(Shape shape)Creates an N-dimensional array of shorts of the given shape.static BooleanNdArrayscalarOf(boolean value)Creates boolean scalar (rank 0) initialized with the given value.static ByteNdArrayscalarOf(byte value)Creates byte scalar (rank 0) initialized with the given value.static DoubleNdArrayscalarOf(double value)Creates double scalar (rank 0) initialized with the given value.static FloatNdArrayscalarOf(float value)Creates float scalar (rank 0) initialized with the given value.static IntNdArrayscalarOf(int value)Creates long scalar (rank 0) initialized with the given value.static LongNdArrayscalarOf(long value)Creates long scalar (rank 0) initialized with the given value.static ShortNdArrayscalarOf(short value)Creates short scalar (rank 0) initialized with the given value.static <T> NdArray<T>scalarOfObject(T value)Creates scalar (rank 0) initialized with the given value.static BooleanSparseNdArraysparseOf(LongNdArray indices, BooleanNdArray values, boolean defaultValue, Shape shape)Creates a Sparse array of boolean valuesstatic BooleanSparseNdArraysparseOf(LongNdArray indices, BooleanNdArray values, Shape shape)Creates a Sparse array of boolean values with a default value of 'false'static ByteSparseNdArraysparseOf(LongNdArray indices, ByteNdArray values, byte defaultValue, Shape shape)Creates a Sparse array of byte valuesstatic ByteSparseNdArraysparseOf(LongNdArray indices, ByteNdArray values, Shape shape)Creates a Sparse array of byte values with a default value of zerostatic DoubleSparseNdArraysparseOf(LongNdArray indices, DoubleNdArray values, double defaultValue, Shape shape)Creates a Sparse array of double valuesstatic DoubleSparseNdArraysparseOf(LongNdArray indices, DoubleNdArray values, Shape shape)Creates a Sparse array of double values with a default value of zerostatic FloatSparseNdArraysparseOf(LongNdArray indices, FloatNdArray values, float defaultValue, Shape shape)Creates a Sparse array of float valuesstatic FloatSparseNdArraysparseOf(LongNdArray indices, FloatNdArray values, Shape shape)Creates a Sparse array of float values with a default value of zerostatic IntSparseNdArraysparseOf(LongNdArray indices, IntNdArray values, int defaultValue, Shape shape)Creates a Sparse array of int valuesstatic IntSparseNdArraysparseOf(LongNdArray indices, IntNdArray values, Shape shape)Creates a Sparse array of int values with a default value of zero.static LongSparseNdArraysparseOf(LongNdArray indices, LongNdArray values, long defaultValue, Shape shape)Creates a Sparse array of long values with a default value of zerostatic LongSparseNdArraysparseOf(LongNdArray indices, LongNdArray values, Shape shape)Creates a Sparse array of long values with a default value of zerostatic ShortSparseNdArraysparseOf(LongNdArray indices, ShortNdArray values, short defaultValue, Shape shape)Creates a Sparse array of short valuesstatic ShortSparseNdArraysparseOf(LongNdArray indices, ShortNdArray values, Shape shape)Creates a Sparse array of short values with a default value of zerostatic <T> NdArray<T>sparseOfObjects(Class<T> type, LongNdArray indices, NdArray<T> values, Shape shape)Creates a Sparse array of values with a null default valuestatic <T> NdArray<T>sparseOfObjects(Class<T> type, LongNdArray indices, NdArray<T> values, T defaultValue, Shape shape)Creates a Sparse array of valuesstatic BooleanNdArrayvectorOf(boolean... values)Creates a boolean vector (rank 1) initialized with the given values.static ByteNdArrayvectorOf(byte... values)Creates a byte vector (rank 1) initialized with the given values.static DoubleNdArrayvectorOf(double... values)Creates a double vector (rank 1) initialized with the given values.static FloatNdArrayvectorOf(float... values)Creates a float vector (rank 1) initialized with the given values.static IntNdArrayvectorOf(int... values)Creates a int vector (rank 1) initialized with the given values.static LongNdArrayvectorOf(long... values)Creates a long vector (rank 1) initialized with the given values.static ShortNdArrayvectorOf(short... values)Creates a short vector (rank 1) initialized with the given values.static <T> NdArray<T>vectorOfObjects(T... values)Creates a vector (rank 1) initialized with the given values.static BooleanNdArraywrap(Shape shape, BooleanDataBuffer buffer)Wraps a buffer in a boolean N-dimensional array of a given shape.static ByteNdArraywrap(Shape shape, ByteDataBuffer buffer)Wraps a buffer in a byte N-dimensional array of a given shape.static <T> NdArray<T>wrap(Shape shape, DataBuffer<T> buffer)Wraps a buffer in an N-dimensional array of a given shape.static DoubleNdArraywrap(Shape shape, DoubleDataBuffer buffer)Wraps a buffer in a double N-dimensional array of a given shape.static FloatNdArraywrap(Shape shape, FloatDataBuffer buffer)Wraps a buffer in a float N-dimensional array of a given shape.static IntNdArraywrap(Shape shape, IntDataBuffer buffer)Wraps a buffer in an int N-dimensional array of a given shape.static LongNdArraywrap(Shape shape, LongDataBuffer buffer)Wraps a buffer in a long N-dimensional array of a given shape.static ShortNdArraywrap(Shape shape, ShortDataBuffer buffer)Wraps a buffer in a short N-dimensional array of a given shape.
-
-
-
Method Detail
-
scalarOf
public static ByteNdArray scalarOf(byte value)
Creates byte scalar (rank 0) initialized with the given value.- Parameters:
value- scalar value- Returns:
- new byte scalar
-
vectorOf
public static ByteNdArray vectorOf(byte... values)
Creates a byte vector (rank 1) initialized with the given values.Modifying the data of the returned vector will also impact the values in the array passed in parameter.
- Parameters:
values- vector values- Returns:
- new byte vector
- Throws:
IllegalArgumentException- if values is null
-
ofBytes
public static ByteNdArray ofBytes(Shape shape)
Creates an N-dimensional array of bytes of the given shape.All values are initialized to zeros.
- Parameters:
shape- shape of the array- Returns:
- new byte N-dimensional array
- Throws:
IllegalArgumentException- if shape is null or has unknown dimensions
-
wrap
public static ByteNdArray wrap(Shape shape, ByteDataBuffer buffer)
Wraps a buffer in a byte N-dimensional array of a given shape.- Parameters:
shape- shape of the arraybuffer- buffer to wrap- Returns:
- new byte N-dimensional array
- Throws:
IllegalArgumentException- if shape is null, has unknown dimensions or has size bigger in the buffer size
-
sparseOf
public static ByteSparseNdArray sparseOf(LongNdArray indices, ByteNdArray values, Shape shape)
Creates a Sparse array of byte values with a default value of zero- Parameters:
indices- A 2-D LongNdArray of shape[N, ndims], that specifies the indices of the elements in the sparse array that contain non-default values (elements are zero-indexed). For example,indices=[[1,3,1], [2,4,0]]specifies that the elements with indexes of[1,3,1]and[2,4,0]have non-default values.values- A 1-D ByteNdArray of shape[N], which supplies the values for each element in indices. For example, givenindices=[[1,3,1], [2,4,0]], the parametervalues=[18, 3]specifies that element[1,3,1]of the sparse NdArray has a value of18, and element[2,4,0]of the NdArray has a value of3.shape- the shape of the dense array represented by this sparse array.- Returns:
- the byte sparse array.
-
sparseOf
public static ByteSparseNdArray sparseOf(LongNdArray indices, ByteNdArray values, byte defaultValue, Shape shape)
Creates a Sparse array of byte values- Parameters:
indices- A 2-D LongNdArray of shape[N, ndims], that specifies the indices of the elements in the sparse array that contain non-default values (elements are zero-indexed). For example,indices=[[1,3,1], [2,4,0]]specifies that the elements with indexes of[1,3,1]and[2,4,0]have non default values.values- A 1-D ByteNdArray of shape[N], which supplies the values for each element in indices. For example, givenindices=[[1,3,1], [2,4,0]], the parametervalues=[18, 3]specifies that element[1,3,1]of the sparse NdArray has a value of18, and element[2,4,0]of the NdArray has a value of3.defaultValue- Scalar value to set for indices not specified in 'indices'shape- the shape of the dense array represented by this sparse array.- Returns:
- the byte sparse array.
-
scalarOf
public static LongNdArray scalarOf(long value)
Creates long scalar (rank 0) initialized with the given value.- Parameters:
value- scalar value- Returns:
- new long scalar
-
vectorOf
public static LongNdArray vectorOf(long... values)
Creates a long vector (rank 1) initialized with the given values.Modifying the data of the returned vector will also impact the values in the array passed in parameter.
- Parameters:
values- vector values- Returns:
- new long vector
- Throws:
IllegalArgumentException- if values is null
-
ofLongs
public static LongNdArray ofLongs(Shape shape)
Creates an N-dimensional array of longs of the given shape.All values are initialized to zeros.
- Parameters:
shape- shape of the array- Returns:
- new long N-dimensional array
- Throws:
IllegalArgumentException- if shape is null or has unknown dimensions
-
wrap
public static LongNdArray wrap(Shape shape, LongDataBuffer buffer)
Wraps a buffer in a long N-dimensional array of a given shape.- Parameters:
shape- shape of the arraybuffer- buffer to wrap- Returns:
- new long N-dimensional array
- Throws:
IllegalArgumentException- if shape is null, has unknown dimensions or has size bigger in the buffer size
-
sparseOf
public static LongSparseNdArray sparseOf(LongNdArray indices, LongNdArray values, Shape shape)
Creates a Sparse array of long values with a default value of zero- Parameters:
indices- A 2-D LongNdArray of shape[N, ndims], that specifies the indices of the elements in the sparse array that contain non-default values (elements are zero-indexed). For example,indices=[[1,3,1], [2,4,0]]specifies that the elements with indexes of[1,3,1]and[2,4,0]have non-default values.values- A 1-D LongNdArray of shape[N], which supplies the values for each element in indices. For example, givenindices=[[1,3,1], [2,4,0]], the parametervalues=[18L, 3L]specifies that element[1,3,1]of the sparse NdArray has a value of18L, and element[2,4,0]of the NdArray has a value of3L.shape- the shape of the dense array represented by this sparse array.- Returns:
- the long sparse array.
-
sparseOf
public static LongSparseNdArray sparseOf(LongNdArray indices, LongNdArray values, long defaultValue, Shape shape)
Creates a Sparse array of long values with a default value of zero- Parameters:
indices- A 2-D LongNdArray of shape[N, ndims], that specifies the indices of the elements in the sparse array that contain non-default values (elements are zero-indexed). For example,indices=[[1,3,1], [2,4,0]]specifies that the elements with indexes of[1,3,1]and[2,4,0]have non-default values.values- A 1-D LongNdArray of shape[N], which supplies the values for each element in indices. For example, givenindices=[[1,3,1], [2,4,0]], the parametervalues=[18L, 3L]specifies that element[1,3,1]of the sparse NdArray has a value of18L, and element[2,4,0]of the NdArray has a value of3L.defaultValue- Scalar value to set for indices not specified in 'indices'shape- the shape of the dense array represented by this sparse array.- Returns:
- the long sparse array.
-
scalarOf
public static IntNdArray scalarOf(int value)
Creates long scalar (rank 0) initialized with the given value.- Parameters:
value- scalar value- Returns:
- new long scalar
-
vectorOf
public static IntNdArray vectorOf(int... values)
Creates a int vector (rank 1) initialized with the given values.Modifying the data of the returned vector will also impact the values in the array passed in parameter.
- Parameters:
values- vector values- Returns:
- new int vector
- Throws:
IllegalArgumentException- if values is null
-
ofInts
public static IntNdArray ofInts(Shape shape)
Creates an N-dimensional array of ints of the given shape.All values are initialized to zeros.
- Parameters:
shape- shape of the array- Returns:
- new int N-dimensional array
- Throws:
IllegalArgumentException- if shape is null or has unknown dimensions
-
wrap
public static IntNdArray wrap(Shape shape, IntDataBuffer buffer)
Wraps a buffer in an int N-dimensional array of a given shape.- Parameters:
shape- shape of the arraybuffer- buffer to wrap- Returns:
- new int N-dimensional array
- Throws:
IllegalArgumentException- if shape is null, has unknown dimensions or has size bigger in the buffer size
-
sparseOf
public static IntSparseNdArray sparseOf(LongNdArray indices, IntNdArray values, Shape shape)
Creates a Sparse array of int values with a default value of zero.- Parameters:
indices- A 2-D LongNdArray of shape[N, ndims], that specifies the indices of the elements in the sparse array that contain non-default values (elements are zero-indexed). For example,indices=[[1,3,1], [2,4,0]]specifies that the elements with indexes of[1,3,1]and[2,4,0]have non-default values.values- A 1-D IntNdArray of shape[N], which supplies the values for each element in indices. For example, givenindices=[[1,3,1], [2,4,0]], the parametervalues=[18, 3]specifies that element[1,3,1]of the sparse NdArray has a value of18, and element[2,4,0]of the NdArray has a value of3.shape- the shape of the dense array represented by this sparse array.- Returns:
- the int sparse array.
-
sparseOf
public static IntSparseNdArray sparseOf(LongNdArray indices, IntNdArray values, int defaultValue, Shape shape)
Creates a Sparse array of int values- Parameters:
indices- A 2-D LongNdArray of shape[N, ndims], that specifies the indices of the elements in the sparse array that contain non-default values (elements are zero-indexed). For example,indices=[[1,3,1], [2,4,0]]specifies that the elements with indexes of[1,3,1]and[2,4,0]have non-default values.values- A 1-D IntNdArray of shape[N], which supplies the values for each element in indices. For example, givenindices=[[1,3,1], [2,4,0]], the parametervalues=[18, 3]specifies that element[1,3,1]of the sparse NdArray has a value of18, and element[2,4,0]of the NdArray has a value of3.defaultValue- Scalar value to set for indices not specified in 'indices'shape- the shape of the dense array represented by this sparse array.- Returns:
- the int sparse array.
-
scalarOf
public static ShortNdArray scalarOf(short value)
Creates short scalar (rank 0) initialized with the given value.- Parameters:
value- scalar value- Returns:
- new short scalar
-
vectorOf
public static ShortNdArray vectorOf(short... values)
Creates a short vector (rank 1) initialized with the given values.Modifying the data of the returned vector will also impact the values in the array passed in parameter.
- Parameters:
values- vector values- Returns:
- new short vector
- Throws:
IllegalArgumentException- if values is null
-
ofShorts
public static ShortNdArray ofShorts(Shape shape)
Creates an N-dimensional array of shorts of the given shape.All values are initialized to zeros.
- Parameters:
shape- shape of the array- Returns:
- new short N-dimensional array
- Throws:
IllegalArgumentException- if shape is null or has unknown dimensions
-
wrap
public static ShortNdArray wrap(Shape shape, ShortDataBuffer buffer)
Wraps a buffer in a short N-dimensional array of a given shape.- Parameters:
shape- shape of the arraybuffer- buffer to wrap- Returns:
- new short N-dimensional array
- Throws:
IllegalArgumentException- if shape is null, has unknown dimensions or has size bigger in the buffer size
-
sparseOf
public static ShortSparseNdArray sparseOf(LongNdArray indices, ShortNdArray values, Shape shape)
Creates a Sparse array of short values with a default value of zero- Parameters:
indices- A 2-D LongNdArray of shape[N, ndims], that specifies the indices of the elements in the sparse array that contain non-default values (elements are zero-indexed). For example,indices=[[1,3,1], [2,4,0]]specifies that the elements with indexes of[1,3,1]and[2,4,0]have non-default values.values- A 1-D ShortNdArray of shape[N], which supplies the values for each element in indices. For example, givenindices=[[1,3,1], [2,4,0]], the parametervalues=[18, 3]specifies that element[1,3,1]of the sparse NdArray has a value of18, and element[2,4,0]of the NdArray has a value of3.shape- the shape of the dense array represented by this sparse array.- Returns:
- the short sparse array.
-
sparseOf
public static ShortSparseNdArray sparseOf(LongNdArray indices, ShortNdArray values, short defaultValue, Shape shape)
Creates a Sparse array of short values- Parameters:
indices- A 2-D LongNdArray of shape[N, ndims], that specifies the indices of the elements in the sparse array that contain non-default values (elements are zero-indexed). For example,indices=[[1,3,1], [2,4,0]]specifies that the elements with indexes of[1,3,1]and[2,4,0]have non-default values.values- A 1-D ShortNdArray of shape[N], which supplies the values for each element in indices. For example, givenindices=[[1,3,1], [2,4,0]], the parametervalues=[18, 3]specifies that element[1,3,1]of the sparse NdArray has a value of18, and element[2,4,0]of the NdArray has a value of3.defaultValue- Scalar value to set for indices not specified in 'indices'shape- the shape of the dense array represented by this sparse array.- Returns:
- the short sparse array.
-
scalarOf
public static FloatNdArray scalarOf(float value)
Creates float scalar (rank 0) initialized with the given value.- Parameters:
value- scalar value- Returns:
- new float scalar
-
vectorOf
public static FloatNdArray vectorOf(float... values)
Creates a float vector (rank 1) initialized with the given values.Modifying the data of the returned vector will also impact the values in the array passed in parameter.
- Parameters:
values- vector values- Returns:
- new float vector
- Throws:
IllegalArgumentException- if values is null
-
ofFloats
public static FloatNdArray ofFloats(Shape shape)
Creates an N-dimensional array of floats of the given shape.All values are initialized to zeros.
- Parameters:
shape- shape of the array- Returns:
- new float N-dimensional array
- Throws:
IllegalArgumentException- if shape is null or has unknown dimensions
-
wrap
public static FloatNdArray wrap(Shape shape, FloatDataBuffer buffer)
Wraps a buffer in a float N-dimensional array of a given shape.- Parameters:
shape- shape of the arraybuffer- buffer to wrap- Returns:
- new float N-dimensional array
- Throws:
IllegalArgumentException- if shape is null, has unknown dimensions or has size bigger in the buffer size
-
sparseOf
public static FloatSparseNdArray sparseOf(LongNdArray indices, FloatNdArray values, Shape shape)
Creates a Sparse array of float values with a default value of zero- Parameters:
indices- A 2-D LongNdArray of shape[N, ndims], that specifies the indices of the elements in the sparse array that contain non-default values (elements are zero-indexed). For example,indices=[[1,3,1], [2,4,0]]specifies that the elements with indexes of[1,3,1]and[2,4,0]have non-default values.values- A 1-D FloatNdArray of shape[N], which supplies the values for each element in indices. For example, givenindices=[[1,3,1], [2,4,0]], the parametervalues=[18f, 3.8f]specifies that element[1,3,1]of the sparse NdArray has a value of18f, and element[2,4,0]of the NdArray has a value of3.8f.shape- the shape of the dense array represented by this sparse array.- Returns:
- the float sparse array.
-
sparseOf
public static FloatSparseNdArray sparseOf(LongNdArray indices, FloatNdArray values, float defaultValue, Shape shape)
Creates a Sparse array of float values- Parameters:
indices- A 2-D LongNdArray of shape[N, ndims], that specifies the indices of the elements in the sparse array that contain non-default values (elements are zero-indexed). For example,indices=[[1,3,1], [2,4,0]]specifies that the elements with indexes of[1,3,1]and[2,4,0]have non-default values.values- A 1-D FloatNdArray of shape[N], which supplies the values for each element in indices. For example, givenindices=[[1,3,1], [2,4,0]], the parametervalues=[18f, 3.8f]specifies that element[1,3,1]of the sparse NdArray has a value of18f, and element[2,4,0]of the NdArray has a value of3.8f.defaultValue- Scalar value to set for indices not specified in 'indices'shape- the shape of the dense array represented by this sparse array.- Returns:
- the float sparse array.
-
scalarOf
public static DoubleNdArray scalarOf(double value)
Creates double scalar (rank 0) initialized with the given value.- Parameters:
value- scalar value- Returns:
- new double scalar
-
vectorOf
public static DoubleNdArray vectorOf(double... values)
Creates a double vector (rank 1) initialized with the given values.Modifying the data of the returned vector will also impact the values in the array passed in parameter.
- Parameters:
values- vector values- Returns:
- new double vector
- Throws:
IllegalArgumentException- if values is null
-
ofDoubles
public static DoubleNdArray ofDoubles(Shape shape)
Creates an N-dimensional array of doubles of the given shape.All values are initialized to zeros.
- Parameters:
shape- shape of the array- Returns:
- new double N-dimensional array
- Throws:
IllegalArgumentException- if shape is null or has unknown dimensions
-
wrap
public static DoubleNdArray wrap(Shape shape, DoubleDataBuffer buffer)
Wraps a buffer in a double N-dimensional array of a given shape.- Parameters:
shape- shape of the arraybuffer- buffer to wrap- Returns:
- new double N-dimensional array
- Throws:
IllegalArgumentException- if shape is null, has unknown dimensions or has size bigger in the buffer size
-
sparseOf
public static DoubleSparseNdArray sparseOf(LongNdArray indices, DoubleNdArray values, Shape shape)
Creates a Sparse array of double values with a default value of zero- Parameters:
indices- A 2-D LongNdArray of shape[N, ndims], that specifies the indices of the elements in the sparse array that contain non-default values (elements are zero-indexed). For example,indices=[[1,3,1], [2,4,0]]specifies that the elements with indexes of[1,3,1]and[2,4,0]have non-default values.values- A 1-D DoubleNdArray of shape[N], which supplies the values for each element in indices. For example, givenindices=[[1,3,1], [2,4,0]], the parametervalues=[18, 3.8]specifies that element[1,3,1]of the sparse NdArray has a value of18, and element[2,4,0]of the NdArray has a value of3.8.shape- the shape of the dense array represented by this sparse array.- Returns:
- the float sparse array.
-
sparseOf
public static DoubleSparseNdArray sparseOf(LongNdArray indices, DoubleNdArray values, double defaultValue, Shape shape)
Creates a Sparse array of double values- Parameters:
indices- A 2-D LongNdArray of shape[N, ndims], that specifies the indices of the elements in the sparse array that contain non-default values (elements are zero-indexed). For example,indices=[[1,3,1], [2,4,0]]specifies that the elements with indexes of[1,3,1]and[2,4,0]have non-default values.values- A 1-D DoubleNdArray of shape[N], which supplies the values for each element in indices. For example, givenindices=[[1,3,1], [2,4,0]], the parametervalues=[18, 3.8]specifies that element[1,3,1]of the sparse NdArray has a value of18, and element[2,4,0]of the NdArray has a value of3.8.defaultValue- Scalar value to set for indices not specified in 'indices'shape- the shape of the dense array represented by this sparse array.- Returns:
- the float sparse array.
-
scalarOf
public static BooleanNdArray scalarOf(boolean value)
Creates boolean scalar (rank 0) initialized with the given value.- Parameters:
value- scalar value- Returns:
- new boolean scalar
-
vectorOf
public static BooleanNdArray vectorOf(boolean... values)
Creates a boolean vector (rank 1) initialized with the given values.Modifying the data of the returned vector will also impact the values in the array passed in parameter.
- Parameters:
values- vector values- Returns:
- new boolean vector
- Throws:
IllegalArgumentException- if values is null
-
ofBooleans
public static BooleanNdArray ofBooleans(Shape shape)
Creates an N-dimensional array of booleans of the given shape.All values are initialized to zeros.
- Parameters:
shape- shape of the array- Returns:
- new boolean N-dimensional array
- Throws:
IllegalArgumentException- if shape is null or has unknown dimensions
-
wrap
public static BooleanNdArray wrap(Shape shape, BooleanDataBuffer buffer)
Wraps a buffer in a boolean N-dimensional array of a given shape.- Parameters:
shape- shape of the arraybuffer- buffer to wrap- Returns:
- new boolean N-dimensional array
- Throws:
IllegalArgumentException- if shape is null, has unknown dimensions or has size bigger in the buffer size
-
sparseOf
public static BooleanSparseNdArray sparseOf(LongNdArray indices, BooleanNdArray values, Shape shape)
Creates a Sparse array of boolean values with a default value of 'false'- Parameters:
indices- A 2-D LongNdArray of shape[N, ndims], that specifies the indices of the elements in the sparse array that contain non-default values (elements are zero-indexed). For example,indices=[[1,3,1], [2,4,0]]specifies that the elements with indexes of[1,3,1]and[2,4,0]have non-default values.values- A 1-D BooleanNdArray of shape[N], which supplies the values for each element in indices. For example, givenindices=[[1,3,1], [2,4,0]], the parametervalues=[true, true]specifies that element[1,3,1]of the sparse NdArray has a value of true, and element[2,4,0]of the NdArray has a value of true. All other values are false.shape- the shape of the dense array represented by this sparse array.- Returns:
- the float sparse array.
-
sparseOf
public static BooleanSparseNdArray sparseOf(LongNdArray indices, BooleanNdArray values, boolean defaultValue, Shape shape)
Creates a Sparse array of boolean values- Parameters:
indices- A 2-D LongNdArray of shape[N, ndims], that specifies the indices of the elements in the sparse array that contain non-default values (elements are zero-indexed). For example,indices=[[1,3,1], [2,4,0]]specifies that the elements with indexes of[1,3,1]and[2,4,0]have non-default values.values- A 1-D BooleanNdArray of shape[N], which supplies the values for each element in indices. For example, givenindices=[[1,3,1], [2,4,0]], the parametervalues=[true, true]specifies that element[1,3,1]of the sparse NdArray has a value of true, and element[2,4,0]of the NdArray has a value of true. All other values are false.defaultValue- Scalar value to set for indices not specified in 'indices'shape- the shape of the dense array represented by this sparse array.- Returns:
- the float sparse array.
-
scalarOfObject
public static <T> NdArray<T> scalarOfObject(T value)
Creates scalar (rank 0) initialized with the given value.- Type Parameters:
T- the data type- Parameters:
value- scalar value- Returns:
- new scalar
-
vectorOfObjects
@SafeVarargs public static <T> NdArray<T> vectorOfObjects(T... values)
Creates a vector (rank 1) initialized with the given values.Modifying the data of the returned vector will also impact the values in the array passed in parameter.
- Type Parameters:
T- the data type- Parameters:
values- vector values- Returns:
- new vector
- Throws:
IllegalArgumentException- if values is null
-
ofObjects
public static <T> NdArray<T> ofObjects(Class<T> clazz, Shape shape)
Creates an N-dimensional array of the given shape.All values are initialized to zeros.
- Type Parameters:
T- the data type- Parameters:
clazz- class of the data to be stored in this arrayshape- shape of the array- Returns:
- new N-dimensional array
- Throws:
IllegalArgumentException- if shape is null or has unknown dimensions
-
wrap
public static <T> NdArray<T> wrap(Shape shape, DataBuffer<T> buffer)
Wraps a buffer in an N-dimensional array of a given shape.- Type Parameters:
T- the data type- Parameters:
shape- shape of the arraybuffer- buffer to wrap- Returns:
- new N-dimensional array
- Throws:
IllegalArgumentException- if shape is null, has unknown dimensions or has size bigger in the buffer size
-
sparseOfObjects
public static <T> NdArray<T> sparseOfObjects(Class<T> type, LongNdArray indices, NdArray<T> values, Shape shape)
Creates a Sparse array of values with a null default value- Parameters:
type- the class type represented by this sparse array.indices- A 2-D LongNdArray of shape[N, ndims], that specifies the indices of the elements in the sparse array that contain non-default values (elements are zero-indexed). For example,indices=[[1,3,1], [2,4,0]]specifies that the elements with indexes of[1,3,1]and[2,4,0]have non-default values.values- A 1-D NdArray of shape[N], which supplies the values for each element in indices. For example, givenindices=[[1,3,1], [2,4,0]], the parametervalues=["one", "two"]specifies that element[1,3,1]of the sparse NdArray has a value of "one", and element[2,4,0]of the NdArray has a value of "two"". All other values are null.shape- the shape of the dense array represented by this sparse array.- Returns:
- the float sparse array.
-
sparseOfObjects
public static <T> NdArray<T> sparseOfObjects(Class<T> type, LongNdArray indices, NdArray<T> values, T defaultValue, Shape shape)
Creates a Sparse array of values- Parameters:
type- the class type represented by this sparse array.indices- A 2-D LongNdArray of shape[N, ndims], that specifies the indices of the elements in the sparse array that contain non-default values (elements are zero-indexed). For example,indices=[[1,3,1], [2,4,0]]specifies that the elements with indexes of[1,3,1]and[2,4,0]have non-default values.values- A 1-D NdArray of shape[N], which supplies the values for each element in indices. For example, givenindices=[[1,3,1], [2,4,0]], the parametervalues=["one", "two"]specifies that element[1,3,1]of the sparse NdArray has a value of "one", and element[2,4,0]of the NdArray has a value of "two"". All other values are null.defaultValue- Scalar value to set for indices not specified in 'indices'shape- the shape of the dense array represented by this sparse array.- Returns:
- the float sparse array.
-
-