Package de.jungblut.writable
Class MatrixWritable
- java.lang.Object
-
- de.jungblut.writable.MatrixWritable
-
- All Implemented Interfaces:
org.apache.hadoop.io.Writable
public final class MatrixWritable extends java.lang.Object implements org.apache.hadoop.io.WritableWritable class for dense and sparse matrices.
-
-
Field Summary
Fields Modifier and Type Field Description static byteDENSE_DOUBLE_MATRIXstatic byteSPARSE_DOUBLE_ROW_MATRIX
-
Constructor Summary
Constructors Constructor Description MatrixWritable()MatrixWritable(de.jungblut.math.DoubleMatrix mat)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description de.jungblut.math.DoubleMatrixgetMatrix()static de.jungblut.math.dense.DenseDoubleMatrixreadDenseMatrix(java.io.DataInput in)Reads a dense matrix from the given input stream.voidreadFields(java.io.DataInput in)static de.jungblut.math.sparse.SparseDoubleRowMatrixreadSparseMatrix(java.io.DataInput in)Reads a sparse matrix from the given input stream.voidwrite(java.io.DataOutput out)static voidwriteDenseMatrix(de.jungblut.math.dense.DenseDoubleMatrix mat, java.io.DataOutput out)Writes a dense matrix to the given output stream.static voidwriteSparseMatrix(de.jungblut.math.sparse.SparseDoubleRowMatrix mat, java.io.DataOutput out)Writes a sparse matrix to the given output stream.
-
-
-
Field Detail
-
DENSE_DOUBLE_MATRIX
public static final byte DENSE_DOUBLE_MATRIX
- See Also:
- Constant Field Values
-
SPARSE_DOUBLE_ROW_MATRIX
public static final byte SPARSE_DOUBLE_ROW_MATRIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
readFields
public void readFields(java.io.DataInput in) throws java.io.IOException- Specified by:
readFieldsin interfaceorg.apache.hadoop.io.Writable- Throws:
java.io.IOException
-
write
public void write(java.io.DataOutput out) throws java.io.IOException- Specified by:
writein interfaceorg.apache.hadoop.io.Writable- Throws:
java.io.IOException
-
getMatrix
public de.jungblut.math.DoubleMatrix getMatrix()
-
writeSparseMatrix
public static void writeSparseMatrix(de.jungblut.math.sparse.SparseDoubleRowMatrix mat, java.io.DataOutput out) throws java.io.IOExceptionWrites a sparse matrix to the given output stream. The layout is as simple as in memory, first the dimension is written (row count, column count as integer) then the number of non-zero row vectors are written (integer). Afterwards for each non-zero row vector the row index (integer) itself is written as well as the count of non-zero elements in the row vector. Then for each non-zero element an integer column index and a double value is following.- Parameters:
mat- the sparse matrix to serialize.out- the output.- Throws:
java.io.IOException- in case of an IO error.
-
readSparseMatrix
public static de.jungblut.math.sparse.SparseDoubleRowMatrix readSparseMatrix(java.io.DataInput in) throws java.io.IOExceptionReads a sparse matrix from the given input stream.- Parameters:
in- the input stream.- Returns:
- a new sparse matrix from the stream.
- Throws:
java.io.IOException- in case of an IO error.
-
writeDenseMatrix
public static void writeDenseMatrix(de.jungblut.math.dense.DenseDoubleMatrix mat, java.io.DataOutput out) throws java.io.IOExceptionWrites a dense matrix to the given output stream. The layout is as simple as in memory, first the dimension is written (row count, column count as integer) afterwards there are following row*columns doubles in a row major fashion.- Parameters:
mat- the dense matrix to serialize.out- the output.- Throws:
java.io.IOException- in case of an IO error.
-
readDenseMatrix
public static de.jungblut.math.dense.DenseDoubleMatrix readDenseMatrix(java.io.DataInput in) throws java.io.IOExceptionReads a dense matrix from the given input stream.- Parameters:
in- the input stream.- Returns:
- a new dense matrix from the stream.
- Throws:
java.io.IOException- in case of an IO error.
-
-