mikera.matrixx.impl
Class SparseRowMatrix
- java.lang.Object
-
- mikera.arrayz.impl.AbstractArray<AVector>
-
- mikera.matrixx.AMatrix
-
- mikera.matrixx.impl.ARectangularMatrix
-
- mikera.matrixx.impl.ASparseRCMatrix
-
- mikera.matrixx.impl.SparseRowMatrix
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<INDArray>, java.lang.Iterable<AVector>, INDArray, ISparse, IMatrix, IFastRows
public class SparseRowMatrix extends ASparseRCMatrix implements ISparse, IFastRows
Matrix stored as a collection of normally sparse row vectors. This format is especially efficient for: - innerProduct() with another matrix, especially one with efficient column access like SparseColumnMatrix - access via getRow() operation - transpose into SparseColumnMatrix- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidadd(AMatrix a)Adds another matrix to this matrix.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 operationvoidaddToArray(double[] targetData, int offset)Adds all the elements of this array to a double array at the specified offset, in row-major orderAMatrixclone()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.intcomponentCount()Returns the number of components of this array.voidcopyColumnTo(int col, double[] targetData, int offset)Copies the elements in a selected row of this matrix to a double arrayvoidcopyRowTo(int i, double[] data, int offset)Copies the elements in a selected row of this matrix to a double arraystatic SparseRowMatrixcreate(AMatrix source)static INDArraycreate(java.util.ArrayList<INDArray> slices, int rows, int cols)static SparseRowMatrixcreate(AVector... vecs)static SparseRowMatrixcreate(AVector[] data, int rows, int cols)static SparseRowMatrixcreate(int rows, int cols)static SparseRowMatrixcreate(java.util.List<AVector> rows)booleanequals(AMatrix m)Returns true if this matrix is exactly equal to another matrixbooleanequals(IFastRows m)Compares this matrix to another matrix implementing IFastColumns This can be much faster than the default equalsSparseRowMatrixexactClone()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 matrixjava.util.List<AVector>getColumns()Gets a List of columns of a matrix.AVectorgetComponent(int k)Gets a component from the array at the specified index Will throw an error if components are not supported, or if the component is out of bounds as defined by 0 <= kAVectorgetRow(int i)Returns a row of the matrix.java.util.List<AVector>getRows()Gets a List of rows of a matrix.AVectorgetRowView(int i)Returns a row of the matrix as a vector view.SparseColumnMatrixgetTransposeView()Returns a transposed view of the array.AMatrixinnerProduct(AMatrix a)Computes the inner product of this matrix with another.AVectorinnerProduct(AVector a)Computes the inner product of this array with a vectorSparseRowMatrixinnerProduct(SparseColumnMatrix a)Specialised inner product for sparse row matrix multiplied by sparse column matrix.SparseRowMatrixinnerProduct(SparseRowMatrix a)booleanisUpperTriangular()Returns true if a matrix is upper triangular An upper triangular matrix is defined as having all elements equal to 0.0 where i > jAMatrixmultiplyCopy(double a)Returns a copy of the array with all elements multiplied by a single constant valuevoidmultiplyRow(int i, double value)Multiplies a row by a constant factor This is an elementary row operationvoidreplaceRow(int i, AVector vec)Replaces a row in a matrix, adding the row to the internal structure of the matrix.doublerowDotProduct(int i, AVector a)Returns the dot product of a specific row with a vector.voidset(AMatrix a)Sets this matrix with the element values from another matrix.voidset(int i, int j, double value)Sets a value at a given position in a mutable 2D arrayvoidsetRow(int i, AVector v)Sets a row in a matrix to the value specified by the given vectorAMatrixsparse()Coerces this INDArray to a sparse format, without changing its element values.voidswapRows(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.SparseColumnMatrixtoSparseColumnMatrix()doubleunsafeGet(int row, int column)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.voidvalidate()Validates the internal data structure of the INDArray.static SparseRowMatrixwrap(AVector... vecs)static SparseRowMatrixwrap(AVector[] vecs, int rows, int cols)static SparseRowMatrixwrap(java.util.List<AVector> vecs)-
Methods inherited from class mikera.matrixx.impl.ASparseRCMatrix
abs, applyOp, dense, elementMax, elementMin, elementSquaredSum, elementSum, exp, fill, getColumnClone, getRowClone, isFullyMutable, isMutable, isSparse, isZero, log, nonZeroCount, pow, reciprocal, setSparse, sqrt, square, unsafeGetVector
-
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, add, add, add2, addCopy, addCopy, addCopy, addCopy, addCopy, addInnerProduct, addInnerProduct, addInnerProduct, addMultiple, addMultiple, addMultiple, addOuterProduct, addOuterProduct, addOuterProductSparse, addOuterProductSparse, addRowMultiple, addSparse, addSparse, applyOp, applyOp, applyOp, applyOp, applyOp, applyOpCopy, asDoubleArray, asElementList, asVector, bandIndex, bandPosition, bandStartColumn, bandStartRow, broadcast, broadcastCloneLike, broadcastCopyLike, broadcastLike, broadcastLike, clamp, composeWith, copy, denseClone, determinant, diagonalProduct, dimensionality, divide, divide, divide, divide, divideCopy, elementIterator, elementsEqual, ensureMutable, epsilonEquals, epsilonEquals, epsilonEquals, equals, equals, equalsArray, equalsTranspose, get, get, get, get, getBand, getBandWrapped, getColumn, getColumnView, getElements, getLeadingDiagonal, getLongShape, getSlices, getSlices, getSliceViews, getTranspose, getTransposeCopy, hashCode, hasOrthonormalColumns, hasOrthonormalRows, hasUncountable, immutable, innerProduct, innerProduct, innerProduct, innerProduct, inputDimensions, inverse, isBoolean, isDiagonal, isElementConstrained, isHermitian, isIdentity, isInvertible, isLowerTriangular, isOrthogonal, isOrthogonal, isPositiveDefinite, isRectangularDiagonal, isSymmetric, isView, iterator, join, lowerBandwidth, lowerBandwidthLimit, mul, multiply, multiply, multiply, multiply, mutable, negate, outerProduct, outputDimensions, rank, reduce, reduce, reduceSlices, reduceSlices, reorder, reorder, replaceColumn, reshape, reshape, rotateView, scaleAdd, scaleAdd, set, set, set, set, set, set, set, setApplyOp, setApplyOp, setColumn, setElements, setElements, setMultiple, setMultiple, setMultiple, setMultiple, setMultiple, setSparse, setSparse, signum, slice, slice, sliceCount, sparseClone, sub, sub, sub, subArray, subCopy, subMatrix, swapColumns, toAffineTransform, toDoubleBuffer, toMatrix, toMatrixTranspose, toMutableMatrix, toNestedDoubleArrays, toSliceArray, toString, toStringFull, toVector, trace, transform, transform, transformInPlace, transformInPlace, transposeInnerProduct, transposeInnerProduct, transposeInPlace, upperBandwidth, upperBandwidthLimit
-
Methods inherited from class mikera.arrayz.impl.AbstractArray
absCopy, absDiff, absDiffCopy, add, addApplyOp, addAt, addCopy, addInnerProduct, addInnerProduct, addMultipleSparse, addPower, addPower, addSparse, broadcastLike, compareTo, density, divideCopy, elementAbsPowSum, elementMaxAbs, elementPowSum, elementProduct, epsilonEquals, equals, equalsArray, get, get, get, get, getComponents, getElements, getElements, getElements, isDense, join, multiplyCopy, negateCopy, reciprocalCopy, scale, scaleCopy, setElements, setInnerProduct, signumCopy, sliceValue, squareCopy, sub, sub, subCopy, withComponents
-
Methods inherited from interface mikera.matrixx.IMatrix
add2, addCopy, addCopy, columnCount, diagonalProduct, getBand, getColumn, getColumnClone, getColumnView, getRowClone, getTranspose, innerProduct, inverse, isDiagonal, isIdentity, isInvertible, isRectangularDiagonal, isSquare, isSymmetric, rowCount, 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, asVector, broadcast, broadcastCloneLike, broadcastCopyLike, broadcastLike, broadcastLike, broadcastLike, clamp, copy, dense, denseClone, dimensionality, divide, divide, divideCopy, divideCopy, elementAbsPowSum, elementCount, elementIterator, elementMax, elementMaxAbs, elementMin, elementPowSum, elementProduct, elementsEqual, elementSquaredSum, elementSum, ensureMutable, epsilonEquals, epsilonEquals, equals, equalsArray, equalsArray, exp, fill, get, get, get, get, get, get, get, get, getComponents, getElement, getElements, getElements, getElements, getElements, getLongShape, getShape, getShape, getShapeClone, getSlices, getSlices, getSliceViews, getTransposeCopy, hasUncountable, immutable, innerProduct, innerProduct, innerProduct, isBoolean, isDense, isElementConstrained, isFullyMutable, isMutable, isSameShape, isSparse, isView, isZero, join, join, log, multiply, multiply, multiplyCopy, mutable, negate, negateCopy, nonZeroCount, 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, sparseClone, sqrt, square, squareCopy, sub, sub, subArray, subCopy, toDoubleBuffer, toSliceArray, toVector, withComponents
-
-
-
-
Method Detail
-
create
public static SparseRowMatrix create(int rows, int cols)
-
create
public static SparseRowMatrix create(AVector[] data, int rows, int cols)
-
create
public static SparseRowMatrix create(AVector... vecs)
-
create
public static SparseRowMatrix create(java.util.List<AVector> rows)
-
wrap
public static SparseRowMatrix wrap(AVector[] vecs, int rows, int cols)
-
wrap
public static SparseRowMatrix wrap(AVector... vecs)
-
create
public static SparseRowMatrix create(AMatrix source)
-
wrap
public static SparseRowMatrix wrap(java.util.List<AVector> vecs)
-
componentCount
public int componentCount()
Description copied from interface:INDArrayReturns the number of components of this array. May return 0 if components are not supported- Specified by:
componentCountin interfaceINDArray- Specified by:
componentCountin classASparseRCMatrix- Returns:
-
getComponent
public AVector getComponent(int k)
Description copied from interface:INDArrayGets a component from the array at the specified index Will throw an error if components are not supported, or if the component is out of bounds as defined by 0 <= k- Specified by:
getComponentin interfaceINDArray- Specified by:
getComponentin classASparseRCMatrix- Returns:
-
get
public double get(int i, int j)Description copied from interface:INDArrayReturns the double value at the specified position in a 2D matrix
-
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
-
unsafeGet
public double unsafeGet(int row, int column)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.
-
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.
-
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.
-
setRow
public void setRow(int i, AVector v)Description copied from class:AMatrixSets a row in a matrix to the value specified by the given vector
-
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
-
addToArray
public void addToArray(double[] targetData, 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
-
getColumns
public java.util.List<AVector> getColumns()
Description copied from interface:IMatrixGets a List of columns of a matrix. May return either copies or views, depending on the specific matrix type.- Specified by:
getColumnsin interfaceIMatrix- Overrides:
getColumnsin classAMatrix- Returns:
-
toSparseColumnMatrix
public SparseColumnMatrix toSparseColumnMatrix()
-
getRow
public AVector getRow(int i)
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).
-
getRows
public java.util.List<AVector> getRows()
Description copied from interface:IMatrixGets a List of rows of a matrix. May return either copies or views, depending on the specific matrix type.
-
getRowView
public AVector getRowView(int i)
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
-
isUpperTriangular
public boolean isUpperTriangular()
Description copied from class:AMatrixReturns true if a matrix is upper triangular An upper triangular matrix is defined as having all elements equal to 0.0 where i > j- Overrides:
isUpperTriangularin classAMatrix
-
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
-
replaceRow
public void replaceRow(int i, AVector vec)Description copied from class:AMatrixReplaces a row in a matrix, adding the row to the internal structure of the matrix. Will throw UnsupportedOperationException if not possible for the given matrix type.- Overrides:
replaceRowin classAMatrix
-
add
public void add(AMatrix a)
Description copied from class:AMatrixAdds another matrix to this matrix. Matrices must be the same size.
-
copyRowTo
public void copyRowTo(int i, double[] data, int offset)Description copied from class:AMatrixCopies the elements in a selected row of this matrix to a double array- Overrides:
copyRowToin classASparseRCMatrix- Parameters:
i- The index of the selected rowdata- Destination double[] arrayoffset- Offset into destination array
-
copyColumnTo
public void copyColumnTo(int col, double[] targetData, int offset)Description copied from class:AMatrixCopies the elements in a selected row of this matrix to a double array- Overrides:
copyColumnToin classASparseRCMatrixtargetData- Destination double[] array
-
getTransposeView
public SparseColumnMatrix 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 classAMatrix- Returns:
- the transpose of this matrix, as a view
-
multiplyCopy
public AMatrix multiplyCopy(double a)
Description copied from interface:INDArrayReturns a copy of the array with all elements multiplied by a single constant value- Specified by:
multiplyCopyin interfaceINDArray- Overrides:
multiplyCopyin classAMatrix- Parameters:
a- A scalar factor- Returns:
- A new array, with all element values scaled by the given factor
-
multiplyRow
public void multiplyRow(int i, double value)Description copied from class:AMatrixMultiplies a row by a constant factor This is an elementary row operation- Overrides:
multiplyRowin classAMatrix
-
innerProduct
public AVector 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
-
rowDotProduct
public double rowDotProduct(int i, AVector a)Description copied from class:AMatrixReturns the dot product of a specific row with a vector. Unsafe operation: performs no bounds checking- Overrides:
rowDotProductin classAMatrix- Returns:
-
toDoubleArray
public double[] toDoubleArray()
Description copied from interface:INDArrayCopies the elements of this array to a new double[] array.- Specified by:
toDoubleArrayin interfaceINDArray- Overrides:
toDoubleArrayin classASparseRCMatrix
-
innerProduct
public AMatrix 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:
-
innerProduct
public SparseRowMatrix innerProduct(SparseColumnMatrix a)
Specialised inner product for sparse row matrix multiplied by sparse column matrix.- Parameters:
a-- Returns:
-
innerProduct
public SparseRowMatrix innerProduct(SparseRowMatrix a)
-
exactClone
public SparseRowMatrix 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
-
clone
public AMatrix 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.
-
sparse
public AMatrix sparse()
Description copied from interface:INDArrayCoerces this INDArray to a sparse format, without changing its element values. May return the same INDArray if already sparse. May also mutate the internal structure of the original NDArray, or create a view over parts of the original INDArray. You should take a defensive copy of the original NDArray if any of this concerns you. The returned sparse array may not be fully mutable in all elements.- Specified by:
sparsein interfaceINDArray- Overrides:
sparsein classASparseRCMatrix
-
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 classASparseRCMatrix
-
equals
public boolean equals(AMatrix m)
Description copied from class:AMatrixReturns true if this matrix is exactly equal to another matrix
-
equals
public boolean equals(IFastRows m)
Compares this matrix to another matrix implementing IFastColumns This can be much faster than the default equals- Parameters:
m-- Returns:
-
-
DMelt 3.0 © DataMelt by jWork.ORG
You see the box below because you did not login.