use of org.apache.commons.math3.linear.NonSquareMatrixException in project olca-modules by GreenDelta.
the class JuliaSolver method solve.
@Override
public double[] solve(MatrixReader a, int idx, double d) {
if (!a.isSquare())
throw new NonSquareMatrixException(a.rows(), a.columns());
if (Julia.hasSparseLibraries() && (a instanceof HashPointMatrix || a instanceof CSCMatrix)) {
var csc = CSCMatrix.of(a);
double[] f = new double[csc.rows];
f[idx] = d;
double[] b = new double[csc.rows];
Julia.umfSolve(csc.rows, csc.columnPointers, csc.rowIndices, csc.values, f, b);
return b;
}
var A = MatrixConverter.dense(a);
var lu = A == a ? A.copy() : A;
double[] b = new double[A.rows()];
b[idx] = d;
int info = Julia.solve(A.columns(), 1, lu.data, b);
if (info > 0)
throw new SingularMatrixException();
if (info < 0)
throw new InsufficientDataException();
return b;
}
use of org.apache.commons.math3.linear.NonSquareMatrixException in project olca-modules by GreenDelta.
the class NativeSolver method invert.
@Override
public DenseMatrix invert(MatrixReader a) {
if (!a.isSquare())
throw new NonSquareMatrixException(a.rows(), a.columns());
DenseMatrix _a = MatrixConverter.dense(a);
DenseMatrix i = _a == a ? _a.copy() : _a;
int info = Julia.invert(_a.columns(), i.data);
if (info > 0)
throw new SingularMatrixException();
if (info < 0)
throw new InsufficientDataException();
return i;
}
use of org.apache.commons.math3.linear.NonSquareMatrixException in project olca-modules by GreenDelta.
the class NativeSolver method solve.
@Override
public double[] solve(MatrixReader a, int idx, double d) {
if (!a.isSquare())
throw new NonSquareMatrixException(a.rows(), a.columns());
if (hasSparseSupport() && (a instanceof HashPointMatrix || a instanceof CSCMatrix)) {
var csc = CSCMatrix.of(a);
double[] f = new double[csc.rows];
f[idx] = d;
double[] b = new double[csc.rows];
Julia.umfSolve(csc.rows, csc.columnPointers, csc.rowIndices, csc.values, f, b);
return b;
}
var A = MatrixConverter.dense(a);
var lu = A == a ? A.copy() : A;
double[] b = new double[A.rows()];
b[idx] = d;
int info = Julia.solve(A.columns(), 1, lu.data, b);
if (info > 0)
throw new SingularMatrixException();
if (info < 0)
throw new InsufficientDataException();
return b;
}
use of org.apache.commons.math3.linear.NonSquareMatrixException in project olca-modules by GreenDelta.
the class JuliaSolver method invert.
@Override
public DenseMatrix invert(MatrixReader a) {
if (!a.isSquare())
throw new NonSquareMatrixException(a.rows(), a.columns());
DenseMatrix _a = MatrixConverter.dense(a);
DenseMatrix i = _a == a ? _a.copy() : _a;
int info = Julia.invert(_a.columns(), i.data);
if (info > 0)
throw new SingularMatrixException();
if (info < 0)
throw new InsufficientDataException();
return i;
}
Aggregations