mikera.matrixx.impl
Class ImmutableMatrix
- java.lang.Object
-
- mikera.arrayz.impl.AbstractArray<AVector>
-
- mikera.matrixx.AMatrix
-
- mikera.matrixx.impl.ARectangularMatrix
-
- mikera.matrixx.impl.ImmutableMatrix
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<INDArray>, java.lang.Iterable<AVector>, IDense, IDenseArray, INDArray, IMatrix, IFastRows
public final class ImmutableMatrix extends ARectangularMatrix implements IDenseArray, IFastRows
Immutable dense matrix class This is the immutable equivalent of mikera.matrixx.Matrix- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description ImmutableMatrix(AMatrix m)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddToArray(double[] data, int offset)Adds all the elements of this array to a double array at the specified offset, in row-major orderImmutableVectorasVector()Returns the matrix values as a single reference Vector in the form [row0 row1 row2....]Matrixclone()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.voidcopyColumnTo(int col, double[] dest, int destOffset)Copies the elements in a selected row of this matrix to a double arrayvoidcopyRowTo(int row, double[] dest, int destOffset)Copies the elements in a selected row of this matrix to a double arraystatic ImmutableMatrixcreate(AMatrix a)doubleelementSquaredSum()Returns the squared sum of all elements in this matrixdoubleelementSum()Returns the sum of all elements in this matrixbooleanequals(AMatrix a)Returns true if this matrix is exactly equal to another matrixbooleanequalsArray(double[] data, int offset)Returns true if the elements in this array exactly match the elements in the given array, in row-major orderAMatrixexactClone()Creates a deep clone of an array, using the same class implementation as the original arraydoubleget(int i, int j)Returns the double value at the specified position in a 2D matrixdouble[]getArray()intgetArrayOffset()voidgetElements(double[] dest, int offset)Copies all elements of this array a double array at the specified offsetdouble[]getInternalData()Unsafe method that returns the internal data arrayImmutableVectorgetRowView(int row)Returns a row of the matrix as a vector view.MatrixinnerProduct(AMatrix a)Computes the inner product of this matrix with another.VectorinnerProduct(AVector a)Computes the inner product of this array with a vectorbooleanisBoolean()Returns true if the array is boolean (contains only 0.0 or 1.0 values)booleanisFullyMutable()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.booleanisZero()Returns true if the matrix is the zero matrix (all components zero)longnonZeroCount()Returns the number of non-zero elements in the array.voidtoDoubleBuffer(java.nio.DoubleBuffer dest)Copies the elements of this INDArray to the specified double buffer.MatrixtoMatrix()Coerces the matrix to the standard mutable Matrix type in row major order.MatrixtoMatrixTranspose()Coerces the transpose of a matrix to the standard mutable Matrix type in row major order.VectortoVector()Coerces the array into a flattened dense Vector, in row-major order.voidtransform(Vector source, Vector dest)doubleunsafeGet(int i, int j)Gets an element in the matrix in an unsafe fashion, without performing bound checks The result is undefined if the row and column are out of bounds.static ImmutableMatrixwrap(int rows, int cols, double[] data)Creates a new ImmutableMatrix wrapping the specified source array WARNING: does not take a defensive copy.static ImmutableMatrixwrap(Matrix source)Creates a new ImmutableMatrix wrapping the data array of a given Matrix WARNING: does not take a defensive copy.-
Methods inherited from class mikera.matrixx.impl.ARectangularMatrix
bandLength, checkColumn, checkRow, checkSquare, columnCount, elementCount, getElement, getShape, getShape, getShapeClone, isSameShape, isSameShape, isSameShape, isSquare, rowCount, set
-
Methods inherited from class mikera.matrixx.AMatrix
abs, add, add, add, add, add2, addAt, addCopy, addCopy, addCopy, addCopy, addCopy, addInnerProduct, addInnerProduct, addInnerProduct, addMultiple, addMultiple, addMultiple, addOuterProduct, addOuterProduct, addOuterProductSparse, addOuterProductSparse, addRowMultiple, addSparse, addSparse, applyOp, applyOp, applyOp, applyOp, applyOp, applyOp, applyOpCopy, asDoubleArray, asElementList, bandIndex, bandPosition, bandStartColumn, bandStartRow, broadcast, broadcastCloneLike, broadcastCopyLike, broadcastLike, broadcastLike, clamp, composeWith, copy, dense, denseClone, determinant, diagonalProduct, dimensionality, divide, divide, divide, divide, divideCopy, elementIterator, elementsEqual, ensureMutable, epsilonEquals, epsilonEquals, epsilonEquals, equals, equals, equalsTranspose, exp, fill, get, get, get, get, getBand, getBandWrapped, getColumn, getColumnClone, getColumns, getColumnView, getLeadingDiagonal, getLongShape, getRow, getRowClone, getRows, getSlices, getSlices, getSliceViews, getTranspose, getTransposeCopy, getTransposeView, hashCode, hasOrthonormalColumns, hasOrthonormalRows, hasUncountable, immutable, innerProduct, innerProduct, innerProduct, innerProduct, inputDimensions, inverse, isDiagonal, isElementConstrained, isHermitian, isIdentity, isInvertible, isLowerTriangular, isOrthogonal, isOrthogonal, isPositiveDefinite, isRectangularDiagonal, isSymmetric, isUpperTriangular, iterator, join, log, lowerBandwidth, lowerBandwidthLimit, mul, multiply, multiply, multiply, multiply, multiplyCopy, multiplyRow, mutable, negate, outerProduct, outputDimensions, pow, rank, reciprocal, reduce, reduce, reduceSlices, reduceSlices, reorder, reorder, replaceColumn, replaceRow, reshape, reshape, rotateView, rowDotProduct, scaleAdd, scaleAdd, set, set, set, set, set, set, set, set, setApplyOp, setApplyOp, setColumn, setElements, setElements, setMultiple, setMultiple, setMultiple, setMultiple, setMultiple, setRow, setSparse, setSparse, signum, slice, slice, sliceCount, sparse, sparseClone, sqrt, square, sub, sub, sub, subArray, subCopy, subMatrix, swapColumns, swapRows, toAffineTransform, toDoubleArray, toMutableMatrix, toNestedDoubleArrays, toSliceArray, toString, toStringFull, trace, transform, transformInPlace, transformInPlace, transposeInnerProduct, transposeInnerProduct, transposeInPlace, unsafeSet, upperBandwidth, upperBandwidthLimit, validate
-
Methods inherited from class mikera.arrayz.impl.AbstractArray
absCopy, absDiff, absDiffCopy, add, addApplyOp, addAt, addCopy, addInnerProduct, addInnerProduct, addMultipleSparse, addPower, addPower, addSparse, broadcastLike, compareTo, componentCount, density, divideCopy, elementAbsPowSum, elementMax, elementMaxAbs, elementMin, elementPowSum, elementProduct, epsilonEquals, equals, equalsArray, get, get, get, get, getComponent, getComponents, getElements, getElements, getElements, isDense, isSparse, join, multiplyCopy, negateCopy, reciprocalCopy, scale, scaleCopy, setElements, setInnerProduct, setSparse, signumCopy, sliceValue, squareCopy, sub, sub, subCopy, withComponents
-
Methods inherited from interface mikera.matrixx.IMatrix
add2, addAt, addCopy, addCopy, columnCount, diagonalProduct, getBand, getColumn, getColumnClone, getColumns, getColumnView, getRowClone, getRows, getTranspose, getTransposeView, innerProduct, inverse, isDiagonal, isIdentity, isInvertible, isRectangularDiagonal, isSquare, isSymmetric, rowCount, set, subMatrix, toNestedDoubleArrays, trace, transform, transformInPlace, transposeInPlace
-
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, applyOp, applyOp, applyOp, applyOp, applyOpCopy, asDoubleArray, asElementList, broadcast, broadcastCloneLike, broadcastCopyLike, broadcastLike, broadcastLike, broadcastLike, clamp, componentCount, copy, dense, denseClone, dimensionality, divide, divide, divideCopy, divideCopy, elementAbsPowSum, elementCount, elementIterator, elementMax, elementMaxAbs, elementMin, elementPowSum, elementProduct, elementsEqual, ensureMutable, epsilonEquals, epsilonEquals, equals, equalsArray, exp, fill, get, get, get, get, get, get, get, get, getComponent, getComponents, getElement, getElements, getElements, getElements, getLongShape, getShape, getShape, getShapeClone, getSlices, getSlices, getSliceViews, getTransposeCopy, hasUncountable, immutable, innerProduct, innerProduct, innerProduct, isDense, isElementConstrained, isSameShape, isSparse, join, join, log, multiply, multiply, multiplyCopy, multiplyCopy, mutable, negate, negateCopy, outerProduct, pow, reciprocal, reciprocalCopy, reduce, reduce, reduceSlices, reduceSlices, reorder, reorder, reshape, rotateView, scale, scaleAdd, scaleAdd, scaleCopy, set, set, set, set, set, set, setApplyOp, setElements, setElements, setElements, setInnerProduct, setMultiple, setMultiple, setSparse, setSparse, signum, signumCopy, slice, slice, sliceCount, sliceValue, sparse, sparseClone, sqrt, square, squareCopy, sub, sub, subArray, subCopy, toDoubleArray, toSliceArray, validate, withComponents
-
-
-
-
Constructor Detail
-
ImmutableMatrix
public ImmutableMatrix(AMatrix m)
-
-
Method Detail
-
wrap
public static ImmutableMatrix wrap(Matrix source)
Creates a new ImmutableMatrix wrapping the data array of a given Matrix WARNING: does not take a defensive copy. Should be used only if you can guarantee that the underlying data array will not be mutated elsewhere.
-
wrap
public static ImmutableMatrix wrap(int rows, int cols, double[] data)
Creates a new ImmutableMatrix wrapping the specified source array WARNING: does not take a defensive copy. Should be used only if you can guarantee that the data array will not be mutated elsewhere.
-
isMutable
public boolean isMutable()
Description copied from interface:INDArrayReturns true if the INDArray is mutable (at least partially)
-
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- Specified by:
isFullyMutablein classAMatrix
-
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.
-
nonZeroCount
public long nonZeroCount()
Description copied from interface:INDArrayReturns the number of non-zero elements in the array.- Specified by:
nonZeroCountin interfaceINDArray- Overrides:
nonZeroCountin classAMatrix
-
isBoolean
public boolean isBoolean()
Description copied from interface:INDArrayReturns true if the array is boolean (contains only 0.0 or 1.0 values)
-
isZero
public boolean isZero()
Description copied from class:AMatrixReturns true if the matrix is the zero matrix (all components zero)
-
get
public double get(int i, int j)Description copied from interface:INDArrayReturns the double value at the specified position in a 2D matrix
-
getRowView
public ImmutableVector getRowView(int row)
Description copied from interface:IMatrixReturns a row of the matrix as a vector view. May be used to modify the original matrix.- Specified by:
getRowViewin interfaceIMatrix- Overrides:
getRowViewin classAMatrix
-
unsafeGet
public double unsafeGet(int i, int j)Description copied from class:AMatrixGets an element in the matrix in an unsafe fashion, without performing bound checks The result is undefined if the row and column are out of bounds.
-
copyRowTo
public final void copyRowTo(int row, double[] dest, int destOffset)Description copied from class:AMatrixCopies the elements in a selected row of this matrix to a double array
-
innerProduct
public Vector innerProduct(AVector a)
Description copied from interface:INDArrayComputes the inner product of this array with a vector- Specified by:
innerProductin interfaceINDArray- Specified by:
innerProductin interfaceIMatrix- Overrides:
innerProductin classAMatrix- Parameters:
a- A vector- Returns:
- A new array representing the inner product
-
innerProduct
public Matrix innerProduct(AMatrix a)
Description copied from interface:IMatrixComputes the inner product of this matrix with another. Equivalent to matrix x matrix multiplication- Specified by:
innerProductin interfaceIMatrix- Overrides:
innerProductin classAMatrix- Returns:
-
copyColumnTo
public final void copyColumnTo(int col, double[] dest, int destOffset)Description copied from class:AMatrixCopies the elements in a selected row of this matrix to a double array- Overrides:
copyColumnToin classAMatrixdest- Destination double[] array
-
elementSum
public double elementSum()
Description copied from class:AMatrixReturns the sum of all elements in this matrix- Specified by:
elementSumin interfaceINDArray- Overrides:
elementSumin classAMatrix
-
elementSquaredSum
public double elementSquaredSum()
Description copied from class:AMatrixReturns the squared sum of all elements in this matrix- Specified by:
elementSquaredSumin interfaceINDArray- Overrides:
elementSquaredSumin classAMatrix
-
toVector
public Vector toVector()
Description copied from interface:INDArrayCoerces the array into a flattened dense Vector, in row-major order. May return the same array if it is already a Vector instance.
-
asVector
public ImmutableVector asVector()
Description copied from class:AMatrixReturns the matrix values as a single reference Vector in the form [row0 row1 row2....]
-
toMatrix
public Matrix toMatrix()
Description copied from class:AMatrixCoerces the matrix to the standard mutable Matrix type in row major order. Performs a copy if necessary.
-
toMatrixTranspose
public Matrix toMatrixTranspose()
Description copied from class:AMatrixCoerces the transpose of a matrix to the standard mutable Matrix type in row major order. Performs a copy if necessary.- Overrides:
toMatrixTransposein classAMatrix
-
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 classAMatrix
-
getElements
public void getElements(double[] dest, int offset)Description copied from interface:INDArrayCopies all elements of this array a double array at the specified offset- Specified by:
getElementsin interfaceINDArray- Overrides:
getElementsin classAMatrix
-
addToArray
public void addToArray(double[] data, int offset)Description copied from interface:INDArrayAdds all the elements of this array to a double array at the specified offset, in row-major order- Specified by:
addToArrayin interfaceINDArray- Overrides:
addToArrayin classAMatrix
-
clone
public Matrix 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.
-
exactClone
public AMatrix exactClone()
Description copied from interface:INDArrayCreates a deep clone of an array, using the same class implementation as the original array- Specified by:
exactClonein interfaceINDArray- Specified by:
exactClonein classAMatrix- Returns:
- A clone of the original array
-
equals
public boolean equals(AMatrix a)
Description copied from class:AMatrixReturns true if this matrix is exactly equal to another matrix
-
equalsArray
public boolean equalsArray(double[] data, int offset)Description copied from interface:INDArrayReturns true if the elements in this array exactly match the elements in the given array, in row-major order- Specified by:
equalsArrayin interfaceINDArray- Overrides:
equalsArrayin classAMatrix- Parameters:
data- Array of double element values to check for equalityoffset- Offset into the data array- Returns:
-
getInternalData
public double[] getInternalData()
Unsafe method that returns the internal data array- Returns:
-
create
public static ImmutableMatrix create(AMatrix a)
-
getArray
public double[] getArray()
- Specified by:
getArrayin interfaceIDenseArray
-
getArrayOffset
public int getArrayOffset()
- Specified by:
getArrayOffsetin interfaceIDenseArray
-
-
DMelt 3.0 © DataMelt by jWork.ORG