Search in sources :

Example 1 with MatrixSparse

use of gov.sandia.n2a.linear.MatrixSparse in project n2a by frothga.

the class Matrix method factory.

public static Matrix factory(Path path) throws EvaluationException {
    try (BufferedReader reader = Files.newBufferedReader(path)) {
        char[] buffer = new char[10];
        reader.mark(buffer.length + 1);
        // just assume buffer is filled completely
        reader.read(buffer);
        String line = new String(buffer);
        reader.reset();
        if (line.toLowerCase().startsWith("sparse"))
            return new MatrixSparse(reader);
        // TODO: import Matlab format.
        return new MatrixDense(reader);
    } catch (IOException exception) {
        throw new EvaluationException("Can't open matrix file");
    }
}
Also used : BufferedReader(java.io.BufferedReader) MatrixSparse(gov.sandia.n2a.linear.MatrixSparse) MatrixDense(gov.sandia.n2a.linear.MatrixDense) IOException(java.io.IOException) EvaluationException(gov.sandia.n2a.language.EvaluationException)

Aggregations

EvaluationException (gov.sandia.n2a.language.EvaluationException)1 MatrixDense (gov.sandia.n2a.linear.MatrixDense)1 MatrixSparse (gov.sandia.n2a.linear.MatrixSparse)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1