public class Shape extends Object
Modifier and Type | Method and Description |
---|---|
static void |
assertShapeLessThan(int[] shape,
int[] lessThan)
Assert the both shapes are the same length
and shape[i] < lessThan[i]
|
static String |
bufferToString(IntBuffer buffer) |
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 |
cOrFortranOrder(int[] shape,
int[] stride,
int elementStride)
Infer order from
|
static DataBuffer |
createShapeInformation(int[] shape,
int[] stride,
int offset,
int elementWiseStride,
char order)
Creates the shape information buffer
given the shape,stride
|
static StridePermutation[] |
createSortedStrides(int[] strides)
Creates sorted strides
whlie retaining the permutation
|
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 int[] |
ensureAtMinRowVector(int... shape)
If a shape array is ony 1 in length
it returns a row vector
|
static double |
getDouble(INDArray arr,
int... indices)
Get a double based on the array and given indices
|
static long |
getOffset(DataBuffer shapeInformation,
int... indices)
Get the offset of the specified indices from the shape info buffer
|
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(IntBuffer shapeInformation,
int... indices)
Get the offset of the specified indices from the shape info buffer
|
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(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 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 long |
getTADLength(int[] shape,
int... dimensions) |
static int[] |
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 int[] |
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 boolean |
isColumnVectorShape(int[] shape)
Returns true if the given shape is length 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 |
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 |
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 |
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 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 int |
length(DataBuffer buffer)
Gets the rank given the shape info buffer
|
static int |
length(IntBuffer buffer)
Gets the rank given the shape info buffer
|
static INDArray |
newShapeNoCopy(INDArray arr,
int[] 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 |
offset(DataBuffer buffer)
Get the offset for the buffer
|
static int |
offset(IntBuffer buffer)
Get the offset for the buffer
|
static long |
offsetFor(INDArray arr,
int[] indexes)
Compute the offset for the given array
given the indices
|
static char |
order(DataBuffer buffer)
Returns the order given the shape information
|
static char |
order(IntBuffer buffer)
Returns the order given the shape information
|
static RawArrayIterationInformation1 |
prepareRawArrayIter(INDArray dst)
Prepares two arrays for
raw iteration linearly through the data.
|
static int |
rank(DataBuffer buffer)
Gets the rank given the shape info buffer
|
static int |
rank(IntBuffer buffer)
Gets the rank given the shape info buffer
|
static boolean |
scalarEquals(int[] shape1,
int[] shape2)
Returns true if the given shapes are both scalars (0 dimension or shape[0] == 1)
|
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 int[] |
shape(DataBuffer buffer)
Get array shape from the buffer, as an int[]
|
static int[] |
shape(IntBuffer buffer)
Get array shape from the buffer, as an int[]
|
static boolean |
shapeEquals(int[] shape1,
int[] shape2)
Returns whether 2 shapes are equals by checking for dimension semantics
as well as array equality
|
static int |
shapeInfoLength(int rank)
Return the shape info length
given the rank
|
static DataBuffer |
shapeOf(DataBuffer buffer)
Get the shape from
the given int buffer
|
static IntBuffer |
shapeOf(IntBuffer buffer)
Get the shape from
the given int 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 int |
size(DataBuffer buffer,
int dimension)
Get the size of the specified dimension.
|
static int |
size(IntBuffer buffer,
int dimension)
Get the size of the specified dimension.
|
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[] |
squeeze(int[] 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 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 boolean |
strideDescendingCAscendingF(INDArray array)
Check if strides are in order suitable for non-strided mmul etc.
|
static int |
strideUnsafe(DataBuffer buffer,
int dimension,
int rank)
Get the stride of the specified dimension, without any input validation
|
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 INDArrayIndex[] |
toIndexes(int[] indices)
Convert the given int indexes
to nd array indexes
|
static INDArray |
toMmulCompatible(INDArray input)
Idea: make an matrix compatible for mmul without needing to be copied first
A matrix is compatible for mmul if its values are contiguous in memory. |
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 boolean |
wholeArrayDimension(int... arr)
Returns true if the given array
is meant for the whole dimension
|
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 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, int[] size, int[] res, CoordinateFunction func)
dimension
- n
- size
- 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(IntBuffer 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, 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, 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 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 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 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(DataBuffer shapeInfo)
shapeInfo
- the shapeinfo to testpublic static boolean isVector(int[] shape)
shape
- the shape to testpublic 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 int[] squeeze(int[] shape)
shape
- the shape to squeezepublic static boolean shapeEquals(int[] shape1, int[] 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 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 isColumnVectorShape(int[] shape)
shape
- the shape to checkpublic static RawArrayIterationInformation1 prepareRawArrayIter(INDArray dst)
dst
- the first arraypublic static StridePermutation[] createSortedStrides(int[] strides)
strides
- the stridespublic static int[] ensureAtMinRowVector(int... shape)
shape
- the shape of the arraypublic static long getTADLength(int[] shape, int... dimensions)
public static int elementWiseStride(int[] shape, int[] stride, boolean isFOrder)
shape
- stride
- isFOrder
- public static INDArray newShapeNoCopy(INDArray arr, int[] newShape, boolean isFOrder)
arr
- the array to reshapenewShape
- the new shapeisFOrder
- whether the array will be fortran ordered or notpublic static boolean cOrFortranOrder(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(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(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 int[] ind2sub(int[] shape, long index)
shape
- the shape of the dimensionsindex
- the index to mappublic static int[] 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 int[] ind2subC(int[] shape, long index)
shape
- the shape of the dimensionsindex
- the index to mappublic static int[] ind2subC(INDArray arr, long index)
arr
- the array to compute the indexes
based onindex
- the index to mappublic static long offsetFor(INDArray arr, int[] indexes)
arr
- the array to compute the offset forindexes
- the indexes along each dimension to create the offset forpublic static void assertShapeLessThan(int[] shape, int[] lessThan)
shape
- the shape to checklessThan
- the shape to assert againstpublic static INDArrayIndex[] toIndexes(int[] indices)
indices
- the indices to convertpublic 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(DataBuffer buffer)
buffer
- the buffer to get the rank forpublic 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 size(IntBuffer buffer, int dimension)
buffer
- The buffer to get thedimension
- The dimension to get.public static int size(DataBuffer buffer, int dimension)
buffer
- The buffer to get the shape fromdimension
- The dimension to get.public static int sizeUnsafe(DataBuffer buffer, int dimension)
buffer
- The buffer to get the shape fromdimension
- The dimension to get.public static int[] shape(IntBuffer buffer)
buffer
- Buffer to get the shape frompublic static int[] shape(DataBuffer buffer)
buffer
- Buffer to get the shape frompublic static int stride(IntBuffer buffer, int dimension)
buffer
- The buffer to get the stride fromdimension
- The dimension to get.public static int stride(DataBuffer buffer, int dimension)
buffer
- The buffer to get the stride fromdimension
- The dimension to get.public 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 shapeInfoLength(int rank)
rank
- the rank to get the length forpublic static IntBuffer stride(IntBuffer buffer)
buffer
- public static DataBuffer stride(DataBuffer buffer)
buffer
- the buffer to get the shape information forpublic 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 String shapeToString(INDArray arr)
arr
- the shape information to printpublic static String shapeToString(IntBuffer buffer)
buffer
- the shape information to printpublic static int offset(DataBuffer buffer)
buffer
- the shape info buffer to get the offset forpublic static int offset(IntBuffer buffer)
buffer
- the shape info buffer to get the offset forpublic 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 void setElementWiseStride(IntBuffer buffer, int elementWiseStride)
buffer
- the buffer to get the element
wise stride frompublic static char order(IntBuffer buffer)
buffer
- the bufferpublic static char order(DataBuffer buffer)
buffer
- the buffer@Deprecated public static void setOrder(IntBuffer buffer, char order)
buffer
- the bufferpublic static DataBuffer createShapeInformation(int[] shape, int[] stride, int offset, int elementWiseStride, char order)
shape
- the shape for the bufferstride
- the stride for the bufferoffset
- the offset for the bufferelementWiseStride
- the element wise stride for the bufferorder
- the order for the bufferpublic 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 boolean contentEquals(int[] arr, DataBuffer other)
arr
- the arrayother
- the bufferpublic static boolean contentEquals(int[] arr, IntBuffer other)
arr
- the arrayother
- the bufferpublic static boolean isContiguousInBuffer(INDArray in)
public static INDArray toMmulCompatible(INDArray input)
input
- Input ndarrayCopyright © 2016. All Rights Reserved.