mikera.matrixx
Class Matrix
- java.lang.Object
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<INDArray>, java.lang.Iterable<AVector>, IDense, IDenseArray, IStridedArray, INDArray, IMatrix, IFastRows
public final class Matrix extends ADenseArrayMatrix
Standard MxN matrix class backed by a densely packed double[] array This is the most efficient Vectorz type for dense 2D matrices.- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class mikera.matrixx.impl.AArrayMatrix
data
-
-
Constructor Summary
Constructors Constructor and Description Matrix(AMatrix m)Creates a new Matrix with a copy of all data from the source matrixMatrix(int rowCount, int columnCount)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidabs()Replaces all elements of this array with their absolute values, according to Math.abs(double)voidadd(AMatrix m)Adds another matrix to this matrix.voidadd(double d)Adds a double value to all elements in this array.static voidadd(Matrix dest, Matrix a, Matrix b)voidadd2(AMatrix a, AMatrix b)Adds two matrices to this matrix.voidadd2(Matrix a, Matrix b)voidaddAt(int i, int j, double d)Adds a value at a specific position in the matrix, mutating the matrix Does not perform bounds checking - this in an unsafe operationvoidaddMultiple(ADenseArrayMatrix m, double factor)voidaddMultiple(AMatrix m, double factor)Adds a scalar multiple of another matrix to this matrixvoidaddRowMultiple(int src, int dst, double factor)Adds a multiple of a source row to a destination row This is an elementary row operationvoidapplyOp(Op op)Applies a unary operator to all elements of the array (in-place)voidapplyOp(Op2 op, double b)Applies a binary operator to this array and a double value.double[]asDoubleArray()Returns the underlying double array representing the densely packed elements of this array.VectorasVector()Returns the matrix values as a single reference Vector in the form [row0 row1 row2....]voidclamp(double min, double max)Clamps all the elements of this array within the specified [min,max] rangeMatrixcopy()Returns a defensive copy of the array data.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 Matrixcreate(AMatrix m)Creates a new mutable dense matrix containing a copy of another matroixstatic Matrixcreate(AVector... data)Creates a new Matrix using the given vectors as row datastatic Matrixcreate(double[][] data)static Matrixcreate(INDArray m)static Matrixcreate(int... shape)Creates a new zero-filled matrix of the specified shape.static Matrixcreate(int rowCount, int columnCount)Creates a new zero-filled matrix of the specified shape.static MatrixcreateFromRows(java.lang.Object... rows)static MatrixcreateIdentity(int dims)Creates a square mutable dense identity Matrix of the specified size.
aij = 0 if i ≠ j
aij = 1 if i = jstatic MatrixcreateIdentity(int numRows, int numCols)Creates a Matrix which contains ones along the main diagonal and zeros everywhere else.static MatrixcreateRandom(int rows, int cols)java.util.Iterator<java.lang.Double>elementIterator()Returns an iterator over all elements in this array, in row-major orderdoubleelementMax()Returns the maximum element value in this array.doubleelementMin()Returns the maximum element value in this array.doubleelementSquaredSum()Returns the squared sum of all elements in this matrixdoubleelementSum()Returns the sum of all elements in this matrixMatrixexactClone()Creates a deep clone of an array, using the same class implementation as the original arrayvoidexp()Computes the function e^x (in-place) for all array elementsvoidfill(double value)Fills this array with a single double value.doubleget(int i, int j)Returns the double value at the specified position in a 2D matrixintgetArrayOffset()Gets the data array offset for the first element of this strided arrayStridedVectorgetBand(int band)Gets a specific band of the matrix, as a view vector.AStridedVectorgetColumn(int col)Returns a column of the matrix.voidgetElements(double[] dest, int offset)Copies all elements of this array a double array at the specified offsetArraySubVectorgetRow(int row)Returns a row of the matrix.ArraySubVectorgetRowView(int row)Returns a row of the matrix as a vector view.DenseColumnMatrixgetTranspose()Returns the transpose of this array.DenseColumnMatrixgetTransposeView()Returns a transposed view of the array.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.booleanisPackedArray()Returns true if the data array is fully packed by this matrix in row-major orderbooleanisView()Return true if this array is considered as a view type.booleanisZero()Returns true if the matrix is the zero matrix (all components zero)voidlog()Computes the natural logarithm (in-place) for all array elementsvoidmultiply(double factor)Multiplies all elements of the array in place by a given double valuevoidmultiplyRow(int i, double factor)Multiplies a row by a constant factor This is an elementary row operationlongnonZeroCount()Returns the number of non-zero elements in the array.voidreciprocal()Replaces all elements in the array with their reciprocalstatic voidscale(Matrix dest, Matrix src, double factor)static voidscaleAdd(Matrix dest, Matrix a, Matrix b, double bFactor)voidset(AMatrix a)Sets this matrix with the element values from another matrix.voidset(AVector a)Sets every row of this matrix with the element values from a vector.voidset(int i, int j, double value)Sets a value at a given position in a mutable 2D arrayvoidsetColumn(int j, AVector col)Sets a column in a matrix.voidsetMultiple(Matrix m, double factor)voidsetRow(int i, AVector row)Sets a row in a matrix to the value specified by the given vectorvoidsignum()Calculates the signum of all elements of this mutable array Sets each component of the array to its sign value (-1, 0 or 1)voidsquare()Squares all elements of the array in placeAStridedMatrixsubMatrix(int rowStart, int rows, int colStart, int cols)Gets a rectangular submatrix view of part of a matrixvoidswapColumns(int i, int j)Swaps two columns of the matrix in placevoidswapRows(int i, int j)Swaps two rows of the matrix in place This is an elementary row operationdouble[]toDoubleArray()Copies the elements of this array to a new double[] 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(AVector source, AVector dest)Transforms a source vector into a destination vector, using matrix multiplication (inner product).voidtransform(Vector source, Vector dest)MatrixtransposeInnerProduct(Matrix s)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.voidunsafeSet(int i, int j, double value)Sets an element value 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 Matrixwrap(int rowCount, int columnCount, double[] data)Wraps a double[] array as a dense Matrix.-
Methods inherited from class mikera.matrixx.impl.ADenseArrayMatrix
add, add, addOuterProduct, addToArray, columnStride, equals, equals, equalsArray, isLowerTriangular, isUpperTriangular, reduce, rowDotProduct, rowStride, setElements, setElements
-
Methods inherited from class mikera.matrixx.impl.AStridedMatrix
applyOpCopy, clone, diagonalProduct, getColumnView, getStride, getStrides, trace
-
Methods inherited from class mikera.matrixx.impl.AArrayMatrix
getArray, getTransposeCopy
-
Methods inherited from class mikera.matrixx.impl.ARectangularMatrix
bandLength, checkColumn, checkRow, checkSquare, columnCount, elementCount, getElement, getShape, getShape, getShapeClone, isSameShape, isSameShape, isSameShape, isSquare, rowCount
-
Methods inherited from class mikera.matrixx.AMatrix
add, addCopy, addCopy, addCopy, addCopy, addCopy, addInnerProduct, addInnerProduct, addInnerProduct, addMultiple, addMultiple, addOuterProduct, addOuterProductSparse, addOuterProductSparse, addSparse, addSparse, applyOp, applyOp, applyOp, applyOp, asElementList, bandIndex, bandPosition, bandStartColumn, bandStartRow, broadcast, broadcastCloneLike, broadcastCopyLike, broadcastLike, broadcastLike, composeWith, dense, denseClone, determinant, dimensionality, divide, divide, divide, divide, divideCopy, elementsEqual, ensureMutable, epsilonEquals, epsilonEquals, epsilonEquals, equals, equalsTranspose, get, get, get, get, getBandWrapped, getColumnClone, getColumns, getLeadingDiagonal, getLongShape, getRowClone, getRows, getSlices, getSlices, getSliceViews, hashCode, hasOrthonormalColumns, hasOrthonormalRows, hasUncountable, immutable, innerProduct, innerProduct, innerProduct, innerProduct, inputDimensions, inverse, isDiagonal, isElementConstrained, isHermitian, isIdentity, isInvertible, isMutable, isOrthogonal, isOrthogonal, isPositiveDefinite, isRectangularDiagonal, isSymmetric, iterator, join, lowerBandwidth, lowerBandwidthLimit, mul, multiply, multiply, multiply, multiplyCopy, mutable, negate, outerProduct, outputDimensions, pow, rank, reduce, reduceSlices, reduceSlices, reorder, reorder, replaceColumn, replaceRow, reshape, reshape, rotateView, scaleAdd, scaleAdd, set, set, set, set, set, set, setApplyOp, setApplyOp, setElements, setMultiple, setMultiple, setMultiple, setMultiple, setMultiple, setSparse, setSparse, slice, slice, sliceCount, sparse, sparseClone, sqrt, sub, sub, sub, subArray, subCopy, toAffineTransform, toMutableMatrix, toNestedDoubleArrays, toSliceArray, toString, toStringFull, transformInPlace, transformInPlace, transposeInnerProduct, transposeInPlace, 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, elementMaxAbs, elementPowSum, elementProduct, epsilonEquals, equals, equalsArray, get, get, get, get, getComponent, getComponents, getElements, getElements, getElements, isDense, isSparse, join, multiplyCopy, negateCopy, reciprocalCopy, scale, scaleCopy, setInnerProduct, setSparse, signumCopy, sliceValue, squareCopy, sub, sub, subCopy, withComponents
-
Methods inherited from interface mikera.matrixx.IMatrix
addCopy, addCopy, columnCount, diagonalProduct, getColumnClone, getColumns, getColumnView, getRowClone, getRows, innerProduct, inverse, isDiagonal, isIdentity, isInvertible, isRectangularDiagonal, isSquare, isSymmetric, rowCount, toNestedDoubleArrays, trace, transformInPlace, transposeInPlace
-
Methods inherited from interface mikera.arrayz.INDArray
absCopy, absDiff, absDiffCopy, add, addApplyOp, addAt, addCopy, addCopy, addInnerProduct, addInnerProduct, addMultiple, addMultipleSparse, addOuterProduct, addOuterProductSparse, addPower, addPower, addSparse, addSparse, applyOp, applyOp, applyOpCopy, asElementList, broadcast, broadcastCloneLike, broadcastCopyLike, broadcastLike, broadcastLike, broadcastLike, clone, componentCount, dense, denseClone, dimensionality, divide, divide, divideCopy, divideCopy, elementAbsPowSum, elementCount, elementMaxAbs, elementPowSum, elementProduct, elementsEqual, ensureMutable, epsilonEquals, epsilonEquals, equalsArray, 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, isMutable, isSameShape, isSparse, join, join, multiply, multiplyCopy, multiplyCopy, mutable, negate, negateCopy, outerProduct, pow, reciprocalCopy, reduce, reduceSlices, reduceSlices, reorder, reorder, reshape, rotateView, scale, scaleAdd, scaleAdd, scaleCopy, set, set, set, set, set, set, setApplyOp, setElements, setInnerProduct, setMultiple, setMultiple, setSparse, setSparse, signumCopy, slice, slice, sliceCount, sliceValue, sparse, sparseClone, sqrt, squareCopy, sub, sub, subArray, subCopy, toSliceArray, validate, withComponents
-
Methods inherited from interface mikera.arrayz.impl.IDenseArray
getArray
-
Methods inherited from interface mikera.arrayz.impl.IStridedArray
getArray
-
-
-
-
Constructor Detail
-
Matrix
public Matrix(AMatrix m)
Creates a new Matrix with a copy of all data from the source matrix- Parameters:
m-
-
Matrix
public Matrix(int rowCount, int columnCount)
-
-
Method Detail
-
create
public static Matrix create(int rowCount, int columnCount)
Creates a new zero-filled matrix of the specified shape.
-
create
public static Matrix create(int... shape)
Creates a new zero-filled matrix of the specified shape.
-
create
public static Matrix create(AMatrix m)
Creates a new mutable dense matrix containing a copy of another matroix
-
createRandom
public static Matrix createRandom(int rows, int cols)
-
createFromRows
public static Matrix createFromRows(java.lang.Object... rows)
-
create
public static Matrix create(double[][] data)
-
create
public static Matrix create(AVector... data)
Creates a new Matrix using the given vectors as row data- Parameters:
data-- Returns:
-
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.
-
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)- Specified by:
isZeroin interfaceINDArray- Overrides:
isZeroin classADenseArrayMatrix
-
isPackedArray
public boolean isPackedArray()
Description copied from class:AArrayMatrixReturns true if the data array is fully packed by this matrix in row-major order- Specified by:
isPackedArrayin interfaceIStridedArray- Overrides:
isPackedArrayin classADenseArrayMatrix- Returns:
-
wrap
public static Matrix wrap(int rowCount, int columnCount, double[] data)
Wraps a double[] array as a dense Matrix. Double array must contain exactly the right number of elements, if not consider Matrixx.wrapStrided(..) *- Parameters:
rowCount-columnCount-data-- Returns:
-
subMatrix
public AStridedMatrix subMatrix(int rowStart, int rows, int colStart, int cols)
Description copied from interface:IMatrixGets a rectangular submatrix view of part of a matrix- Specified by:
subMatrixin interfaceIMatrix- Overrides:
subMatrixin classAStridedMatrix
-
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:
-
transposeInnerProduct
public Matrix transposeInnerProduct(Matrix s)
- Overrides:
transposeInnerProductin classAMatrix
-
elementSum
public double elementSum()
Description copied from class:AMatrixReturns the sum of all elements in this matrix- Specified by:
elementSumin interfaceINDArray- Overrides:
elementSumin classADenseArrayMatrix
-
elementSquaredSum
public double elementSquaredSum()
Description copied from class:AMatrixReturns the squared sum of all elements in this matrix- Specified by:
elementSquaredSumin interfaceINDArray- Overrides:
elementSquaredSumin classADenseArrayMatrix
-
elementMax
public double elementMax()
Description copied from interface:INDArrayReturns the maximum element value in this array. Throws an error if there are no elements.- Specified by:
elementMaxin interfaceINDArray- Overrides:
elementMaxin classADenseArrayMatrix
-
elementMin
public double elementMin()
Description copied from interface:INDArrayReturns the maximum element value in this array. Throws an error if there are no elements.- Specified by:
elementMinin interfaceINDArray- Overrides:
elementMinin classADenseArrayMatrix
-
abs
public void abs()
Description copied from interface:INDArrayReplaces all elements of this array with their absolute values, according to Math.abs(double)
-
signum
public void signum()
Description copied from interface:INDArrayCalculates the signum of all elements of this mutable array Sets each component of the array to its sign value (-1, 0 or 1)
-
square
public void square()
Description copied from interface:INDArraySquares all elements of the array in place
-
exp
public void exp()
Description copied from interface:INDArrayComputes the function e^x (in-place) for all array elements
-
log
public void log()
Description copied from interface:INDArrayComputes the natural logarithm (in-place) for all array elements
-
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
-
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- Overrides:
copyRowToin classADenseArrayMatrix- Parameters:
row- The index of the selected rowdest- Destination double[] arraydestOffset- Offset into destination array
-
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- Specified by:
copyColumnToin classAStridedMatrixdest- Destination double[] array
-
transform
public void transform(AVector source, AVector dest)
Description copied from interface:IMatrixTransforms a source vector into a destination vector, using matrix multiplication (inner product). The destination vector is overwritten.- Specified by:
transformin interfaceIMatrix- Overrides:
transformin classADenseArrayMatrix
-
getRow
public ArraySubVector getRow(int row)
Description copied from interface:IMatrixReturns a row of the matrix. May or may not be a view, depending on matrix type. Intended for the fastest possible read access of the row. This often means a view, but might not be (e.g. getRow on a Matrix33 returns a Vector3).
-
getRowView
public ArraySubVector 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 classAStridedMatrix
-
getColumn
public AStridedVector getColumn(int col)
Description copied from interface:IMatrixReturns a column of the matrix. May or may not be a view, depending on matrix type. Intended for the fastest possible read access of the column. This often means a view, but might not be (e.g. getColumn on a Matrix33 returns a Vector3).- Specified by:
getColumnin interfaceIMatrix- Overrides:
getColumnin classADenseArrayMatrix
-
swapRows
public void swapRows(int i, int j)Description copied from class:AMatrixSwaps two rows of the matrix in place This is an elementary row operation
-
swapColumns
public void swapColumns(int i, int j)Description copied from class:AMatrixSwaps two columns of the matrix in place- Overrides:
swapColumnsin classAMatrix
-
multiplyRow
public void multiplyRow(int i, double factor)Description copied from class:AMatrixMultiplies a row by a constant factor This is an elementary row operation- Overrides:
multiplyRowin classAMatrix
-
addRowMultiple
public void addRowMultiple(int src, int dst, double factor)Description copied from class:AMatrixAdds a multiple of a source row to a destination row This is an elementary row operation- Overrides:
addRowMultiplein classAMatrix
-
asVector
public Vector asVector()
Description copied from class:AMatrixReturns the matrix values as a single reference Vector in the form [row0 row1 row2....]- Specified by:
asVectorin interfaceINDArray- Overrides:
asVectorin classADenseArrayMatrix
-
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.
-
toMatrix
public final Matrix toMatrix()
Description copied from class:AMatrixCoerces the matrix to the standard mutable Matrix type in row major order. Performs a copy if necessary.
-
toDoubleArray
public final double[] toDoubleArray()
Description copied from interface:INDArrayCopies the elements of this array to a new double[] array.- Specified by:
toDoubleArrayin interfaceINDArray- Overrides:
toDoubleArrayin classAMatrix
-
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
-
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 classAStridedMatrix
-
get
public double get(int i, int j)Description copied from interface:INDArrayReturns the double value at the specified position in a 2D matrix
-
unsafeSet
public void unsafeSet(int i, int j, double value)Description copied from class:AMatrixSets an element value in the matrix in an unsafe fashion, without performing bound checks The result is undefined if the row and column are out of bounds.- Overrides:
unsafeSetin classADenseArrayMatrix
-
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.- Overrides:
unsafeGetin classADenseArrayMatrix- Returns:
-
addAt
public void addAt(int i, int j, double d)Description copied from interface:IMatrixAdds a value at a specific position in the matrix, mutating the matrix Does not perform bounds checking - this in an unsafe operation
-
set
public void set(int i, int j, double value)Description copied from interface:INDArraySets a value at a given position in a mutable 2D array
-
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 classAStridedMatrix
-
applyOp
public void applyOp(Op2 op, double b)
Description copied from interface:INDArrayApplies a binary operator to this array and a double value. Works as if the double value was broadcast to the shape of this array.
-
addMultiple
public void addMultiple(ADenseArrayMatrix m, double factor)
-
setMultiple
public void setMultiple(Matrix m, double factor)
-
add
public void add(AMatrix m)
Description copied from class:AMatrixAdds another matrix to this matrix. Matrices must be the same size.- Overrides:
addin classADenseArrayMatrix
-
add2
public void add2(AMatrix a, AMatrix b)
Description copied from interface:IMatrixAdds two matrices to this matrix. May be better optimised than adding both matrices individually.
-
addMultiple
public void addMultiple(AMatrix m, double factor)
Description copied from class:AMatrixAdds a scalar multiple of another matrix to this matrix- Overrides:
addMultiplein classAMatrix
-
add
public void add(double d)
Description copied from interface:INDArrayAdds a double value to all elements in this array. Implementations may optimize the case of 0.0
-
multiply
public void multiply(double factor)
Description copied from interface:INDArrayMultiplies all elements of the array in place by a given double value
-
set
public void set(AMatrix a)
Description copied from class:AMatrixSets this matrix with the element values from another matrix. Source matrix must have the same shape.- Overrides:
setin classADenseArrayMatrix
-
set
public void set(AVector a)
Description copied from class:AMatrixSets every row of this matrix with the element values from a vector.- Overrides:
setin classADenseArrayMatrix
-
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
-
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 classAStridedMatrix
-
getTranspose
public DenseColumnMatrix 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- Specified by:
getTransposein interfaceIMatrix- Overrides:
getTransposein classAStridedMatrix- Returns:
- the transpose of this matrix
-
getTransposeView
public DenseColumnMatrix 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- Specified by:
getTransposeViewin interfaceIMatrix- Overrides:
getTransposeViewin classAStridedMatrix- Returns:
- the transpose of this matrix, as a view
-
fill
public void fill(double value)
Description copied from interface:INDArrayFills this array with a single double value. Requires the array to be mutable.
-
reciprocal
public void reciprocal()
Description copied from interface:INDArrayReplaces all elements in the array with their reciprocal- Specified by:
reciprocalin interfaceINDArray- Overrides:
reciprocalin classAMatrix
-
clamp
public void clamp(double min, double max)Description copied from interface:INDArrayClamps all the elements of this array within the specified [min,max] range
-
copy
public Matrix copy()
Description copied from interface:INDArrayReturns a defensive copy of the array data. Use this if the original array might change and you need a defensive copy. May return the same array if the original was immutable, otherwise will return a defensive copy.
-
exactClone
public Matrix 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
-
setRow
public void setRow(int i, AVector row)Description copied from class:AMatrixSets a row in a matrix to the value specified by the given vector- Overrides:
setRowin classADenseArrayMatrix
-
setColumn
public void setColumn(int j, AVector col)Description copied from class:AMatrixSets a column in a matrix.
-
getBand
public StridedVector getBand(int band)
Description copied from class:AMatrixGets a specific band of the matrix, as a view vector. The band is truncated at the edges of the matrix, i.e. it does not wrap around the matrix.- Specified by:
getBandin interfaceIMatrix- Overrides:
getBandin classAStridedMatrix- Returns:
-
getArrayOffset
public int getArrayOffset()
Description copied from interface:IStridedArrayGets the data array offset for the first element of this strided array- Specified by:
getArrayOffsetin interfaceIDenseArray- Specified by:
getArrayOffsetin interfaceIStridedArray- Specified by:
getArrayOffsetin classADenseArrayMatrix- Returns:
-
createIdentity
public static Matrix createIdentity(int numRows, int numCols)
Creates a Matrix which contains ones along the main diagonal and zeros everywhere else. If square, is equal to the identity matrix.- Parameters:
numRows- Number of rows in the matrix.numCols- Number of columns in the matrix.- Returns:
- A matrix with diagonal elements equal to one.
-
createIdentity
public static Matrix createIdentity(int dims)
Creates a square mutable dense identity Matrix of the specified size.
aij = 0 if i ≠ j
aij = 1 if i = j
- Returns:
- A new instance of an identity matrix.
-
-
DMelt 3.0 © DataMelt by jWork.ORG