Package org.apache.spark.mllib.linalg
Interface Matrix
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
DenseMatrix
,SparseMatrix
Trait for a local matrix.
-
Method Summary
Modifier and TypeMethodDescriptiondouble
apply
(int i, int j) Gets the (i, j)-th element.breeze.linalg.Matrix<Object>
asBreeze()
Converts to a breeze matrix.asML()
Convert this matrix to the new mllib-local representation.scala.collection.Iterator<Vector>
colIter()
Returns an iterator of column vectors.copy()
Get a deep copy of the matrix.void
foreachActive
(scala.Function3<Object, Object, Object, scala.runtime.BoxedUnit> f) Applies a functionf
to all the active elements of dense and sparse matrix.int
index
(int i, int j) Return the index for the (i, j)-th element in the backing array.boolean
Flag that keeps track whether the matrix is transposed or not.Map the values of this matrix using a function.Convenience method forMatrix
-DenseMatrix
multiplication.Convenience method forMatrix
-DenseVector
multiplication.Convenience method forMatrix
-Vector
multiplication.int
Find the number of values stored explicitly.int
numCols()
Number of columns.int
Find the number of non-zero active values.int
numRows()
Number of rows.scala.collection.Iterator<Vector>
rowIter()
Returns an iterator of row vectors.double[]
toArray()
Converts to a dense array in column major.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.void
update
(int i, int j, double v) Update element at (i, j)Update all the values of this matrix using the function f.
-
Method Details
-
apply
double apply(int i, int j) Gets the (i, j)-th element. -
asBreeze
breeze.linalg.Matrix<Object> asBreeze()Converts to a breeze matrix. -
asML
Matrix asML()Convert this matrix to the new mllib-local representation. This does NOT copy the data; it copies references.- Returns:
- (undocumented)
-
colIter
scala.collection.Iterator<Vector> colIter()Returns an iterator of column vectors. This operation could be expensive, depending on the underlying storage.- Returns:
- (undocumented)
-
copy
Matrix copy()Get a deep copy of the matrix. -
foreachActive
Applies a functionf
to 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 typeInt
, and the final parameter is the corresponding value in the matrix with typeDouble
.
-
index
int index(int i, int j) Return the index for the (i, j)-th element in the backing array. -
isTransposed
boolean isTransposed()Flag that keeps track whether the matrix is transposed or not. False by default. -
map
Map 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)
-
multiply
Convenience method forMatrix
-DenseMatrix
multiplication.- Parameters:
y
- (undocumented)- Returns:
- (undocumented)
-
multiply
Convenience method forMatrix
-DenseVector
multiplication. For binary compatibility.- Parameters:
y
- (undocumented)- Returns:
- (undocumented)
-
multiply
Convenience method forMatrix
-Vector
multiplication.- Parameters:
y
- (undocumented)- Returns:
- (undocumented)
-
numActives
int numActives()Find the number of values stored explicitly. These values can be zero as well.- Returns:
- (undocumented)
-
numCols
int numCols()Number of columns. -
numNonzeros
int numNonzeros()Find the number of non-zero active values.- Returns:
- (undocumented)
-
numRows
int numRows()Number of rows. -
rowIter
scala.collection.Iterator<Vector> rowIter()Returns an iterator of row vectors. This operation could be expensive, depending on the underlying storage.- Returns:
- (undocumented)
-
toArray
double[] toArray()Converts to a dense array in column major. -
toString
String toString()A human readable representation of the matrix -
toString
A human readable representation of the matrix with maximum lines and width -
transpose
Matrix transpose()Transpose the Matrix. Returns a newMatrix
instance sharing the same underlying data.- Returns:
- (undocumented)
-
update
void update(int i, int j, double v) Update element at (i, j) -
update
Update 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)
-