public class Shape extends Object
| Constructor and Description |
|---|
Shape() |
| 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 void |
assignArray(INDArray destination,
INDArray source) |
static int[] |
broadcastStrides(int nDim,
int[] shape,
int numStrideDimensions,
int[] strideShape,
int[] strides)
Broadcasts strides to match the given dimensions.
|
static INDArray |
copyArrayWithWholeBuffer(INDArray arr)
Copy the whole buffer whole sale
|
static boolean |
cOrFortranOrder(int[] shape,
int[] stride,
int elementStride)
Infer order from
|
static int[] |
createConcatStrides(INDArray... arrays)
A port of numpy's stride resolution algorithm
for multiple arrays
|
static StridePermutation[] |
createSortedStrides(int[] strides)
Creates sorted strides
whlie retaining the permutation
|
static void |
forEachOffset(INDArray[] arr,
CoordinateFunction coordinateFunction)
Iterates over
each possible
offset of an ndarray
|
static void |
forEachOffset(INDArray arr,
CoordinateFunction coordinateFunction)
Iterates over each possible offset of an ndarray
|
static double |
getDouble(INDArray arr,
int... indices)
Get a double based on the array and given indices
|
static int |
getOffset(int 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 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 int[] |
ind2sub(INDArray arr,
int index)
Convert a linear index to
the equivalent nd index based on the shape of the specified ndarray.
|
static int[] |
ind2sub(int[] shape,
int index)
Convert a linear index to
the equivalent nd index.
|
static int[] |
ind2sub(int[] shape,
int index,
int numIndices)
Convert a linear index to
the equivalent nd index
|
static int[] |
ind2subC(INDArray arr,
int index)
Convert a linear index to
the equivalent nd index based on the shape of the specified ndarray.
|
static int[] |
ind2subC(int[] shape,
int index)
Convert a linear index to
the equivalent nd index.
|
static int[] |
ind2subC(int[] shape,
int index,
int 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(int[] shape)
Returns whether the passed in shape is a matrix
|
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 |
isVector(int[] shape)
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[] |
leadingAndTrailingOnes(int[] original)
Get rid ones in the shape when
its not a vector
|
static int[] |
moveOnesToEnd(int[] shape)
Returns a permutation of the dimensions
with all 1s moved to end
|
static int[] |
newOffsets(int[] offsets,
int newLength,
INDArrayIndex[] indexes) |
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[] |
nonOneDimensions(int[] dimensions,
int[] shape)
Keep all the non one dimensions
|
static int |
offsetFor(INDArray arr,
int index)
Compute the offset for a given index
|
static int |
offsetFor(INDArray arr,
int[] indexes)
Compute the offset for the given array
given the indices
|
static boolean |
opIsWholeBufferWithMatchingStrides(Op op)
Checks the following:
each x,y,z is offset zero
op.n() is == data buffer.length()
all strides are equal
|
static boolean |
opIsWithMatchingStrides(Op op)
Checks the following:
each x,y,z is offset zero
op.n() is == data buffer.length()
all strides are equal
|
static RawArrayIterationInformation1 |
prepareRawArrayIter(INDArray dst)
Prepares two arrays for
raw iteration linearly through the data.
|
static RawArrayIterationInformation2 |
prepareTwoRawArrayIter(INDArray dst,
INDArray src)
Prepares two arrays for
raw iteration linearly through the data.
|
static int[] |
raw2dLoop(int idim,
int ndim,
int[] coord,
int[] shape,
int dataA,
int[] stridesA,
int dataB,
int[] stridesB,
RawArrayIterationInformation2 info,
LoopFunction2 loopFunction2)
Raw 2 dimensional loop
over a data buffer given some strides.
|
static int[] |
raw3dLoop(int idim,
int ndim,
int[] coord,
int[] shape,
int dataA,
int[] stridesA,
int dataB,
int[] stridesB,
int dataC,
int[] stridesC,
RawArrayIterationInformation3 info,
LoopFunction3 loopFunction3)
3 dimensional loop
Credit to:
https://github.com/numpy/numpy/blob/master/numpy/core/src/private/lowlevel_strided_loops.h#L548
|
static int[] |
raw4DLoop(int idim,
int ndim,
int[] coord,
int[] shape,
int dataA,
int[] stridesA,
int dataB,
int[] stridesB,
int dataC,
int[] stridesC,
int dataD,
int[] stridesD,
RawArrayIterationInformation4 info,
LoopFunction4 loopFunction4)
4 dimensional loop
Credit to:
https://github.com/numpy/numpy/blob/master/numpy/core/src/private/lowlevel_strided_loops.h#L548
|
static boolean |
scalarEquals(int[] shape1,
int[] shape2)
Returns true if the given shapes are both scalars (0 dimension or shape[0] == 1)
|
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[] |
sizeForAxes(int[] axes,
int[] shape)
Output an int array for a particular dimension
|
static int[] |
squeeze(int[] shape)
Gets rid of any singleton dimensions of the given array
|
static boolean |
squeezeEquals(int[] test1,
int[] test2)
Returns true for the case where
singleton dimensions are being compared
|
static int[] |
squeezeOffsets(int[] shape,
int[] offsets) |
static boolean |
strideDescendingCAscendingF(INDArray array)
Check if strides are in order suitable for non-strided mmul etc.
|
static int |
sub2Ind(int[] shape,
int[] indices)
Convert the given index (such as 1,1)
to a linear index
|
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.
|
public static INDArray toOffsetZero(INDArray arr)
arr - the array to copy to offset 0public static INDArray copyArrayWithWholeBuffer(INDArray arr)
arr - public 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 INDArray toMmulCompatible(INDArray input)
input - Input ndarraypublic 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 forEachOffset(INDArray[] arr, CoordinateFunction coordinateFunction)
arr - coordinateFunction - public static void forEachOffset(INDArray arr, CoordinateFunction coordinateFunction)
arr - coordinateFunction - public static void iterate(int dimension,
int n,
int[] size,
int[] res,
CoordinateFunction func)
dimension - n - size - public static int[] raw2dLoop(int idim,
int ndim,
int[] coord,
int[] shape,
int dataA,
int[] stridesA,
int dataB,
int[] stridesB,
RawArrayIterationInformation2 info,
LoopFunction2 loopFunction2)
idim - the current dimensionndim - the number of dimensionscoord - the current coordinateshape - the oerall shape of the arraydataA - the offset for data astridesA - the strides for adataB - the offset for data bstridesB - the strides for bpublic static int[] raw3dLoop(int idim,
int ndim,
int[] coord,
int[] shape,
int dataA,
int[] stridesA,
int dataB,
int[] stridesB,
int dataC,
int[] stridesC,
RawArrayIterationInformation3 info,
LoopFunction3 loopFunction3)
idim - ndim - coord - shape - dataA - stridesA - dataB - stridesB - dataC - stridesC - public static int[] raw4DLoop(int idim,
int ndim,
int[] coord,
int[] shape,
int dataA,
int[] stridesA,
int dataB,
int[] stridesB,
int dataC,
int[] stridesC,
int dataD,
int[] stridesD,
RawArrayIterationInformation4 info,
LoopFunction4 loopFunction4)
idim - ndim - coord - shape - dataA - stridesA - dataB - stridesB - dataC - stridesC - dataD - stridesD - public static int getOffset(int 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 int[] sizeForAxes(int[] axes,
int[] shape)
axes - the axesshape - the current shapepublic static boolean isVector(int[] shape)
shape - the shape to testpublic 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 int[] nonOneDimensions(int[] dimensions,
int[] shape)
dimensions - the dimensions to start withshape - the shapes to inspectpublic static int[] leadingAndTrailingOnes(int[] original)
original - the original shape
to prunepublic 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(int[] shape)
shape - the shape to checkpublic static boolean isColumnVectorShape(int[] shape)
shape - the shape to checkpublic static int[] createConcatStrides(INDArray... arrays)
arrays - the arrays to get concat strides forpublic static int[] broadcastStrides(int nDim,
int[] shape,
int numStrideDimensions,
int[] strideShape,
int[] strides)
nDim - the number of dimensions to iterate throughshape - the shape to compare broadcasting strides againstnumStrideDimensions - the number of stride dimensions to broadcaststrideShape - the shape of the stride to broadcaststrides - the strides to broadcastpublic static RawArrayIterationInformation1 prepareRawArrayIter(INDArray dst)
dst - the first arraypublic static RawArrayIterationInformation2 prepareTwoRawArrayIter(INDArray dst, INDArray src)
dst - the first arraysrc - the second arraypublic static StridePermutation[] createSortedStrides(int[] strides)
strides - the stridespublic 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 int sub2Ind(int[] shape,
int[] indices)
shape - the shape of the indexes to convertindices - the index to convertpublic static int[] ind2sub(int[] shape,
int index,
int 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,
int index)
shape - the shape of the dimensionsindex - the index to mappublic static int[] ind2sub(INDArray arr, int index)
arr - the array to compute the indexes
based onindex - the index to mappublic static int[] ind2subC(int[] shape,
int index,
int numIndices)
shape - the shape of the dimensionsindex - the index to mapnumIndices - the number of total indices (typically prod of shape(public static boolean opIsWholeBufferWithMatchingStrides(Op op)
op - the op to checkpublic static boolean opIsWithMatchingStrides(Op op)
op - the op to checkpublic static int[] ind2subC(int[] shape,
int index)
shape - the shape of the dimensionsindex - the index to mappublic static int[] ind2subC(INDArray arr, int index)
arr - the array to compute the indexes
based onindex - the index to mappublic static int offsetFor(INDArray arr, int[] indexes)
arr - the array to compute the offset forindexes - the indexes along each dimension to create the offset forpublic static int offsetFor(INDArray arr, int index)
arr - the array to compute the offset forindex - the linear index to compute the offset forpublic static void assertShapeLessThan(int[] shape,
int[] lessThan)
shape - the shape to checklessThan - the shape to assert againstpublic static int[] moveOnesToEnd(int[] shape)
shape - the shape to permutepublic static INDArrayIndex[] toIndexes(int[] indices)
indices - the indices to convertpublic static int[] newStrides(int[] strides,
int newLength,
INDArrayIndex[] indexes)
public static int[] newOffsets(int[] offsets,
int newLength,
INDArrayIndex[] indexes)
public static int[] squeezeOffsets(int[] shape,
int[] offsets)
public static boolean squeezeEquals(int[] test1,
int[] test2)
test1 - the first to testtest2 - the second to testpublic static boolean strideDescendingCAscendingF(INDArray array)
public static boolean isContiguousInBuffer(INDArray in)
Copyright © 2016. All Rights Reserved.