mikera.matrixx.impl
Class SparseColumnMatrix
- java.lang.Object
-
- mikera.arrayz.impl.AbstractArray<AVector>
-
- mikera.matrixx.AMatrix
-
- mikera.matrixx.impl.ARectangularMatrix
-
- mikera.matrixx.impl.ASparseRCMatrix
-
- mikera.matrixx.impl.SparseColumnMatrix
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<INDArray>, java.lang.Iterable<AVector>, INDArray, ISparse, IMatrix, IFastColumns
public class SparseColumnMatrix extends ASparseRCMatrix implements ISparse, IFastColumns
Matrix stored as a collection of normally sparse column vectors This format is especially efficient for: - transposeInnerProduct() with another matrix - access via getColumn() operation - transpose into SparseRowMatrix- 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 operationAMatrixaddCopy(AMatrix m)Adds another matrix to this matrix, returning a new matrixSparseRowMatrixaddCopy(AVector v)Adds a vector to every row of this matrix, returning a new matrixSparseColumnMatrixaddCopy(SparseColumnMatrix m)Adds another SparseColumnMatrix to this matrixvoidaddMultiple(AMatrix a, double factor)Adds a scalar multiple of another matrix to this matrixvoidaddToArray(double[] targetData, int offset)Adds all the elements of this array to a double array at the specified offset, in row-major ordervoidapplyOp(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)voidapplyOp(Op2 op, AMatrix b)voidapplyOp(Op2 op, double b)Applies a binary operator to this array and a double value.AMatrixclone()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 i, double[] targetData, int offset)Copies the elements in a selected row of this matrix to a double arrayvoidcopyRowTo(int row, double[] targetData, int offset)Copies the elements in a selected row of this matrix to a double arraystatic SparseColumnMatrixcreate(AMatrix source)static SparseColumnMatrixcreate(AVector... vecs)Create a SparseColumnMatrix wrapping a specified array of columns null may be provided after first rowstatic SparseColumnMatrixcreate(AVector[] data, int rows, int cols)static SparseColumnMatrixcreate(int rows, int cols)static SparseColumnMatrixcreate(java.util.List<AVector> columns)booleanepsilonEquals(AMatrix a, double epsilon)booleanequals(AMatrix m)Returns true if this matrix is exactly equal to another matrixbooleanequals(IFastColumns m)Compares this matrix to another matrix implementing IFastColumns This is much faster than the default equalsbooleanequalsArray(double[] data, int offset)Returns true if the elements in this array exactly match the elements in the given array, in row-major orderSparseColumnMatrixexactClone()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 matrixAVectorgetColumn(int j)Returns a column of the matrix.AVectorgetColumnView(int j)Returns a column of the matrix as a vector view.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 <= kjava.util.List<AVector>getRows()Gets a List of rows of a matrix.SparseRowMatrixgetTransposeView()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 vectorVectorinnerProduct(Vector a)Transforms a dense source Vector using matrix multiplication (inner product).booleanisLowerTriangular()Returns true if a matrix is lower triangular.AMatrixmultiplyCopy(double a)Returns a copy of the array with all elements multiplied by a single constant valuedoublereduce(Op2 op, double init)Reduces over all elements of the array in row-major order.voidreplaceColumn(int i, AVector vec)Replaces a column in a matrix, adding the column to the internal structure of the matrix.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 arrayvoidsetColumn(int i, AVector col)Sets a column in a matrix.AMatrixsparse()Coerces this INDArray to a sparse format, without changing its element values.voidswapColumns(int i, int j)Swaps two columns of the matrix in placedouble[]toDoubleArray()Copies the elements of this array to a new double[] array.MatrixtoMatrixTranspose()Coerces the transpose of a matrix to the standard mutable Matrix type in row major order.SparseRowMatrixtoSparseRowMatrix()Coerces this matrix into a SparseRowMatrix format.AMatrixtransposeInnerProduct(AMatrix a)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 SparseColumnMatrixwrap(AVector... vecs)static SparseColumnMatrixwrap(AVector[] vecs, int rows, int cols)static SparseColumnMatrixwrap(java.util.List<AVector> vecs)-
Methods inherited from class mikera.matrixx.impl.ASparseRCMatrix
abs, 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, addInnerProduct, addInnerProduct, addInnerProduct, addMultiple, addMultiple, addOuterProduct, addOuterProduct, addOuterProductSparse, addOuterProductSparse, addRowMultiple, addSparse, addSparse, 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, equals, equals, equalsTranspose, get, get, get, get, getBand, getBandWrapped, getColumns, getElements, getLeadingDiagonal, getLongShape, getRow, getRowView, getSlices, getSlices, getSliceViews, getTranspose, getTransposeCopy, hashCode, hasOrthonormalColumns, hasOrthonormalRows, hasUncountable, immutable, innerProduct, innerProduct, innerProduct, inputDimensions, inverse, isBoolean, isDiagonal, isElementConstrained, isHermitian, isIdentity, isInvertible, isOrthogonal, isOrthogonal, isPositiveDefinite, isRectangularDiagonal, isSymmetric, isUpperTriangular, isView, iterator, join, lowerBandwidth, lowerBandwidthLimit, mul, multiply, multiply, multiply, multiply, multiplyRow, mutable, negate, outerProduct, outputDimensions, rank, reduce, reduceSlices, reduceSlices, reorder, reorder, replaceRow, reshape, reshape, rotateView, rowDotProduct, scaleAdd, scaleAdd, set, set, set, set, set, set, set, setApplyOp, setApplyOp, setElements, setElements, setMultiple, setMultiple, setMultiple, setMultiple, setMultiple, setRow, setSparse, setSparse, signum, slice, slice, sliceCount, sparseClone, sub, sub, sub, subArray, subCopy, subMatrix, swapRows, toAffineTransform, toDoubleBuffer, toMatrix, toMutableMatrix, toNestedDoubleArrays, toSliceArray, toString, toStringFull, toVector, trace, transform, transform, transformInPlace, transformInPlace, 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, columnCount, diagonalProduct, getBand, getColumnClone, getColumns, getRow, getRowClone, getRowView, getTranspose, 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, 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, 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, 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 SparseColumnMatrix create(int rows, int cols)
-
create
public static SparseColumnMatrix create(AVector[] data, int rows, int cols)
-
create
public static SparseColumnMatrix create(AVector... vecs)
Create a SparseColumnMatrix wrapping a specified array of columns null may be provided after first row- Parameters:
vecs-- Returns:
-
create
public static SparseColumnMatrix create(java.util.List<AVector> columns)
-
wrap
public static SparseColumnMatrix wrap(AVector[] vecs, int rows, int cols)
-
wrap
public static SparseColumnMatrix wrap(AVector... vecs)
-
create
public static SparseColumnMatrix create(AMatrix source)
-
wrap
public static SparseColumnMatrix 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.
-
setColumn
public void setColumn(int i, AVector col)Description copied from class:AMatrixSets a column in a matrix.
-
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
-
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.
-
applyOp
public void applyOp(IOperator op)
Description copied from interface:INDArrayApplies a unary operator to all elements of the array (in-place)
-
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 classASparseRCMatrix
-
reduce
public double reduce(Op2 op, double init)
Description copied from interface:INDArrayReduces over all elements of the array in row-major order. Applies the operator to the initial/previous result at each step. Returns the final result.
-
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.
-
toSparseRowMatrix
public SparseRowMatrix toSparseRowMatrix()
Coerces this matrix into a SparseRowMatrix format.- Returns:
-
getColumn
public AVector getColumn(int j)
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).
-
getColumnView
public AVector getColumnView(int j)
Description copied from interface:IMatrixReturns a column of the matrix as a vector view. May be used to modify the original matrix.- Specified by:
getColumnViewin interfaceIMatrix- Overrides:
getColumnViewin classAMatrix
-
isLowerTriangular
public boolean isLowerTriangular()
Description copied from class:AMatrixReturns true if a matrix is lower triangular. A lower triangular matrix is defined as having all elements equal to 0.0 where i < j- Overrides:
isLowerTriangularin classAMatrix
-
swapColumns
public void swapColumns(int i, int j)Description copied from class:AMatrixSwaps two columns of the matrix in place- Overrides:
swapColumnsin classAMatrix
-
replaceColumn
public void replaceColumn(int i, AVector vec)Description copied from class:AMatrixReplaces a column in a matrix, adding the column to the internal structure of the matrix. Will throw UnsupportedOperationException if not possible for the given matrix type.- Overrides:
replaceColumnin classAMatrix
-
add
public void add(AMatrix a)
Description copied from class:AMatrixAdds another matrix to this matrix. Matrices must be the same size.
-
addMultiple
public void addMultiple(AMatrix a, double factor)
Description copied from class:AMatrixAdds a scalar multiple of another matrix to this matrix- Overrides:
addMultiplein classAMatrix
-
addCopy
public AMatrix addCopy(AMatrix m)
Description copied from interface:IMatrixAdds another matrix to this matrix, returning a new matrix
-
addCopy
public SparseRowMatrix addCopy(AVector v)
Description copied from interface:IMatrixAdds a vector to every row of this matrix, returning a new matrix
-
addCopy
public SparseColumnMatrix addCopy(SparseColumnMatrix m)
Adds another SparseColumnMatrix to this matrix- Parameters:
m-- Returns:
- A new SparseColumnMatrix
-
copyColumnTo
public void copyColumnTo(int i, 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
-
copyRowTo
public void copyRowTo(int row, double[] targetData, int offset)Description copied from class:AMatrixCopies the elements in a selected row of this matrix to a double array- Overrides:
copyRowToin classASparseRCMatrix- Parameters:
row- The index of the selected rowtargetData- Destination double[] arrayoffset- Offset into destination array
-
getTransposeView
public SparseRowMatrix 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
-
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 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
-
innerProduct
public Vector innerProduct(Vector a)
Description copied from interface:IMatrixTransforms a dense source Vector using matrix multiplication (inner product).- Specified by:
innerProductin interfaceIMatrix- Overrides:
innerProductin classAMatrix- Returns:
- A new dense vector
-
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
-
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
-
transposeInnerProduct
public AMatrix transposeInnerProduct(AMatrix a)
- Overrides:
transposeInnerProductin classAMatrix
-
exactClone
public SparseColumnMatrix 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
-
epsilonEquals
public boolean epsilonEquals(AMatrix a, double epsilon)
- Overrides:
epsilonEqualsin classAMatrix
-
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(IFastColumns m)
Compares this matrix to another matrix implementing IFastColumns This is much faster than the default equals- Parameters:
m-- Returns:
-
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:
-
-
DMelt 3.0 © DataMelt by jWork.ORG
You see the box below because you did not login.