Class MatrixWritable

  • All Implemented Interfaces:
    org.apache.hadoop.io.Writable

    public final class MatrixWritable
    extends java.lang.Object
    implements org.apache.hadoop.io.Writable
    Writable class for dense and sparse matrices.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      de.jungblut.math.DoubleMatrix getMatrix()  
      static de.jungblut.math.dense.DenseDoubleMatrix readDenseMatrix​(java.io.DataInput in)
      Reads a dense matrix from the given input stream.
      void readFields​(java.io.DataInput in)  
      static de.jungblut.math.sparse.SparseDoubleRowMatrix readSparseMatrix​(java.io.DataInput in)
      Reads a sparse matrix from the given input stream.
      void write​(java.io.DataOutput out)  
      static void writeDenseMatrix​(de.jungblut.math.dense.DenseDoubleMatrix mat, java.io.DataOutput out)
      Writes a dense matrix to the given output stream.
      static void writeSparseMatrix​(de.jungblut.math.sparse.SparseDoubleRowMatrix mat, java.io.DataOutput out)
      Writes a sparse matrix to the given output stream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MatrixWritable

        public MatrixWritable()
      • MatrixWritable

        public MatrixWritable​(de.jungblut.math.DoubleMatrix mat)
    • Method Detail

      • readFields

        public void readFields​(java.io.DataInput in)
                        throws java.io.IOException
        Specified by:
        readFields in interface org.apache.hadoop.io.Writable
        Throws:
        java.io.IOException
      • write

        public void write​(java.io.DataOutput out)
                   throws java.io.IOException
        Specified by:
        write in interface org.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.IOException
        Writes 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.IOException
        Reads 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.IOException
        Writes 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.IOException
        Reads 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.