public class Shape extends Object
Modifier and Type | Method and Description |
---|---|
static boolean |
areShapesBroadcastable(@NonNull int[] x,
@NonNull int[] y) |
static boolean |
areShapesBroadcastable(@NonNull long[] left,
@NonNull long[] right) |
static void |
assertBroadcastable(@NonNull INDArray x,
@NonNull INDArray y) |
static void |
assertBroadcastable(@NonNull int[] x,
@NonNull int[] y) |
static void |
assertBroadcastable(@NonNull long[] x,
@NonNull long[] y) |
static void |
assertBroadcastable(@NonNull long[] x,
@NonNull long[] y,
Class<?> opClass) |
static void |
assertBroadcastable(String op,
INDArray first,
INDArray second,
INDArray result)
Assert that the broadcast operation
result = first.op(second) is valid, given the
shapes of first, second, and result.Throws an exception otherwise |
static void |
assertShapeLessThan(int[] shape,
int[] lessThan)
Assert the both shapes are the same length
and shape[i] < lessThan[i]
|
static void |
assertShapeLessThan(long[] shape,
long[] lessThan) |
static void |
assertValidOrder(char order) |
static int[] |
broadcastOutputShape(int[] left,
int[] right)
Get the broadcast output shape
based on the 2 input shapes
Result output shape based on:
https://docs.scipy.org/doc/numpy-1.10.1/user/basics.broadcasting.html
|
static long[] |
broadcastOutputShape(long[] left,
long[] right) |
static String |
bufferToString(IntBuffer buffer)
Prints the
IntBuffer |
static boolean |
containsZeros(long[] shapeOnly) |
static boolean |
contentEquals(int[] arr,
DataBuffer other)
Compare the contents of a buffer and
an array for equals
|
static boolean |
contentEquals(int[] arr,
IntBuffer other)
Compare the contents of a buffer and
an array for equals
|
static boolean |
contentEquals(long[] arr,
DataBuffer other) |
static boolean |
contentEquals(long[] arr,
IntBuffer other) |
static boolean |
contentEquals(long[] arr,
long[] other) |
static boolean |
contentEquals(long[] arr,
LongBuffer other) |
static boolean |
cOrFortranOrder(int[] shape,
int[] stride,
int elementStride)
Deprecated.
|
static boolean |
cOrFortranOrder(long[] shape,
long[] stride,
long elementStride)
Infer order from
|
static DataBuffer |
createShapeInformation(long[] shape,
long[] stride,
long elementWiseStride,
char order,
DataType dataType,
boolean empty) |
static DataBuffer |
createShapeInformation(long[] shape,
long[] stride,
long elementWiseStride,
char order,
long extras) |
static DataBuffer |
createSparseInformation(int[] flags,
long[] sparseOffsets,
int[] hiddenDimensions,
int underlyingRank) |
static int |
elementWiseStride(DataBuffer buffer)
Get the element wise stride for the
shape info buffer
|
static int |
elementWiseStride(int[] shape,
int[] stride,
boolean isFOrder) |
static int |
elementWiseStride(IntBuffer buffer)
Get the element wise stride for the
shape info buffer
|
static long |
elementWiseStride(long[] buffer)
Get the element wise stride for the
shape info buffer
|
static long |
elementWiseStride(long[] shape,
long[] stride,
boolean isFOrder) |
static long |
elementWiseStride(LongBuffer buffer) |
static int[] |
ensureAtMinRowVector(int... shape)
If a shape array is ony 1 in length
it returns a row vector
|
static long |
extras(long[] buffer) |
static int[] |
flags(DataBuffer buffer) |
static int[] |
getBroadcastDimensions(int[] left,
int[] right)
Compute the broadcast rules according to:
https://docs.scipy.org/doc/numpy-1.10.1/user/basics.broadcasting.html
Note that the array can be null if the arrays are already equal
in shape.
|
static int[] |
getBroadcastDimensions(long[] left,
long[] right) |
static double |
getDouble(INDArray arr,
int[] indices)
Get a double based on the array and given indices
|
static double |
getDouble(INDArray arr,
long... indices) |
static long |
getLong(INDArray arr,
long... indices) |
static int[] |
getMatrixMultiplyShape(int[] left,
int[] right)
Get the output shape of a matrix multiply
|
static long[] |
getMatrixMultiplyShape(long[] left,
long[] right) |
static long[] |
getMaxShape(INDArray... inputs)
Return the shape of the largest length array
based on the input
|
static long |
getOffset(DataBuffer shapeInformation,
int[] indices)
Deprecated.
|
static long |
getOffset(DataBuffer shapeInformation,
int row,
int col)
Get the offset of the specified [row,col] for the 2d array
|
static long |
getOffset(DataBuffer shapeInformation,
int dim0,
int dim1,
int dim2)
Get the offset of the specified [dim0,dim1,dim2] for the 3d array
|
static long |
getOffset(DataBuffer shapeInformation,
int dim0,
int dim1,
int dim2,
int dim3)
Get the offset of the specified [dim0,dim1,dim2,dim3] for the 4d array
|
static long |
getOffset(DataBuffer shapeInformation,
long... indices) |
static long |
getOffset(int[] shapeInformation,
int... indices) |
static long |
getOffset(IntBuffer shapeInformation,
int row,
int col)
Get the offset of the specified [row,col] for the 2d array
|
static long |
getOffset(IntBuffer shapeInformation,
int dim0,
int dim1,
int dim2)
Get the offset of the specified [dim0,dim1,dim2] for the 3d array
|
static long |
getOffset(IntBuffer shapeInformation,
int dim0,
int dim1,
int dim2,
int dim3)
Get the offset of the specified [dim0,dim1,dim2,dim3] for the 4d array
|
static long |
getOffset(IntBuffer shapeInformation,
long... indices) |
static long |
getOffset(long[] shapeInformation,
int... indices) |
static long |
getOffset(long[] shapeInformation,
long... indices) |
static long |
getOffset(LongBuffer shapeInformation,
long... indices)
Get the offset of the specified indices from the shape info buffer
|
static long |
getOffset(long baseOffset,
int[] shape,
int[] stride,
int... indices)
Get an offset for retrieval
from a data buffer
based on the given
shape stride and given indices
|
static long |
getOffsetUnsafe(DataBuffer shapeInformation,
int row,
int col)
Identical to
getOffset(DataBuffer, int, int) but without input validation on array rank |
static long |
getOffsetUnsafe(DataBuffer shapeInformation,
int dim0,
int dim1,
int dim2)
Identical to
getOffset(DataBuffer, int, int, int) but without input validation on array rank |
static long |
getOffsetUnsafe(DataBuffer shapeInformation,
int dim0,
int dim1,
int dim2,
int dim3) |
static long |
getOffsetUnsafe(int[] shapeInformation,
int row,
int col) |
static long |
getOffsetUnsafe(int[] shapeInformation,
int dim0,
int dim1,
int dim2) |
static long |
getOffsetUnsafe(int[] shapeInformation,
int dim0,
int dim1,
int dim2,
int dim3) |
static long |
getOffsetUnsafe(long[] shapeInformation,
long row,
long col) |
static long |
getOffsetUnsafe(long[] shapeInformation,
long dim0,
long dim1,
long dim2,
long dim3) |
static char |
getOrder(INDArray arr)
Infer the order for the ndarray based on the
array's strides
|
static char |
getOrder(int[] shape,
int[] stride,
int elementStride)
Infer order from
|
static char |
getOrder(long[] shape,
long[] stride,
long elementStride) |
static long[] |
getReducedShape(int[] wholeShape,
int[] dimensions)
Get the shape of the reduced array
|
static long[] |
getReducedShape(int[] wholeShape,
int[] dimensions,
boolean keepDims,
boolean newFormat)
Get the shape of the reduced array
|
static long[] |
getReducedShape(long[] wholeShape,
int[] dimensions) |
static long[] |
getReducedShape(long[] wholeShape,
int[] dimensions,
boolean keepDims) |
static long[] |
getReducedShape(long[] wholeShape,
int[] dimensions,
boolean keepDims,
boolean newFormat) |
static long |
getTADLength(int[] shape,
int... dimensions) |
static long |
getTADLength(long[] shape,
int... dimensions) |
static boolean |
hasDefaultStridesForShape(INDArray input) |
static int[] |
hiddenDimension(DataBuffer buffer) |
static long[] |
ind2sub(INDArray arr,
long index)
Convert a linear index to
the equivalent nd index based on the shape of the specified ndarray.
|
static int[] |
ind2sub(int[] shape,
long index)
Convert a linear index to
the equivalent nd index.
|
static int[] |
ind2sub(int[] shape,
long index,
long numIndices)
Convert a linear index to
the equivalent nd index
|
static long[] |
ind2sub(long[] shape,
long index) |
static long[] |
ind2sub(long[] shape,
long index,
long numIndices) |
static long[] |
ind2subC(INDArray arr,
long index)
Convert a linear index to
the equivalent nd index based on the shape of the specified ndarray.
|
static int[] |
ind2subC(int[] shape,
long index)
Convert a linear index to
the equivalent nd index.
|
static int[] |
ind2subC(int[] shape,
long index,
long numIndices)
Convert a linear index to
the equivalent nd index
|
static long[] |
ind2subC(long[] shape,
long index) |
static long[] |
ind2subC(long[] shape,
long index,
long numIndices) |
static boolean |
isB(@NonNull DataType x) |
static boolean |
isColumnVectorShape(int[] shape)
Returns true if the given shape is length 2 and
the size at element 1 is 1
|
static boolean |
isColumnVectorShape(long[] shape)
Returns true if the given shape length is 2
and the size at element 1 is 1
|
static boolean |
isContiguousInBuffer(INDArray in)
Are the elements in the buffer contiguous for this NDArray?
|
static boolean |
isEmpty(long[] shapeInfo) |
static boolean |
isMatrix(DataBuffer shapeInfo)
Returns whether the passed in shape is a matrix
|
static boolean |
isMatrix(int[] shape)
Returns whether the passed in shape is a matrix
|
static boolean |
isMatrix(IntBuffer shapeInfo)
Returns whether the passed in shape is a matrix
|
static boolean |
isMatrix(long[] shape) |
static boolean |
isPlaceholderShape(int[] shape)
Returns true if any shape has a -1
or a null or empty array is passed in
|
static boolean |
isPlaceholderShape(long[] shape) |
static boolean |
isR(@NonNull DataType x) |
static boolean |
isRowVectorShape(DataBuffer shapeInfo)
Returns true if the given shape is of length 1
or provided the shape length is 2:
element 0 is 1
|
static boolean |
isRowVectorShape(int[] shape)
Returns true if the given shape is of length 1
or provided the shape length is 2:
element 0 is 1
|
static boolean |
isRowVectorShape(IntBuffer shapeInfo)
Returns true if the given shape is of length 1
or provided the shape length is 2:
element 0 is 1
|
static boolean |
isRowVectorShape(long[] shape) |
static boolean |
isS(@NonNull DataType x) |
static boolean |
isVector(DataBuffer shapeInfo)
Returns whether the given shape is a vector
|
static boolean |
isVector(int[] shape)
Returns whether the given shape is a vector
|
static boolean |
isVector(IntBuffer shapeInfo)
Returns whether the given shape is a vector
|
static boolean |
isVector(long[] shape) |
static boolean |
isVector(LongBuffer shapeInfo) |
static boolean |
isWholeArray(int[] shape,
int... dimension)
Returns true if the dimension is null
or the dimension length is 1 and the first entry
is
Integer.MAX_VALUE |
static boolean |
isWholeArray(int rank,
int... dimension)
Returns true if the dimension is null
or the dimension length is 1 and the first entry
is
Integer.MAX_VALUE |
static boolean |
isWholeArray(long[] shape,
int... dimension) |
static boolean |
isZ(@NonNull DataType x) |
static void |
iterate(INDArray arr,
CoordinateFunction coordinateFunction)
Iterate over 2
coordinate spaces given 2 arrays
|
static void |
iterate(INDArray arr,
INDArray arr2,
CoordinateFunction coordinateFunction)
Iterate over 2
coordinate spaces given 2 arrays
|
static void |
iterate(int dimension,
int n,
int[] size,
int[] res,
CoordinateFunction func)
Iterate over a pair of coordinates
|
static void |
iterate(int dimension,
int n,
int[] size,
int[] res,
int dimension2,
int n2,
int[] size2,
int[] res2,
CoordinateFunction func)
Iterate over a pair of coordinates
|
static void |
iterate(int dimension,
int n,
long[] size,
long[] res,
CoordinateFunction func) |
static void |
iterate(int dimension,
int n,
long[] size,
long[] res,
int dimension2,
int n2,
long[] size2,
long[] res2,
CoordinateFunction func) |
static long |
length(DataBuffer buffer)
Gets the rank given the shape info buffer
|
static long |
length(int[] buffer) |
static int |
length(IntBuffer buffer)
Gets the rank given the shape info buffer
|
static long |
length(long[] buffer) |
static int |
length(LongBuffer buffer) |
static long |
lengthOf(int[] shape) |
static long |
lengthOf(long[] shape) |
static long |
lengthOfBuffer(@NonNull int[] shape,
@NonNull int[] stride)
Calculate the length of the buffer required to store the given shape with the given strides
|
static long |
lengthOfBuffer(@NonNull long[] shape,
@NonNull long[] stride)
Calculate the length of the buffer required to store the given shape with the given strides
|
static INDArray |
ndArrayDimFromInt(int... dimensions)
Create an INDArray to represent the (possibly null) int[] dimensions.
|
static INDArray |
newShapeNoCopy(INDArray arr,
int[] newShape,
boolean isFOrder) |
static INDArray |
newShapeNoCopy(INDArray arr,
long[] newShape,
boolean isFOrder)
A port of numpy's reshaping algorithm that leverages
no copy where possible and returns
null if the reshape
couldn't happen without copying
|
static int[] |
newStrides(int[] strides,
int newLength,
INDArrayIndex[] indexes) |
static int[] |
normalizeAxis(int rank,
int... axis) |
static int |
offset(DataBuffer buffer)
Deprecated.
|
static int |
offset(int[] buffer)
Deprecated.
|
static int |
offset(IntBuffer buffer)
Deprecated.
|
static int |
offset(long[] buffer)
Deprecated.
|
static long |
offset(LongBuffer buffer)
Deprecated.
|
static long |
options(long[] buffer) |
static char |
order(DataBuffer buffer)
Returns the order given the shape information
|
static char |
order(int[] buffer) |
static char |
order(IntBuffer buffer)
Returns the order given the shape information
|
static char |
order(long[] buffer) |
static char |
order(LongBuffer buffer) |
static DataType |
pickPairwiseDataType(@NonNull DataType typeX,
@NonNull DataType typeY) |
static DataType |
pickPairwiseDataType(@NonNull DataType typeX,
@NonNull Number number) |
static int |
rank(DataBuffer buffer)
Gets the rank given the shape info buffer
|
static int |
rank(int[] buffer) |
static int |
rank(IntBuffer buffer)
Gets the rank given the shape info buffer
|
static int |
rank(long[] buffer) |
static int |
rank(LongBuffer buffer) |
static int |
rankFromShape(int[] shape)
Return the rank for the given shape
|
static int |
rankFromShape(long[] shape) |
static long[] |
reductionShape(INDArray x,
int[] dimension,
boolean newFormat,
boolean keepDims)
Calculate the shape of the returned array, for a reduction along dimension
|
static int[] |
resolveNegativeShapeIfNeccessary(int[] newShape,
int[] shape) |
static boolean |
scalarEquals(int[] shape1,
int[] shape2)
Returns true if the given shapes are both scalars (0 dimension or shape[0] == 1)
|
static boolean |
scalarEquals(long[] shape1,
long[] shape2) |
static void |
setElementWiseStride(DataBuffer buffer,
int elementWiseStride)
Get the element wise stride for the
shape info buffer
|
static void |
setElementWiseStride(IntBuffer buffer,
int elementWiseStride)
Get the element wise stride for the
shape info buffer
|
static void |
setOrder(IntBuffer buffer,
char order)
Deprecated.
|
static long[] |
shape(DataBuffer buffer)
Get array shape from the buffer, as an int[]
|
static int[] |
shape(int[] buffer)
Get array shape from an int[]
|
static long[] |
shape(IntBuffer buffer)
Get array shape from the buffer, as an int[]
|
static long[] |
shape(long[] buffer) |
static long[] |
shape(LongBuffer buffer) |
static boolean |
shapeEquals(int[] shape1,
int[] shape2)
Returns whether 2 shapes are equals by checking for dimension semantics
as well as array equality
|
static boolean |
shapeEquals(long[] shape1,
long[] shape2)
Returns whether 2 shapes are equals by checking for dimension semantics
as well as array equality
|
static boolean |
shapeEqualWithSqueeze(long[] shape1,
long[] shape2)
Return true if the shapes are equal after removing any size 1 dimensions
For example, [1,3,4] and [3,4] are considered equal by this method.
|
static int |
shapeInfoLength(long rank)
Return the shape info length
given the rank
|
static int |
shapeInfoLength(long[] shape) |
static boolean |
shapeIsScalar(int[] shape)
Returns true if this shape is scalar
|
static boolean |
shapeIsScalar(long[] shape) |
static boolean |
shapeMatchesPlaceholder(long[] phShape,
long[] arrShape)
Determine whether the placeholder shape and the specified shape are compatible.
Shapes are compatible if: (a) They are both the same length (same array rank, or null) (b) At each position either phShape[i] == -1 or phShape[i] == arrShape[i] |
static DataBuffer |
shapeOf(DataBuffer buffer)
Get the shape from
the given int buffer
|
static int[] |
shapeOf(int[] buffer) |
static IntBuffer |
shapeOf(IntBuffer buffer)
Get the shape from
the given int buffer
|
static long[] |
shapeOf(long[] buffer) |
static LongBuffer |
shapeOf(LongBuffer buffer) |
static String |
shapeToString(INDArray arr)
Prints the shape
for this shape information
|
static String |
shapeToString(IntBuffer buffer)
Prints the shape
for this shape information
|
static String |
shapeToString(LongBuffer buffer) |
static String |
shapeToStringShort(INDArray arr) |
static int |
size(DataBuffer buffer,
int dimension)
Get the size of the specified dimension.
|
static int |
size(int[] buffer,
int dimension) |
static int |
size(IntBuffer buffer,
int dimension)
Get the size of the specified dimension.
|
static long |
size(long[] buffer,
int dimension) |
static long |
size(LongBuffer buffer,
int dimension) |
static long |
sizeAt(long[] shape,
int index) |
static int[] |
sizeForAxes(int[] axes,
int[] shape)
Output an int array for a particular dimension
|
static int |
sizeUnsafe(DataBuffer buffer,
int dimension)
Get the size of the specified dimension.
|
static int |
sizeUnsafe(int[] buffer,
int dimension) |
static long |
sizeUnsafe(long[] buffer,
int dimension) |
static int[] |
sparseOffsets(DataBuffer buffer) |
static int[] |
squeeze(int[] shape)
Gets rid of any singleton dimensions of the given array
|
static long[] |
squeeze(long[] shape)
Gets rid of any singleton dimensions of the given array
|
static DataBuffer |
stride(DataBuffer buffer)
Get the shape from
the given int buffer
|
static int |
stride(DataBuffer buffer,
int dimension)
Get the stride of the specified dimension
|
static int[] |
stride(int[] buffer) |
static int |
stride(int[] buffer,
int dimension) |
static IntBuffer |
stride(IntBuffer buffer)
Get the stride for the given
shape information buffer
|
static int |
stride(IntBuffer buffer,
int dimension)
Get the stride of the specified dimension
|
static long[] |
stride(long[] buffer) |
static long |
stride(long[] buffer,
int dimension) |
static LongBuffer |
stride(LongBuffer buffer) |
static long |
stride(LongBuffer buffer,
int dimension) |
static long[] |
strideArr(DataBuffer buffer)
Get array shape from the buffer, as an int[]
|
static boolean |
strideDescendingCAscendingF(INDArray array)
Check if strides are in order suitable for non-strided mmul etc.
|
static int[] |
stridesOf(int[] buffer) |
static long[] |
stridesOf(long[] buffer) |
static int |
strideUnsafe(DataBuffer buffer,
int dimension,
int rank)
Get the stride of the specified dimension, without any input validation
|
static int |
strideUnsafe(int[] buffer,
int dimension,
int rank) |
static long |
strideUnsafe(long[] buffer,
int dimension,
int rank) |
static long |
sub2Ind(int[] shape,
int[] indices)
Convert the given index (such as 1,1)
to a linear index
|
static IntBuffer |
toBuffer(int... arr)
Convert an array to a byte buffer
|
static INDArray |
toMmulCompatible(INDArray input)
This method is used in DL4J LSTM implementation
|
static INDArray |
toOffsetZero(INDArray arr)
Create a copy of the matrix
where the new offset is zero
|
static INDArray |
toOffsetZeroCopy(INDArray arr)
Create a copy of the ndarray where the new offset is zero
|
static INDArray |
toOffsetZeroCopy(INDArray arr,
char order)
Create a copy of the ndarray where the new offset is zero, and has specified order
|
static INDArray |
toOffsetZeroCopyAnyOrder(INDArray arr)
Create a copy of the ndarray where the new offset is zero.
|
static String |
toString(DataBuffer buffer)
To String for an int buffer
|
static String |
toString(IntBuffer buffer)
To String for an int buffer
|
static int |
underlyingRank(DataBuffer buffer) |
static int[] |
uniquify(int[] array) |
static boolean |
wholeArrayDimension(int... arr)
Returns true if the given array
is meant for the whole dimension
|
public static long[] getMaxShape(INDArray... inputs)
inputs
- the inputs to get the max shape forpublic static boolean shapeIsScalar(int[] shape)
shape
- the shape that is scalarpublic static boolean shapeIsScalar(long[] shape)
public static boolean isPlaceholderShape(int[] shape)
shape
- the input shape to validatepublic static boolean isPlaceholderShape(long[] shape)
public static int[] getBroadcastDimensions(int[] left, int[] right)
left
- the left arrayright
- the right array (the array to be broadcastedpublic static long sizeAt(long[] shape, int index)
public static int[] getBroadcastDimensions(long[] left, long[] right)
public static int[] broadcastOutputShape(int[] left, int[] right)
left
- the left shaperight
- the right secondpublic static boolean containsZeros(long[] shapeOnly)
public static void assertBroadcastable(String op, INDArray first, INDArray second, INDArray result)
result = first.op(second)
is valid, given the
shapes of first, second, and result.op
- Name of the operationfirst
- First arraysecond
- Second arrayresult
- Result arrray.public static long[] broadcastOutputShape(long[] left, long[] right)
public static int[] resolveNegativeShapeIfNeccessary(int[] newShape, int[] shape)
newShape
- the new shape possibly
containing a negative numbershape
- the shape to calculate frompublic static boolean isWholeArray(int[] shape, int... dimension)
Integer.MAX_VALUE
shape
- the shape of the input arraydimension
- the dimensions specifiedInteger.MAX_VALUE
public static boolean isWholeArray(long[] shape, int... dimension)
public static boolean isWholeArray(int rank, int... dimension)
Integer.MAX_VALUE
rank
- the rank of the input arraydimension
- the dimensions specifiedInteger.MAX_VALUE
public static long[] getReducedShape(int[] wholeShape, int[] dimensions)
wholeShape
- the shape of the array
with the reduce op being performeddimensions
- the dimensions the reduce op is being performed onpublic static long[] getReducedShape(long[] wholeShape, int[] dimensions)
public static long[] getReducedShape(int[] wholeShape, int[] dimensions, boolean keepDims, boolean newFormat)
wholeShape
- the shape of the array
with the reduce op being performeddimensions
- the dimensions the reduce op is being performed onkeepDims
- if set to true, corresponding dimensions will be set to 1public static long[] getReducedShape(long[] wholeShape, int[] dimensions, boolean keepDims)
public static long[] getReducedShape(long[] wholeShape, int[] dimensions, boolean keepDims, boolean newFormat)
public static int[] getMatrixMultiplyShape(int[] left, int[] right)
left
- the first matrix shape to multiplyright
- the second matrix shape to multiplypublic static long[] getMatrixMultiplyShape(long[] left, long[] right)
public static INDArray toOffsetZero(INDArray arr)
arr
- the array to copy to offset 0public static INDArray toOffsetZeroCopy(INDArray arr)
arr
- the array to copy to offset 0public static INDArray toOffsetZeroCopy(INDArray arr, char order)
arr
- the array to copy to offset 0order
- the order of the returned arraypublic static INDArray toOffsetZeroCopyAnyOrder(INDArray arr)
arr
- NDArray to duplicatepublic static double getDouble(INDArray arr, int[] indices)
arr
- the array to retrieve the double fromindices
- the indices to iterate overpublic static double getDouble(INDArray arr, long... indices)
public static long getLong(INDArray arr, long... indices)
public static void iterate(INDArray arr, CoordinateFunction coordinateFunction)
arr
- the first arraycoordinateFunction
- the coordinate function to usepublic static void iterate(INDArray arr, INDArray arr2, CoordinateFunction coordinateFunction)
arr
- the first arrayarr2
- the second arraycoordinateFunction
- the coordinate function to usepublic static void iterate(int dimension, int n, int[] size, int[] res, int dimension2, int n2, int[] size2, int[] res2, CoordinateFunction func)
dimension
- n
- size
- res
- dimension2
- n2
- size2
- res2
- func
- public static void iterate(int dimension, int n, long[] size, long[] res, int dimension2, int n2, long[] size2, long[] res2, CoordinateFunction func)
public static void iterate(int dimension, int n, int[] size, int[] res, CoordinateFunction func)
dimension
- n
- size
- public static void iterate(int dimension, int n, long[] size, long[] res, CoordinateFunction func)
public static long getOffset(long baseOffset, int[] shape, int[] stride, int... indices)
baseOffset
- the offset to start fromshape
- the shape of the arraystride
- the stride of the arrayindices
- the indices to iterate overpublic static long getOffset(LongBuffer shapeInformation, long... indices)
shapeInformation
- Shape information to get the offset forindices
- Indices array to get the offset for (must be same length as array rank)public static long getOffset(IntBuffer shapeInformation, long... indices)
@Deprecated public static long getOffset(DataBuffer shapeInformation, int[] indices)
shapeInformation
- Shape information to get the offset forindices
- Indices array to get the offset for (must be same length as array rank)public static long getOffset(DataBuffer shapeInformation, long... indices)
public static long getOffset(int[] shapeInformation, int... indices)
public static long getOffset(long[] shapeInformation, int... indices)
public static long getOffset(long[] shapeInformation, long... indices)
public static long getOffset(DataBuffer shapeInformation, int row, int col)
shapeInformation
- Shape informationrow
- Row index to get the offset forcol
- Column index to get the offset forpublic static long getOffsetUnsafe(DataBuffer shapeInformation, int row, int col)
getOffset(DataBuffer, int, int)
but without input validation on array rankpublic static long getOffsetUnsafe(int[] shapeInformation, int row, int col)
public static long getOffsetUnsafe(long[] shapeInformation, long row, long col)
public static long getOffset(IntBuffer shapeInformation, int row, int col)
shapeInformation
- Shape informationrow
- Row index to get the offset forcol
- Column index to get the offset forpublic static long getOffset(IntBuffer shapeInformation, int dim0, int dim1, int dim2)
shapeInformation
- Shape informationdim0
- Row index to get the offset fordim1
- Column index to get the offset fordim2
- dimension 2 index to get the offset forpublic static long getOffset(DataBuffer shapeInformation, int dim0, int dim1, int dim2)
shapeInformation
- Shape informationdim0
- Row index to get the offset fordim1
- Column index to get the offset fordim2
- dimension 2 index to get the offset forpublic static long getOffsetUnsafe(DataBuffer shapeInformation, int dim0, int dim1, int dim2)
getOffset(DataBuffer, int, int, int)
but without input validation on array rankpublic static long getOffsetUnsafe(int[] shapeInformation, int dim0, int dim1, int dim2)
public static long getOffset(IntBuffer shapeInformation, int dim0, int dim1, int dim2, int dim3)
shapeInformation
- Shape informationdim0
- Row index to get the offset fordim1
- Column index to get the offset fordim2
- dimension 2 index to get the offset fordim3
- dimension 3 index to get the offset forpublic static long getOffset(DataBuffer shapeInformation, int dim0, int dim1, int dim2, int dim3)
shapeInformation
- Shape informationdim0
- Row index to get the offset fordim1
- Column index to get the offset fordim2
- dimension 2 index to get the offset fordim3
- dimension 3 index to get the offset forpublic static long getOffsetUnsafe(DataBuffer shapeInformation, int dim0, int dim1, int dim2, int dim3)
public static long getOffsetUnsafe(int[] shapeInformation, int dim0, int dim1, int dim2, int dim3)
public static long getOffsetUnsafe(long[] shapeInformation, long dim0, long dim1, long dim2, long dim3)
public static int[] sizeForAxes(int[] axes, int[] shape)
axes
- the axesshape
- the current shapepublic static boolean isVector(IntBuffer shapeInfo)
shapeInfo
- the shapeinfo to testpublic static boolean isVector(LongBuffer shapeInfo)
public static boolean isVector(DataBuffer shapeInfo)
shapeInfo
- the shapeinfo to testpublic static boolean isVector(int[] shape)
shape
- the shape to testpublic static boolean isVector(long[] shape)
public static boolean isMatrix(IntBuffer shapeInfo)
shapeInfo
- whether the passed in shape is a matrixpublic static boolean isMatrix(DataBuffer shapeInfo)
shapeInfo
- whether the passed in shape is a matrixpublic static boolean isMatrix(int[] shape)
shape
- whether the passed in shape is a matrixpublic static boolean isMatrix(long[] shape)
public static int[] squeeze(int[] shape)
shape
- the shape to squeezepublic static long[] squeeze(long[] shape)
shape
- the shape to squeezepublic static boolean shapeEqualWithSqueeze(long[] shape1, long[] shape2)
shape1
- First shapeshape2
- Second shapepublic static boolean shapeEquals(int[] shape1, int[] shape2)
shape1
- the first shape for comparisonshape2
- the second shape for comparisonpublic static boolean shapeEquals(long[] shape1, long[] shape2)
shape1
- the first shape for comparisonshape2
- the second shape for comparisonpublic static boolean scalarEquals(int[] shape1, int[] shape2)
shape1
- the first shape for comparisonshape2
- the second shape for comparisonpublic static boolean scalarEquals(long[] shape1, long[] shape2)
public static boolean isRowVectorShape(DataBuffer shapeInfo)
shapeInfo
- the shape info to checkpublic static boolean isRowVectorShape(IntBuffer shapeInfo)
shapeInfo
- the shape info to checkpublic static boolean isRowVectorShape(int[] shape)
shape
- the shape to checkpublic static boolean isRowVectorShape(long[] shape)
public static boolean isColumnVectorShape(int[] shape)
shape
- the shape to checkpublic static boolean isColumnVectorShape(long[] shape)
shape
- public static int[] ensureAtMinRowVector(int... shape)
shape
- the shape of the arraypublic static long getTADLength(int[] shape, int... dimensions)
public static long getTADLength(long[] shape, int... dimensions)
public static int elementWiseStride(int[] shape, int[] stride, boolean isFOrder)
shape
- stride
- isFOrder
- public static long elementWiseStride(long[] shape, long[] stride, boolean isFOrder)
public static INDArray newShapeNoCopy(INDArray arr, int[] newShape, boolean isFOrder)
public static INDArray newShapeNoCopy(INDArray arr, long[] newShape, boolean isFOrder)
arr
- the array to reshapenewShape
- the new shapeisFOrder
- whether the array will be fortran ordered or notpublic static boolean cOrFortranOrder(long[] shape, long[] stride, long elementStride)
shape
- the shape to infer bystride
- the stride to infer byelementStride
- the element stride to start at@Deprecated public static boolean cOrFortranOrder(int[] shape, int[] stride, int elementStride)
public static char getOrder(int[] shape, int[] stride, int elementStride)
shape
- the shape to infer bystride
- the stride to infer byelementStride
- the element stride to start atpublic static char getOrder(long[] shape, long[] stride, long elementStride)
public static char getOrder(INDArray arr)
arr
- the array to get the
ordering forpublic static long sub2Ind(int[] shape, int[] indices)
shape
- the shape of the indexes to convertindices
- the index to convertpublic static int[] ind2sub(int[] shape, long index, long numIndices)
shape
- the shape of the dimensionsindex
- the index to mapnumIndices
- the number of total indices (typically prod of shape(public static long[] ind2sub(long[] shape, long index, long numIndices)
public static int[] ind2sub(int[] shape, long index)
shape
- the shape of the dimensionsindex
- the index to mappublic static long[] ind2sub(long[] shape, long index)
public static long[] ind2sub(INDArray arr, long index)
arr
- the array to compute the indexes
based onindex
- the index to mappublic static int[] ind2subC(int[] shape, long index, long numIndices)
shape
- the shape of the dimensionsindex
- the index to mapnumIndices
- the number of total indices (typically prod of shape(public static long[] ind2subC(long[] shape, long index, long numIndices)
public static int[] ind2subC(int[] shape, long index)
shape
- the shape of the dimensionsindex
- the index to mappublic static long[] ind2subC(long[] shape, long index)
public static long[] ind2subC(INDArray arr, long index)
arr
- the array to compute the indexes
based onindex
- the index to mappublic static void assertShapeLessThan(int[] shape, int[] lessThan)
shape
- the shape to checklessThan
- the shape to assert againstpublic static void assertShapeLessThan(long[] shape, long[] lessThan)
public static int[] newStrides(int[] strides, int newLength, INDArrayIndex[] indexes)
public static boolean strideDescendingCAscendingF(INDArray array)
public static int length(IntBuffer buffer)
buffer
- the buffer to get the rank forpublic static int length(LongBuffer buffer)
public static long length(DataBuffer buffer)
buffer
- the buffer to get the rank forpublic static long length(int[] buffer)
public static long length(long[] buffer)
public static int rank(DataBuffer buffer)
buffer
- the buffer to get the rank forpublic static int rank(IntBuffer buffer)
buffer
- the buffer to get the rank forpublic static int rank(LongBuffer buffer)
public static int rank(long[] buffer)
public static int rank(int[] buffer)
public static int size(IntBuffer buffer, int dimension)
buffer
- The buffer to get thedimension
- The dimension to get.public static long size(LongBuffer buffer, int dimension)
public static int size(DataBuffer buffer, int dimension)
buffer
- The buffer to get the shape fromdimension
- The dimension to get.public static int size(int[] buffer, int dimension)
public static long size(long[] buffer, int dimension)
public static int sizeUnsafe(DataBuffer buffer, int dimension)
buffer
- The buffer to get the shape fromdimension
- The dimension to get.public static int sizeUnsafe(int[] buffer, int dimension)
public static long sizeUnsafe(long[] buffer, int dimension)
public static long[] shape(IntBuffer buffer)
buffer
- Buffer to get the shape frompublic static long[] shape(LongBuffer buffer)
public static long[] shape(DataBuffer buffer)
buffer
- Buffer to get the shape frompublic static int[] shape(int[] buffer)
buffer
- Buffer to get the shape frompublic static long[] shape(long[] buffer)
public static int stride(IntBuffer buffer, int dimension)
buffer
- The buffer to get the stride fromdimension
- The dimension to get.public static long stride(LongBuffer buffer, int dimension)
public static int stride(DataBuffer buffer, int dimension)
buffer
- The buffer to get the stride fromdimension
- The dimension to get.public static int stride(int[] buffer, int dimension)
public static long stride(long[] buffer, int dimension)
public static long[] strideArr(DataBuffer buffer)
buffer
- Buffer to get the shape frompublic static int strideUnsafe(DataBuffer buffer, int dimension, int rank)
buffer
- The buffer to get the stride fromdimension
- The dimension to get.rank
- Rank of the arraypublic static int strideUnsafe(int[] buffer, int dimension, int rank)
public static long strideUnsafe(long[] buffer, int dimension, int rank)
public static int shapeInfoLength(long rank)
rank
- the rank to get the length forpublic static int shapeInfoLength(long[] shape)
public static IntBuffer stride(IntBuffer buffer)
buffer
- public static LongBuffer stride(LongBuffer buffer)
public static DataBuffer stride(DataBuffer buffer)
buffer
- the buffer to get the shape information forpublic static int[] stride(int[] buffer)
public static long[] stride(long[] buffer)
public static DataBuffer shapeOf(DataBuffer buffer)
buffer
- the buffer to get the shape information forpublic static IntBuffer shapeOf(IntBuffer buffer)
buffer
- the buffer to get the shape information forpublic static LongBuffer shapeOf(LongBuffer buffer)
public static int[] shapeOf(int[] buffer)
public static long[] shapeOf(long[] buffer)
public static int[] stridesOf(int[] buffer)
public static long[] stridesOf(long[] buffer)
public static int[] flags(DataBuffer buffer)
public static int[] sparseOffsets(DataBuffer buffer)
public static int[] hiddenDimension(DataBuffer buffer)
public static int underlyingRank(DataBuffer buffer)
public static String shapeToString(INDArray arr)
arr
- the shape information to printpublic static String shapeToString(IntBuffer buffer)
buffer
- the shape information to printpublic static String shapeToString(LongBuffer buffer)
@Deprecated public static int offset(DataBuffer buffer)
buffer
- the shape info buffer to get the offset forpublic static long options(long[] buffer)
public static long extras(long[] buffer)
@Deprecated public static int offset(int[] buffer)
buffer
- @Deprecated public static int offset(long[] buffer)
@Deprecated public static int offset(IntBuffer buffer)
buffer
- the shape info buffer to get the offset for@Deprecated public static long offset(LongBuffer buffer)
public static int elementWiseStride(DataBuffer buffer)
buffer
- the buffer to get the element
wise stride frompublic static int elementWiseStride(IntBuffer buffer)
buffer
- the buffer to get the element
wise stride frompublic static long elementWiseStride(LongBuffer buffer)
public static long elementWiseStride(long[] buffer)
buffer
- the buffer to get the element
wise stride frompublic static void setElementWiseStride(IntBuffer buffer, int elementWiseStride)
buffer
- the buffer to get the element
wise stride frompublic static void setElementWiseStride(DataBuffer buffer, int elementWiseStride)
buffer
- the buffer to get the element
wise stride frompublic static String bufferToString(IntBuffer buffer)
IntBuffer
buffer
- the buffer to printpublic static char order(IntBuffer buffer)
buffer
- the bufferpublic static char order(LongBuffer buffer)
public static char order(DataBuffer buffer)
buffer
- the bufferpublic static char order(int[] buffer)
public static char order(long[] buffer)
@Deprecated public static void setOrder(IntBuffer buffer, char order)
buffer
- the bufferpublic static DataBuffer createShapeInformation(long[] shape, long[] stride, long elementWiseStride, char order, DataType dataType, boolean empty)
public static DataBuffer createShapeInformation(long[] shape, long[] stride, long elementWiseStride, char order, long extras)
public static DataBuffer createSparseInformation(int[] flags, long[] sparseOffsets, int[] hiddenDimensions, int underlyingRank)
public static IntBuffer toBuffer(int... arr)
arr
- the arraypublic static String toString(IntBuffer buffer)
buffer
- public static String toString(DataBuffer buffer)
buffer
- public static boolean wholeArrayDimension(int... arr)
arr
- the array to testpublic static int[] uniquify(int[] array)
public static int[] normalizeAxis(int rank, int... axis)
public static boolean contentEquals(int[] arr, DataBuffer other)
arr
- the arrayother
- the bufferpublic static boolean contentEquals(long[] arr, long[] other)
public static boolean contentEquals(long[] arr, DataBuffer other)
public static boolean contentEquals(int[] arr, IntBuffer other)
arr
- the arrayother
- the bufferpublic static boolean contentEquals(long[] arr, IntBuffer other)
public static boolean contentEquals(long[] arr, LongBuffer other)
public static boolean isContiguousInBuffer(INDArray in)
public static INDArray toMmulCompatible(INDArray input)
input
- public static int rankFromShape(int[] shape)
shape
- Shape to get the rank forND4JIllegalStateException
- If shape array is nullpublic static int rankFromShape(long[] shape)
public static void assertBroadcastable(@NonNull @NonNull INDArray x, @NonNull @NonNull INDArray y)
public static void assertBroadcastable(@NonNull @NonNull int[] x, @NonNull @NonNull int[] y)
public static void assertBroadcastable(@NonNull @NonNull long[] x, @NonNull @NonNull long[] y)
public static void assertBroadcastable(@NonNull @NonNull long[] x, @NonNull @NonNull long[] y, Class<?> opClass)
public static boolean areShapesBroadcastable(@NonNull @NonNull int[] x, @NonNull @NonNull int[] y)
public static boolean areShapesBroadcastable(@NonNull @NonNull long[] left, @NonNull @NonNull long[] right)
public static long lengthOf(long[] shape)
shape
- public static long lengthOf(int[] shape)
public static long lengthOfBuffer(@NonNull @NonNull long[] shape, @NonNull @NonNull long[] stride)
shape
- Shape of the arraystride
- Stridespublic static long lengthOfBuffer(@NonNull @NonNull int[] shape, @NonNull @NonNull int[] stride)
shape
- Shape of the arraystride
- Stridespublic static boolean hasDefaultStridesForShape(INDArray input)
public static boolean isS(@NonNull @NonNull DataType x)
public static boolean isB(@NonNull @NonNull DataType x)
public static boolean isZ(@NonNull @NonNull DataType x)
public static boolean isR(@NonNull @NonNull DataType x)
public static DataType pickPairwiseDataType(@NonNull @NonNull DataType typeX, @NonNull @NonNull Number number)
public static DataType pickPairwiseDataType(@NonNull @NonNull DataType typeX, @NonNull @NonNull DataType typeY)
public static boolean isEmpty(long[] shapeInfo)
public static void assertValidOrder(char order)
public static INDArray ndArrayDimFromInt(int... dimensions)
dimensions
- Dimensions to convertpublic static long[] reductionShape(INDArray x, int[] dimension, boolean newFormat, boolean keepDims)
x
- Input array to reducedimension
- Dimensions/axis to reduce onnewFormat
- If new format (almost always true; will be removed eventually)keepDims
- If reduced dimensions should be kept as size 1 dimensionspublic static boolean shapeMatchesPlaceholder(long[] phShape, long[] arrShape)
phShape
- Placeholder shapearrShape
- Array shape to check if it matches the placeholder shapeCopyright © 2020. All rights reserved.