Package com.linkedin.dagli.math.mdarray
Class MDArrays
java.lang.Object
com.linkedin.dagli.math.mdarray.MDArrays
public abstract class MDArrays
extends java.lang.Object
Static utility methods for
MDArrays.-
Method Summary
Modifier and Type Method Description static voidcheckValidIndices(long[] indices, long[] shape)Checks that the provided indices are valid in an array of a given shape, throwing anIllegalArgumentExceptionif they are not.static long[]concatenate(long[] prefix, long[] suffix)Concatenates two arrays of longs; this is primarily useful for manipulating indices and shapes.static longelementCount(long[] shape)Gets the number of values in anMDArraywith the specified shape.static longindicesToOffset(long[] indices, long[] shape)Calculates the canonical offset of an element located at a given array of indices.static long[]offsetToIndices(long offset, long[] shape)Calculates the indices of an element in anMDArraygiven its offset.static booleanvalidIndices(long[] indices, long[] shape)Checks if the provided indices fall within a shape.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Method Details
-
elementCount
public static long elementCount(long[] shape)Gets the number of values in anMDArraywith the specified shape.- Parameters:
shape- the shape of the MDArray- Returns:
- the number of values the MDArray stores (including 0s)
-
offsetToIndices
public static long[] offsetToIndices(long offset, long[] shape)Calculates the indices of an element in anMDArraygiven its offset. AnIllegalArgumentExceptionwill be thrown if it falls outside the bounds of the array.- Parameters:
offset- the canonical offset of the elementshape- the shape of theMDArray- Returns:
- the indices of the element at the given offset
-
indicesToOffset
public static long indicesToOffset(long[] indices, long[] shape)Calculates the canonical offset of an element located at a given array of indices.- Parameters:
indices- the indices of the element whose offset should be calculatedshape- the shape of theMDArraycontaining the element- Returns:
- the element's 0-based offset
-
validIndices
public static boolean validIndices(long[] indices, long[] shape)Checks if the provided indices fall within a shape.- Parameters:
indices- the indices to checkshape- the shape- Returns:
- true if the indices are a valid location within an
MDArraywith the given shape
-
checkValidIndices
public static void checkValidIndices(long[] indices, long[] shape)Checks that the provided indices are valid in an array of a given shape, throwing anIllegalArgumentExceptionif they are not.- Parameters:
indices- the indices to checkshape- the shape of the array
-
concatenate
public static long[] concatenate(long[] prefix, long[] suffix)Concatenates two arrays of longs; this is primarily useful for manipulating indices and shapes.- Parameters:
prefix- the indices that will comprise the first part of the resulting arraysuffix- the indices that will comprise the second part of the resulting array- Returns:
- an array of the elements of
prefixfollowed bysuffix
-