Package de.gsi.dataset.spi.utils
Class MultiArray<T>
- java.lang.Object
-
- de.gsi.dataset.spi.utils.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.ObjectMulti-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[]dimensionsprotected Telementsprotected intoffsetprotected int[]strides
-
Constructor Summary
Constructors Modifier Constructor Description protectedMultiArray(T elements, int[] dimensions, int offset)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Telements()int[]getDimensions()intgetElementsCount()intgetIndex(int[] indices)int[]getIndices(int index)intgetOffset()java.lang.StringtoString()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 supportedstatic <O> MultiArray<O>wrap(O elements, int offset, int[] dimensions)Creates a MultiArray of the given type and dimension if supported
-
-
-
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 storagedimensions- 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 storageoffset- where in the backing array the element data startsdimensions- 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 storageoffset- 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:
toStringin classjava.lang.Object
-
-