public abstract class AbstractNdArray<T,U extends NdArray<T>> extends Object implements NdArray<T>
| Modifier and Type | Field and Description |
|---|---|
protected DimensionalSpace |
dimensions |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractNdArray(DimensionalSpace dimensions) |
| Modifier and Type | Method and Description |
|---|---|
DimensionalSpace |
dimensions() |
boolean |
equals(Object obj)
Checks equality between n-dimensional arrays.
|
int |
hashCode() |
NdArraySequence<U> |
scalars()
Returns a sequence of all scalars in this array.
|
Shape |
shape() |
abstract U |
slice(long position,
DimensionalSpace dimensions) |
protected void |
slowCopyTo(NdArray<T> array) |
protected boolean |
slowEquals(NdArray<?> array) |
protected int |
slowHashCode() |
protected final DimensionalSpace dimensions
protected AbstractNdArray(DimensionalSpace dimensions)
public abstract U slice(long position, DimensionalSpace dimensions)
public DimensionalSpace dimensions()
public Shape shape()
public NdArraySequence<U> scalars()
NdArrayThis is equivalent to call elements(shape().numDimensions() - 1)
public boolean equals(Object obj)
NdArrayAn array is equal to another object if this object is another NdArray of the
same shape, type and the elements are equal and in the same order. For example:
IntNdArray array = NdArrays.ofInts(Shape.of(2, 2))
.set(NdArrays.vectorOf(1, 2), 0)
.set(NdArrays.vectorOf(3, 4), 1);
assertEquals(array, StdArrays.ndCopyOf(new int[][] {{1, 2}, {3, 4}})); // true
assertEquals(array, StdArrays.ndCopyOf(new Integer[][] {{1, 2}, {3, 4}})); // true, as Integers are equal to ints
assertNotEquals(array, NdArrays.vectorOf(1, 2, 3, 4)); // false, different shapes
assertNotEquals(array, StdArrays.ndCopyOf(new int[][] {{3, 4}, {1, 2}})); // false, different order
assertNotEquals(array, StdArrays.ndCopyOf(new long[][] {{1L, 2L}, {3L, 4L}})); // false, different types
Note that the computation required to verify equality between two arrays can be expensive in some cases and therefore, it is recommended to not use this method in a critical path where performances matter.
protected int slowHashCode()
protected boolean slowEquals(NdArray<?> array)
Copyright © 2015–2020. All rights reserved.