Class MultiArray<T>

  • Type Parameters:
    T - generics for primitive array (ie. double[], float[], int[] ...)
    Direct Known Subclasses:
    MultiArrayBoolean, MultiArrayByte, MultiArrayChar, MultiArrayDouble, MultiArrayFloat, MultiArrayInt, MultiArrayLong, MultiArrayObject, MultiArrayShort

    public abstract class MultiArray<T>
    extends java.lang.Object
    Multi-dimensional arrays of any type. Implements the indexing logic but no explicit data storage. Use the factory method to create MultiArray of the appropriate type and dimension. If you want to create an uninitialized MultiArray, directly use the Factory method for the required type.

    The data is stored in row-major in a flat double array.

    Author:
    Alexxander Krimm
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int[] dimensions  
      protected T elements  
      protected int offset  
      protected int[] strides  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected MultiArray​(T elements, int[] dimensions, int offset)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T elements()  
      int[] getDimensions()  
      int getElementsCount()  
      int getIndex​(int[] indices)  
      int[] getIndices​(int index)  
      int getOffset()  
      java.lang.String toString()  
      static <O> MultiArray<O> wrap​(O elements)
      Creates a 1D MultiArray of the given type if supported.
      static <O> MultiArray<O> wrap​(O elements, int offset)
      Creates a 1D MultiArray of the given type if supported.
      static <O> MultiArray<O> wrap​(O elements, int[] dimensions)
      Creates a MultiArray of the given type and dimension if supported
      static <O> MultiArray<O> wrap​(O elements, int offset, int[] dimensions)
      Creates a MultiArray of the given type and dimension if supported
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • elements

        protected final T elements
      • dimensions

        protected final int[] dimensions
      • strides

        protected final int[] strides
      • offset

        protected final int offset
    • Constructor Detail

      • MultiArray

        protected MultiArray​(T elements,
                             int[] dimensions,
                             int offset)
    • Method Detail

      • wrap

        public static <O> MultiArray<O> wrap​(O elements,
                                             int[] dimensions)
        Creates a MultiArray of the given type and dimension if supported
        Type Parameters:
        O - Type of the underlying array
        Parameters:
        elements - Array of the data in row major storage
        dimensions - int array of the dimensions
        Returns:
        A specific MultiArray implementation
      • wrap

        public static <O> MultiArray<O> wrap​(O elements,
                                             int offset,
                                             int[] dimensions)
        Creates a MultiArray of the given type and dimension if supported
        Type Parameters:
        O - Type of the underlying array
        Parameters:
        elements - Array of the data in row major storage
        offset - where in the backing array the element data starts
        dimensions - int array of the dimensions
        Returns:
        A specific MultiArray implementation
      • wrap

        public static <O> MultiArray<O> wrap​(O elements)
        Creates a 1D MultiArray of the given type if supported.
        Type Parameters:
        O - Type of the underlying array
        Parameters:
        elements - Array of the data in row major storage
        Returns:
        A specific MultiArray implementation
      • wrap

        public static <O> MultiArray<O> wrap​(O elements,
                                             int offset)
        Creates a 1D MultiArray of the given type if supported.
        Type Parameters:
        O - Type of the underlying array
        Parameters:
        elements - Array of the data in row major storage
        offset - where in the backing array the element data starts
        Returns:
        A specific MultiArray implementation
      • getDimensions

        public int[] getDimensions()
        Returns:
        The dimensions of the MultiArray as an int[] array
      • getOffset

        public int getOffset()
        Returns:
        the position in the array where the data starts
      • getElementsCount

        public int getElementsCount()
        Returns:
        The number of elements in the MultiArray
      • getIndex

        public int getIndex​(int[] indices)
        Parameters:
        indices - Indices for which to get the position in the linear array.
        Returns:
        position in the strided array
      • getIndices

        public int[] getIndices​(int index)
        Parameters:
        index - position in the strided array
        Returns:
        indices of the given element
      • elements

        public T elements()
        Returns:
        the underlying raw array
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object