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 void checkValidIndices​(long[] indices, long[] shape)
    Checks that the provided indices are valid in an array of a given shape, throwing an IllegalArgumentException if 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 long elementCount​(long[] shape)
    Gets the number of values in an MDArray with the specified shape.
    static long indicesToOffset​(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 an MDArray given its offset.
    static boolean validIndices​(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 an MDArray with 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 an MDArray given its offset. An IllegalArgumentException will be thrown if it falls outside the bounds of the array.
      Parameters:
      offset - the canonical offset of the element
      shape - the shape of the MDArray
      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 calculated
      shape - the shape of the MDArray containing 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 check
      shape - the shape
      Returns:
      true if the indices are a valid location within an MDArray with 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 an IllegalArgumentException if they are not.
      Parameters:
      indices - the indices to check
      shape - 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 array
      suffix - the indices that will comprise the second part of the resulting array
      Returns:
      an array of the elements of prefix followed by suffix