mikera.arrayz
Class NDArray
- java.lang.Object
-
- mikera.arrayz.impl.AbstractArray<INDArray>
-
- mikera.arrayz.impl.BaseShapedArray
-
- mikera.arrayz.impl.BaseNDArray
-
- mikera.arrayz.NDArray
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<INDArray>, java.lang.Iterable<INDArray>, IStridedArray, INDArray
public final class NDArray extends BaseNDArray
General purpose dense strided NDArray class. Allows arbitrary strided access over a dense double[] array.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidapplyOp(IOperator op)Applies a unary operator to all elements of the array (in-place)voidapplyOp(Op op)Applies a unary operator to all elements of the array (in-place)double[]asDoubleArray()Returns the underlying double array representing the densely packed elements of this array.AVectorasVector()Constructs a view of all elements in the array as a single vector in row-major order.INDArraybroadcast(int... dimensions)Returns a view of this array broadcasted up to a larger shapeINDArrayclone()Returns a clone of the array data, as a new array which will be fully mutable and may be of a different class to the original.java.util.Iterator<java.lang.Double>elementIterator()Returns an iterator over all elements in this array, in row-major orderbooleanequals(INDArray a)Checks if two arrays are equal exactly in terms of both value and shape Element equality checks are consistent with compareToNDArrayexactClone()Creates a deep clone of an array, using the same class implementation as the original arraydouble[]getArray()Gets the underlying data array for this strided array Unsafe operation - may allow modification of otherwise immutable arraysjava.util.List<INDArray>getSlices()Returns a list of all major slices of this array.INDArraygetTranspose()Returns the transpose of this array.INDArraygetTransposeView()Returns a transposed view of the array.INDArrayimmutable()Returns an immutable version of this array.booleanisElementConstrained()Returns true if this array has some constraints on element valuesbooleanisFullyMutable()If this method returns true, the INDArray is guaranteed to be fully mutable in all positions i.e.booleanisMutable()Returns true if the INDArray is mutable (at least partially)booleanisView()Return true if this array is considered as a view type.voidmultiply(double d)Multiplies all elements of the array in place by a given double valuestatic NDArraynewArray(int... shape)Creates a new zero-filled NDArray with the given shape.INDArrayreshape(int... dimensions)Returns a new array by rearranging the elements of this array into the desired shape Truncates or zero-pads the elements as required to fill the new shapevoidset(double value)Sets all elements of an array to a specific double valuevoidset(int[] indexes, double value)Sets the element at the given indexed position in a mutable arrayvoidset(int x, double value)Sets a value at a given position in a mutable 1D arrayvoidset(int x, int y, double value)Sets a value at a given position in a mutable 2D arrayvoidsetElements(int pos, double[] values, int offset, int length)Sets elements in an array using the given double values.INDArrayslice(int majorSlice)Returns the specified major slice of this array as a view (slice along dimension 0) 0 dimensional slice results are permitted, but attempting to slice a 0 dimensional array will result in an error.INDArrayslice(int dimension, int index)Returns a slice view of this array along the specified dimensionNDArraysubArray(int[] offsets, int[] shape)Returns a subarray view of a larger arrayvoidtoDoubleBuffer(java.nio.DoubleBuffer dest)Copies the elements of this INDArray to the specified double buffer.voidvalidate()Validates the internal data structure of the INDArray.static NDArraywrap(double[] data, int[] shape)Wraps the given double[] data in an NDArray with the given shape.static NDArraywrap(INDArray a)static NDArraywrap(IStridedArray a)static NDArraywrap(Matrix m)static NDArraywrap(Vector v)static INDArraywrapStrided(double[] data, int offset, int[] shape, int[] strides)-
Methods inherited from class mikera.arrayz.impl.BaseNDArray
dimensionality, elementCount, get, get, get, get, getArrayOffset, getIndex, getLongShape, getShape, getStride, getStrides, isPackedArray
-
Methods inherited from class mikera.arrayz.impl.BaseShapedArray
getElement, getShape, getShapeClone, isZero, reduce, reduce, sliceCount
-
Methods inherited from class mikera.arrayz.impl.AbstractArray
abs, absCopy, absDiff, absDiffCopy, add, add, add, addApplyOp, addAt, addCopy, addCopy, addCopy, addInnerProduct, addInnerProduct, addInnerProduct, addInnerProduct, addMultiple, addMultipleSparse, addOuterProduct, addOuterProductSparse, addPower, addPower, addSparse, addSparse, addToArray, applyOp, applyOp, applyOpCopy, asElementList, broadcastCloneLike, broadcastCopyLike, broadcastLike, broadcastLike, broadcastLike, clamp, compareTo, componentCount, copy, dense, denseClone, density, divide, divide, divideCopy, divideCopy, elementAbsPowSum, elementMax, elementMaxAbs, elementMin, elementPowSum, elementProduct, elementsEqual, elementSquaredSum, elementSum, ensureMutable, epsilonEquals, epsilonEquals, equals, equals, equalsArray, equalsArray, exp, fill, get, get, get, get, get, getComponent, getComponents, getElements, getElements, getElements, getElements, getSlices, getSliceViews, getTransposeCopy, hashCode, hasUncountable, innerProduct, innerProduct, innerProduct, innerProduct, isBoolean, isDense, isSameShape, isSparse, iterator, join, join, log, multiply, multiplyCopy, multiplyCopy, mutable, negate, negateCopy, nonZeroCount, outerProduct, pow, reciprocal, reciprocalCopy, reduceSlices, reduceSlices, reorder, reorder, rotateView, scale, scaleAdd, scaleAdd, scaleCopy, set, set, set, setApplyOp, setElements, setElements, setInnerProduct, setMultiple, setMultiple, setSparse, setSparse, signum, signumCopy, sliceValue, sparse, sparseClone, sqrt, square, squareCopy, sub, sub, sub, subCopy, toDoubleArray, toSliceArray, toString, toStringFull, toVector, withComponents
-
Methods inherited from interface mikera.arrayz.INDArray
abs, absCopy, absDiff, absDiffCopy, add, add, addApplyOp, addAt, addCopy, addCopy, addInnerProduct, addInnerProduct, addMultiple, addMultipleSparse, addOuterProduct, addOuterProductSparse, addPower, addPower, addSparse, addSparse, addToArray, applyOp, applyOp, applyOpCopy, asElementList, broadcastCloneLike, broadcastCopyLike, broadcastLike, broadcastLike, broadcastLike, clamp, componentCount, copy, dense, denseClone, divide, divide, divideCopy, divideCopy, elementAbsPowSum, elementMax, elementMaxAbs, elementMin, elementPowSum, elementProduct, elementsEqual, elementSquaredSum, elementSum, ensureMutable, epsilonEquals, epsilonEquals, equalsArray, equalsArray, exp, fill, get, get, get, get, get, getComponent, getComponents, getElement, getElements, getElements, getElements, getElements, getShape, getShapeClone, getSlices, getSliceViews, getTransposeCopy, hasUncountable, innerProduct, innerProduct, innerProduct, innerProduct, isBoolean, isDense, isSameShape, isSparse, isZero, join, join, log, multiply, multiplyCopy, multiplyCopy, mutable, negate, negateCopy, nonZeroCount, outerProduct, pow, reciprocal, reciprocalCopy, reduce, reduce, reduceSlices, reduceSlices, reorder, reorder, rotateView, scale, scaleAdd, scaleAdd, scaleCopy, set, set, set, setApplyOp, setElements, setElements, setInnerProduct, setMultiple, setMultiple, setSparse, setSparse, signum, signumCopy, sliceCount, sliceValue, sparse, sparseClone, sqrt, square, squareCopy, sub, sub, subCopy, toDoubleArray, toSliceArray, toVector, withComponents
-
-
-
-
Method Detail
-
wrap
public static NDArray wrap(double[] data, int[] shape)
Wraps the given double[] data in an NDArray with the given shape. Does *not* take a defensive copy of either the data or shape array.- Parameters:
data-shape-- Returns:
-
wrap
public static NDArray wrap(IStridedArray a)
-
newArray
public static NDArray newArray(int... shape)
Creates a new zero-filled NDArray with the given shape.- Parameters:
shape-- Returns:
-
set
public void set(double value)
Description copied from interface:INDArraySets all elements of an array to a specific double value- Specified by:
setin interfaceINDArray- Overrides:
setin classAbstractArray<INDArray>
-
set
public void set(int x, double value)Description copied from interface:INDArraySets a value at a given position in a mutable 1D array- Specified by:
setin interfaceINDArray- Overrides:
setin classAbstractArray<INDArray>
-
set
public void set(int x, int y, double value)Description copied from interface:INDArraySets a value at a given position in a mutable 2D array- Specified by:
setin interfaceINDArray- Overrides:
setin classAbstractArray<INDArray>
-
set
public void set(int[] indexes, double value)Description copied from interface:INDArraySets the element at the given indexed position in a mutable array
-
getTranspose
public INDArray getTranspose()
Description copied from interface:INDArrayReturns the transpose of this array. A transpose of an array is equivalent to reversing the order of dimensions. May or may not return a view depending on the array type.- Specified by:
getTransposein interfaceINDArray- Overrides:
getTransposein classAbstractArray<INDArray>
-
getTransposeView
public INDArray getTransposeView()
Description copied from interface:INDArrayReturns a transposed view of the array. May throw UnsupportedOperationException if the array type does not support this capability- Specified by:
getTransposeViewin interfaceINDArray- Overrides:
getTransposeViewin classAbstractArray<INDArray>
-
asVector
public AVector asVector()
Description copied from interface:INDArrayConstructs a view of all elements in the array as a single vector in row-major order.- Specified by:
asVectorin interfaceINDArray- Overrides:
asVectorin classAbstractArray<INDArray>
-
reshape
public INDArray reshape(int... dimensions)
Description copied from interface:INDArrayReturns a new array by rearranging the elements of this array into the desired shape Truncates or zero-pads the elements as required to fill the new shape- Specified by:
reshapein interfaceINDArray- Overrides:
reshapein classAbstractArray<INDArray>
-
broadcast
public INDArray broadcast(int... dimensions)
Description copied from interface:INDArrayReturns a view of this array broadcasted up to a larger shape- Specified by:
broadcastin interfaceINDArray- Overrides:
broadcastin classAbstractArray<INDArray>
-
slice
public INDArray slice(int majorSlice)
Description copied from interface:INDArrayReturns the specified major slice of this array as a view (slice along dimension 0) 0 dimensional slice results are permitted, but attempting to slice a 0 dimensional array will result in an error.
-
slice
public INDArray slice(int dimension, int index)
Description copied from interface:INDArrayReturns a slice view of this array along the specified dimension
-
subArray
public NDArray subArray(int[] offsets, int[] shape)
Description copied from interface:INDArrayReturns a subarray view of a larger array- Specified by:
subArrayin interfaceINDArray- Overrides:
subArrayin classAbstractArray<INDArray>
-
isMutable
public boolean isMutable()
Description copied from interface:INDArrayReturns true if the INDArray is mutable (at least partially)- Specified by:
isMutablein interfaceINDArray- Overrides:
isMutablein classAbstractArray<INDArray>
-
isFullyMutable
public boolean isFullyMutable()
Description copied from interface:INDArrayIf this method returns true, the INDArray is guaranteed to be fully mutable in all positions i.e. every position can store any valid double value- Specified by:
isFullyMutablein interfaceINDArray- Overrides:
isFullyMutablein classAbstractArray<INDArray>
-
isElementConstrained
public boolean isElementConstrained()
Description copied from interface:INDArrayReturns true if this array has some constraints on element values- Specified by:
isElementConstrainedin interfaceINDArray- Overrides:
isElementConstrainedin classAbstractArray<INDArray>
-
isView
public boolean isView()
Description copied from interface:INDArrayReturn true if this array is considered as a view type. This indicates (but does not guarantee): a) Data is *likely* to be shared with other arrays, so mutation of one may affect others b) It is *unlikely* to be in the most efficient general purpose format isView is intended to be used as for heuristics. It should *not* be used where the outcome might affect correctness.
-
applyOp
public void applyOp(Op op)
Description copied from interface:INDArrayApplies a unary operator to all elements of the array (in-place)- Specified by:
applyOpin interfaceINDArray- Overrides:
applyOpin classAbstractArray<INDArray>
-
applyOp
public void applyOp(IOperator op)
Description copied from interface:INDArrayApplies a unary operator to all elements of the array (in-place)- Specified by:
applyOpin interfaceINDArray- Overrides:
applyOpin classAbstractArray<INDArray>- Parameters:
op- The operator to apply to the array
-
equals
public boolean equals(INDArray a)
Description copied from interface:INDArrayChecks if two arrays are equal exactly in terms of both value and shape Element equality checks are consistent with compareTo- Specified by:
equalsin interfaceINDArray- Overrides:
equalsin classAbstractArray<INDArray>
-
exactClone
public NDArray exactClone()
Description copied from interface:INDArrayCreates a deep clone of an array, using the same class implementation as the original array- Returns:
- A clone of the original array
-
clone
public INDArray clone()
Description copied from interface:INDArrayReturns a clone of the array data, as a new array which will be fully mutable and may be of a different class to the original. Clone should attempt to return the most efficient possible array type. Clone should preserve sparsity property where possible, but this is not guaranteed.- Specified by:
clonein interfaceINDArray- Overrides:
clonein classAbstractArray<INDArray>
-
multiply
public void multiply(double d)
Description copied from interface:INDArrayMultiplies all elements of the array in place by a given double value- Specified by:
multiplyin interfaceINDArray- Overrides:
multiplyin classAbstractArray<INDArray>
-
setElements
public void setElements(int pos, double[] values, int offset, int length)Description copied from interface:INDArraySets elements in an array using the given double values. The source array must contain at least the specified length in terms of number of elements- Specified by:
setElementsin interfaceINDArray- Overrides:
setElementsin classAbstractArray<INDArray>- Parameters:
pos- Offset into this array, expressed in terms of number of elements in row major ordervalues- Element values in a double[] array. There must be at least as many element values as elements in this array.offset- Position in the values array from which to start taking values.length- Number of elements to set.
-
toDoubleBuffer
public void toDoubleBuffer(java.nio.DoubleBuffer dest)
Description copied from interface:INDArrayCopies the elements of this INDArray to the specified double buffer.- Specified by:
toDoubleBufferin interfaceINDArray- Overrides:
toDoubleBufferin classAbstractArray<INDArray>
-
asDoubleArray
public double[] asDoubleArray()
Description copied from interface:INDArrayReturns the underlying double array representing the densely packed elements of this array. Modifications to this double array will change the original array. Returns null if there is no such array.- Specified by:
asDoubleArrayin interfaceINDArray- Overrides:
asDoubleArrayin classAbstractArray<INDArray>
-
getSlices
public java.util.List<INDArray> getSlices()
Description copied from interface:INDArrayReturns a list of all major slices of this array. Returns a list of Double values if a 1-dimensional array is sliced, otherwise a list of INDArray instances- Specified by:
getSlicesin interfaceINDArray- Overrides:
getSlicesin classAbstractArray<INDArray>
-
elementIterator
public java.util.Iterator<java.lang.Double> elementIterator()
Description copied from interface:INDArrayReturns an iterator over all elements in this array, in row-major order- Specified by:
elementIteratorin interfaceINDArray- Overrides:
elementIteratorin classAbstractArray<INDArray>
-
validate
public void validate()
Description copied from interface:INDArrayValidates the internal data structure of the INDArray. Throws an exception on failure. Failure indicates a serious bug and/or data corruption.- Specified by:
validatein interfaceINDArray- Overrides:
validatein classAbstractArray<INDArray>
-
immutable
public INDArray immutable()
Description copied from interface:INDArrayReturns an immutable version of this array. May return the same array if already immutable. Guarantees a defensive copy if the array is mutable.- Specified by:
immutablein interfaceINDArray- Overrides:
immutablein classAbstractArray<INDArray>
-
getArray
public double[] getArray()
Description copied from interface:IStridedArrayGets the underlying data array for this strided array Unsafe operation - may allow modification of otherwise immutable arrays- Returns:
-
wrapStrided
public static INDArray wrapStrided(double[] data, int offset, int[] shape, int[] strides)
-
-
DMelt 3.0 © DataMelt by jWork.ORG