org.apache.spark.mllib.linalg
Interface Matrix

All Superinterfaces:
java.io.Serializable
All Known Implementing Classes:
DenseMatrix, SparseMatrix

public interface Matrix
extends scala.Serializable

Trait for a local matrix.


Method Summary
 double apply(int i, int j)
          Gets the (i, j)-th element.
 Matrix copy()
          Get a deep copy of the matrix.
 void foreachActive(scala.Function3<Object,Object,Object,scala.runtime.BoxedUnit> f)
          Applies a function f 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 isTransposed()
          Flag that keeps track whether the matrix is transposed or not.
 Matrix map(scala.Function1<Object,Object> f)
          Map the values of this matrix using a function.
 DenseMatrix multiply(DenseMatrix y)
          Convenience method for `Matrix`-`DenseMatrix` multiplication.
 DenseVector multiply(DenseVector y)
          Convenience method for `Matrix`-`DenseVector` multiplication.
 DenseVector multiply(Vector y)
          Convenience method for `Matrix`-`Vector` multiplication.
 int numCols()
          Number of columns.
 int numRows()
          Number of rows.
 double[] toArray()
          Converts to a dense array in column major.
 breeze.linalg.Matrix<Object> toBreeze()
          Converts to a breeze matrix.
 String toString()
          A human readable representation of the matrix
 String toString(int maxLines, int maxLineWidth)
          A human readable representation of the matrix with maximum lines and width
 Matrix transpose()
          Transpose the Matrix.
 Matrix update(scala.Function1<Object,Object> f)
          Update all the values of this matrix using the function f.
 void update(int i, int j, double v)
          Update element at (i, j)
 

Method Detail

numRows

int numRows()
Number of rows.


numCols

int numCols()
Number of columns.


isTransposed

boolean isTransposed()
Flag that keeps track whether the matrix is transposed or not. False by default.


toArray

double[] toArray()
Converts to a dense array in column major.


toBreeze

breeze.linalg.Matrix<Object> toBreeze()
Converts to a breeze matrix.


apply

double apply(int i,
             int j)
Gets the (i, j)-th element.


index

int index(int i,
          int j)
Return the index for the (i, j)-th element in the backing array.


update

void update(int i,
            int j,
            double v)
Update element at (i, j)


copy

Matrix copy()
Get a deep copy of the matrix.


transpose

Matrix transpose()
Transpose the Matrix. Returns a new `Matrix` instance sharing the same underlying data.


multiply

DenseMatrix multiply(DenseMatrix y)
Convenience method for `Matrix`-`DenseMatrix` multiplication.


multiply

DenseVector multiply(DenseVector y)
Convenience method for `Matrix`-`DenseVector` multiplication. For binary compatibility.


multiply

DenseVector multiply(Vector y)
Convenience method for `Matrix`-`Vector` multiplication.


toString

String toString()
A human readable representation of the matrix

Overrides:
toString in class Object

toString

String toString(int maxLines,
                int maxLineWidth)
A human readable representation of the matrix with maximum lines and width


map

Matrix map(scala.Function1<Object,Object> f)
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

Parameters:
f - (undocumented)
Returns:
(undocumented) subtraction will only be performed on the non-zero values in a SparseMatrix.

update

Matrix update(scala.Function1<Object,Object> f)
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

Parameters:
f - (undocumented)
Returns:
(undocumented) performed on the non-zero values in a SparseMatrix.

foreachActive

void foreachActive(scala.Function3<Object,Object,Object,scala.runtime.BoxedUnit> f)
Applies a function f 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 type Int, and the final parameter is the corresponding value in the matrix with type Double.