public class ShapeUtils extends Object
Modifier and Type | Method and Description |
---|---|
static boolean |
areShapesBroadcastCompatible(int[] ashape,
int[] bshape)
Check if shapes are broadcast compatible
|
static boolean |
areShapesCompatible(int[] ashape,
int[] bshape)
Check if shapes are compatible, ignoring extra axes of length 1
|
static boolean |
areShapesCompatible(int[] ashape,
int[] bshape,
int axis)
Check if shapes are compatible but skip axis
|
static long |
calcLongSize(int[] shape)
Calculate total number of items in given shape
|
static int[] |
calcShapePadding(int[] aShape,
int[] bShape)
Calculate the padding difference between two shapes.
|
static int |
calcSize(int[] shape)
Calculate total number of items in given shape
|
static int[] |
checkAxes(int rank,
int... axes)
Check that all axes are in range [-rank,rank)
|
static int |
checkAxis(int rank,
int axis)
Check that axis is in range [-rank,rank)
|
static void |
checkCompatibility(ILazyDataset g,
ILazyDataset h)
This function takes a dataset and checks its shape against another dataset.
|
static boolean |
differsByOnes(int[] a,
int[] b) |
static int |
getFlat1DIndex(int[] shape,
int[] pos)
Get flattened view index of given position
|
static int[] |
getNDPositionFromShape(int n,
int[] shape)
Get n-D position from given index
|
static int[] |
getReducedShapeKeepRank(int[] shape,
int... axes)
Set reduced axes to 1
|
static int[] |
getRemainingAxes(int rank,
int... axes) |
static int[] |
getShapeFromObject(Object obj)
Get shape from object (array or list supported)
|
static boolean |
isZeroSize(int[] shape)
Check if size is zero
|
static int[] |
reduceShape(int[] shape,
int... axes)
Remove axes from shape
|
static int[] |
squeezeShape(int[] shape,
boolean onlyFromEnds)
Remove dimensions of 1 in given shape - from both ends only, if true
|
static int[] |
squeezeShape(int[] shape,
int axis)
Remove dimension of 1 in given shape
|
public static long calcLongSize(int[] shape)
shape
- dataset shapepublic static int calcSize(int[] shape)
shape
- dataset shapepublic static boolean isZeroSize(int[] shape)
shape
- dataset shapepublic static boolean areShapesBroadcastCompatible(int[] ashape, int[] bshape)
ashape
- first shapebshape
- second shapepublic static boolean areShapesCompatible(int[] ashape, int[] bshape)
ashape
- first shapebshape
- second shapepublic static boolean areShapesCompatible(int[] ashape, int[] bshape, int axis)
ashape
- first shapebshape
- second shapeaxis
- to skippublic static int[] squeezeShape(int[] shape, boolean onlyFromEnds)
shape
- dataset shapeonlyFromEnds
- if true, trim endspublic static int[] squeezeShape(int[] shape, int axis)
shape
- dataset shapeaxis
- to removepublic static int[] getShapeFromObject(Object obj)
obj
- objectpublic static int[] getNDPositionFromShape(int n, int[] shape)
n
- absolute indexshape
- dataset shapepublic static int getFlat1DIndex(int[] shape, int[] pos)
shape
- dataset shapepos
- the integer array specifying the n-D positionpublic static void checkCompatibility(ILazyDataset g, ILazyDataset h) throws IllegalArgumentException
g
- The first dataset to be comparedh
- The second dataset to be comparedIllegalArgumentException
- This will be thrown if there is a problem with the compatibilitypublic static int checkAxis(int rank, int axis)
rank
- number of dimensionsaxis
- dimension to checkpublic static int[] checkAxes(int rank, int... axes)
rank
- number of dimensionsaxes
- to skippublic static int[] getRemainingAxes(int rank, int... axes)
rank
- number of dimensionsaxes
- to skippublic static int[] reduceShape(int[] shape, int... axes)
shape
- to useaxes
- to removepublic static int[] getReducedShapeKeepRank(int[] shape, int... axes)
shape
- inputaxes
- to set to 1public static boolean differsByOnes(int[] a, int[] b)
a
- first shapeb
- second shapepublic static int[] calcShapePadding(int[] aShape, int[] bShape)
aShape
- first shapebShape
- second shapeIllegalArgumentException
- if one shape is null but not the other, or if shapes do
not possess common non-unit lengthsCopyright © 2014–2022 Eclipse Foundation. All rights reserved.