Package org.apache.spark.ml.linalg
Interface Matrix
- All Superinterfaces:
- Serializable
- All Known Implementing Classes:
- DenseMatrix,- SparseMatrix
Trait for a local matrix.
- 
Method SummaryModifier and TypeMethodDescriptiondoubleapply(int i, int j) Gets the (i, j)-th element.breeze.linalg.Matrix<Object>asBreeze()Converts to a breeze matrix.scala.collection.Iterator<Vector>colIter()Returns an iterator of column vectors.Returns a matrix in dense column major, dense row major, sparse row major, or sparse column major format, whichever uses less storage.Returns a matrix in dense or sparse column major format, whichever uses less storage.Returns a matrix in dense or sparse row major format, whichever uses less storage.copy()Get a deep copy of the matrix.voidforeachActive(scala.Function3<Object, Object, Object, scala.runtime.BoxedUnit> f) Applies a functionfto all the active elements of dense and sparse matrix.longGets the size of the dense representation of this `Matrix`.longGets the current size in bytes of this `Matrix`.longgetSparseSizeInBytes(boolean colMajor) Gets the size of the minimal sparse representation of this `Matrix`.intindex(int i, int j) Return the index for the (i, j)-th element in the backing array.booleanIndicates whether the values backing this matrix are arranged in column major order.booleanIndicates whether the values backing this matrix are arranged in row major order.booleanFlag that keeps track whether the matrix is transposed or not.Map the values of this matrix using a function.Convenience method forMatrix-DenseMatrixmultiplication.Convenience method forMatrix-DenseVectormultiplication.Convenience method forMatrix-Vectormultiplication.intFind the number of values stored explicitly.intnumCols()Number of columns.intFind the number of non-zero active values.intnumRows()Number of rows.scala.collection.Iterator<Vector>rowIter()Returns an iterator of row vectors.double[]toArray()Converts to a dense array in column major.toDense()Converts this matrix to a dense matrix while maintaining the layout of the current matrix.Converts this matrix to a dense matrix in column major order.toDenseMatrix(boolean colMajor) Converts this matrix to a dense matrix.Converts this matrix to a dense matrix in row major order.toSparse()Converts this matrix to a sparse matrix while maintaining the layout of the current matrix.Converts this matrix to a sparse matrix in column major order.toSparseMatrix(boolean colMajor) Converts this matrix to a sparse matrix.Converts this matrix to a sparse matrix in row major order.toString()A human readable representation of the matrixtoString(int maxLines, int maxLineWidth) A human readable representation of the matrix with maximum lines and widthTranspose the Matrix.voidupdate(int i, int j, double v) Update element at (i, j)Update all the values of this matrix using the function f.
- 
Method Details- 
applydouble apply(int i, int j) Gets the (i, j)-th element.
- 
asBreezebreeze.linalg.Matrix<Object> asBreeze()Converts to a breeze matrix.
- 
colIterscala.collection.Iterator<Vector> colIter()Returns an iterator of column vectors. This operation could be expensive, depending on the underlying storage.- Returns:
- (undocumented)
 
- 
compressedMatrix compressed()Returns a matrix in dense column major, dense row major, sparse row major, or sparse column major format, whichever uses less storage. When dense representation is optimal, it maintains the current layout order.- Returns:
- (undocumented)
 
- 
compressedColMajorMatrix compressedColMajor()Returns a matrix in dense or sparse column major format, whichever uses less storage.- Returns:
- (undocumented)
 
- 
compressedRowMajorMatrix compressedRowMajor()Returns a matrix in dense or sparse row major format, whichever uses less storage.- Returns:
- (undocumented)
 
- 
copyMatrix copy()Get a deep copy of the matrix.
- 
foreachActiveApplies a functionfto all the active elements of dense and sparse matrix. The ordering of the elements are not defined.- Parameters:
- f- the function takes three parameters where the first two parameters are the row and column indices respectively with the type- Int, and the final parameter is the corresponding value in the matrix with type- Double.
 
- 
getDenseSizeInByteslong getDenseSizeInBytes()Gets the size of the dense representation of this `Matrix`.
- 
getSizeInByteslong getSizeInBytes()Gets the current size in bytes of this `Matrix`. Useful for testing
- 
getSparseSizeInByteslong getSparseSizeInBytes(boolean colMajor) Gets the size of the minimal sparse representation of this `Matrix`.
- 
indexint index(int i, int j) Return the index for the (i, j)-th element in the backing array.
- 
isColMajorboolean isColMajor()Indicates whether the values backing this matrix are arranged in column major order.
- 
isRowMajorboolean isRowMajor()Indicates whether the values backing this matrix are arranged in row major order.
- 
isTransposedboolean isTransposed()Flag that keeps track whether the matrix is transposed or not. False by default.
- 
mapMap the values of this matrix using a function. Generates a new matrix. Performs the function on only the backing array. For example, an operation such as addition or subtraction will only be performed on the non-zero values in aSparseMatrix.- Parameters:
- f- (undocumented)
- Returns:
- (undocumented)
 
- 
multiplyConvenience method forMatrix-DenseMatrixmultiplication.- Parameters:
- y- (undocumented)
- Returns:
- (undocumented)
 
- 
multiplyConvenience method forMatrix-DenseVectormultiplication. For binary compatibility.- Parameters:
- y- (undocumented)
- Returns:
- (undocumented)
 
- 
multiplyConvenience method forMatrix-Vectormultiplication.- Parameters:
- y- (undocumented)
- Returns:
- (undocumented)
 
- 
numActivesint numActives()Find the number of values stored explicitly. These values can be zero as well.- Returns:
- (undocumented)
 
- 
numColsint numCols()Number of columns.
- 
numNonzerosint numNonzeros()Find the number of non-zero active values.- Returns:
- (undocumented)
 
- 
numRowsint numRows()Number of rows.
- 
rowIterscala.collection.Iterator<Vector> rowIter()Returns an iterator of row vectors. This operation could be expensive, depending on the underlying storage.- Returns:
- (undocumented)
 
- 
toArraydouble[] toArray()Converts to a dense array in column major.
- 
toDenseDenseMatrix toDense()Converts this matrix to a dense matrix while maintaining the layout of the current matrix.- Returns:
- (undocumented)
 
- 
toDenseColMajorDenseMatrix toDenseColMajor()Converts this matrix to a dense matrix in column major order.- Returns:
- (undocumented)
 
- 
toDenseMatrixConverts this matrix to a dense matrix.- Parameters:
- colMajor- Whether the values of the resulting dense matrix should be in column major or row major order. If- false, resulting matrix will be row major.
- Returns:
- (undocumented)
 
- 
toDenseRowMajorDenseMatrix toDenseRowMajor()Converts this matrix to a dense matrix in row major order.- Returns:
- (undocumented)
 
- 
toSparseSparseMatrix toSparse()Converts this matrix to a sparse matrix while maintaining the layout of the current matrix.- Returns:
- (undocumented)
 
- 
toSparseColMajorSparseMatrix toSparseColMajor()Converts this matrix to a sparse matrix in column major order.- Returns:
- (undocumented)
 
- 
toSparseMatrixConverts this matrix to a sparse matrix.- Parameters:
- colMajor- Whether the values of the resulting sparse matrix should be in column major or row major order. If- false, resulting matrix will be row major.
- Returns:
- (undocumented)
 
- 
toSparseRowMajorSparseMatrix toSparseRowMajor()Converts this matrix to a sparse matrix in row major order.- Returns:
- (undocumented)
 
- 
toStringString toString()A human readable representation of the matrix
- 
toStringA human readable representation of the matrix with maximum lines and width
- 
transposeMatrix transpose()Transpose the Matrix. Returns a newMatrixinstance sharing the same underlying data.- Returns:
- (undocumented)
 
- 
updatevoid update(int i, int j, double v) Update element at (i, j)
- 
updateUpdate all the values of this matrix using the function f. Performed in-place on the backing array. For example, an operation such as addition or subtraction will only be performed on the non-zero values in aSparseMatrix.- Parameters:
- f- (undocumented)
- Returns:
- (undocumented)
 
 
-