Package no.uib.cipr.matrix.io
Class MatrixVectorReader
- java.lang.Object
-
- java.io.Reader
-
- java.io.BufferedReader
-
- no.uib.cipr.matrix.io.MatrixVectorReader
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.lang.Readable
public class MatrixVectorReader extends java.io.BufferedReader
Reads matrices and vectors
-
-
Constructor Summary
Constructors Constructor Description MatrixVectorReader(java.io.Reader in)
Constructor for MatrixVectorReaderMatrixVectorReader(java.io.Reader in, int sz)
Constructor for MatrixVectorReader
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int num, int[] indices)
Shifts the indices.boolean
hasInfo()
Checks if a Matrix Market header is present ("%%MatrixMarket")void
readArray(double[] data)
Reads the array datavoid
readArray(double[] dataR, double[] dataI)
Reads the array data.void
readArray(float[] data)
Reads the array datavoid
readArray(float[] dataR, float[] dataI)
Reads the array data.void
readArray(int[] data)
Reads the array datavoid
readArray(long[] data)
Reads the array dataMatrixSize
readArraySize()
Reads in the size of an array matrix.java.lang.String[]
readComments()
Reads all the comments (lines starting with '%').void
readCoordinate(int[] index, double[] data)
Reads a coordinate vectorvoid
readCoordinate(int[] index, double[] dataR, double[] dataI)
Reads a coordinate vector.void
readCoordinate(int[] index, float[] data)
Reads a coordinate vectorvoid
readCoordinate(int[] index, float[] dataR, float[] dataI)
Reads a coordinate vector.void
readCoordinate(int[] index, int[] data)
Reads a coordinate vectorvoid
readCoordinate(int[] row, int[] column, double[] data)
Reads a coordinate matrixvoid
readCoordinate(int[] row, int[] column, double[] dataR, double[] dataI)
Reads a coordinate matrix.void
readCoordinate(int[] row, int[] column, float[] data)
Reads a coordinate matrixvoid
readCoordinate(int[] row, int[] column, float[] dataR, float[] dataI)
Reads a coordinate matrix.void
readCoordinate(int[] row, int[] column, int[] data)
Reads a coordinate matrixvoid
readCoordinate(int[] row, int[] column, long[] data)
Reads a coordinate matrixvoid
readCoordinate(int[] index, long[] data)
Reads a coordinate vectorMatrixSize
readCoordinateSize()
Reads in the size of a coordinate matrix.MatrixInfo
readMatrixInfo()
Reads the matrix info for the Matrix Market exchange format.MatrixSize
readMatrixSize(MatrixInfo info)
Reads in the size of a matrix.void
readPattern(int[] index)
Reads a pattern vectorvoid
readPattern(int[] row, int[] column)
Reads a pattern matrixVectorSize
readVectorArraySize()
Reads in the size of a dense vector.VectorSize
readVectorCoordinateSize()
Reads in the size of a coordinate vector.VectorInfo
readVectorInfo()
Reads the vector info for the Matrix Market exchange format.VectorSize
readVectorSize(VectorInfo info)
Reads in the size of a vector.
-
-
-
Constructor Detail
-
MatrixVectorReader
public MatrixVectorReader(java.io.Reader in)
Constructor for MatrixVectorReader- Parameters:
in
- A Reader
-
MatrixVectorReader
public MatrixVectorReader(java.io.Reader in, int sz)
Constructor for MatrixVectorReader- Parameters:
in
- A Readersz
- Input buffer size
-
-
Method Detail
-
add
public void add(int num, int[] indices)
Shifts the indices. Useful for converting between 0- and 1-based indicing.- Parameters:
num
- Added to every indexindices
- Indices to shift
-
readMatrixInfo
public MatrixInfo readMatrixInfo() throws java.io.IOException
Reads the matrix info for the Matrix Market exchange format. The line must consist of exactly 5 space-separated entries, the first being "%%MatrixMarket"- Throws:
java.io.IOException
-
readVectorInfo
public VectorInfo readVectorInfo() throws java.io.IOException
Reads the vector info for the Matrix Market exchange format. The line must consist of exactly 4 space-separated entries, the first being "%%MatrixMarket"- Throws:
java.io.IOException
-
hasInfo
public boolean hasInfo() throws java.io.IOException
Checks if a Matrix Market header is present ("%%MatrixMarket")- Returns:
- True if a header was found, else false
- Throws:
java.io.IOException
-
readComments
public java.lang.String[] readComments() throws java.io.IOException
Reads all the comments (lines starting with '%'). Positions the reader at the first non-comment line. Can only be called after reading the matrix or vector info. The comments read does not include '%' or the newline- Throws:
java.io.IOException
-
readMatrixSize
public MatrixSize readMatrixSize(MatrixInfo info) throws java.io.IOException
Reads in the size of a matrix. Skips initial comments- Throws:
java.io.IOException
-
readArraySize
public MatrixSize readArraySize() throws java.io.IOException
Reads in the size of an array matrix. Skips initial comments- Throws:
java.io.IOException
-
readCoordinateSize
public MatrixSize readCoordinateSize() throws java.io.IOException
Reads in the size of a coordinate matrix. Skips initial comments- Throws:
java.io.IOException
-
readVectorSize
public VectorSize readVectorSize(VectorInfo info) throws java.io.IOException
Reads in the size of a vector. Skips initial comments- Throws:
java.io.IOException
-
readVectorArraySize
public VectorSize readVectorArraySize() throws java.io.IOException
Reads in the size of a dense vector. Skips initial comments- Throws:
java.io.IOException
-
readVectorCoordinateSize
public VectorSize readVectorCoordinateSize() throws java.io.IOException
Reads in the size of a coordinate vector. Skips initial comments- Throws:
java.io.IOException
-
readArray
public void readArray(double[] data) throws java.io.IOException
Reads the array data- Throws:
java.io.IOException
-
readArray
public void readArray(float[] data) throws java.io.IOException
Reads the array data- Throws:
java.io.IOException
-
readArray
public void readArray(int[] data) throws java.io.IOException
Reads the array data- Throws:
java.io.IOException
-
readArray
public void readArray(long[] data) throws java.io.IOException
Reads the array data- Throws:
java.io.IOException
-
readArray
public void readArray(double[] dataR, double[] dataI) throws java.io.IOException
Reads the array data. The first array will contain real entries, while the second contain imaginary entries- Throws:
java.io.IOException
-
readArray
public void readArray(float[] dataR, float[] dataI) throws java.io.IOException
Reads the array data. The first array will contain real entries, while the second contain imaginary entries- Throws:
java.io.IOException
-
readCoordinate
public void readCoordinate(int[] index, double[] data) throws java.io.IOException
Reads a coordinate vector- Throws:
java.io.IOException
-
readCoordinate
public void readCoordinate(int[] index, float[] data) throws java.io.IOException
Reads a coordinate vector- Throws:
java.io.IOException
-
readCoordinate
public void readCoordinate(int[] index, int[] data) throws java.io.IOException
Reads a coordinate vector- Throws:
java.io.IOException
-
readCoordinate
public void readCoordinate(int[] index, long[] data) throws java.io.IOException
Reads a coordinate vector- Throws:
java.io.IOException
-
readCoordinate
public void readCoordinate(int[] index, float[] dataR, float[] dataI) throws java.io.IOException
Reads a coordinate vector. First data array contains real entries, and the second contains imaginary entries- Throws:
java.io.IOException
-
readCoordinate
public void readCoordinate(int[] index, double[] dataR, double[] dataI) throws java.io.IOException
Reads a coordinate vector. First data array contains real entries, and the second contains imaginary entries- Throws:
java.io.IOException
-
readPattern
public void readPattern(int[] index) throws java.io.IOException
Reads a pattern vector- Throws:
java.io.IOException
-
readCoordinate
public void readCoordinate(int[] row, int[] column, double[] data) throws java.io.IOException
Reads a coordinate matrix- Throws:
java.io.IOException
-
readCoordinate
public void readCoordinate(int[] row, int[] column, float[] data) throws java.io.IOException
Reads a coordinate matrix- Throws:
java.io.IOException
-
readCoordinate
public void readCoordinate(int[] row, int[] column, int[] data) throws java.io.IOException
Reads a coordinate matrix- Throws:
java.io.IOException
-
readCoordinate
public void readCoordinate(int[] row, int[] column, long[] data) throws java.io.IOException
Reads a coordinate matrix- Throws:
java.io.IOException
-
readPattern
public void readPattern(int[] row, int[] column) throws java.io.IOException
Reads a pattern matrix- Throws:
java.io.IOException
-
readCoordinate
public void readCoordinate(int[] row, int[] column, double[] dataR, double[] dataI) throws java.io.IOException
Reads a coordinate matrix. First data array contains real entries, and the second contains imaginary entries- Throws:
java.io.IOException
-
readCoordinate
public void readCoordinate(int[] row, int[] column, float[] dataR, float[] dataI) throws java.io.IOException
Reads a coordinate matrix. First data array contains real entries, and the second contains imaginary entries- Throws:
java.io.IOException
-
-