use of org.openlca.core.matrix.format.DenseMatrix in project olca-modules by GreenDelta.
the class BlasTest method testSparseMatrixMatrixMult.
@Test
public void testSparseMatrixMatrixMult() {
// currently auto-conversion to a dense matrix
var a = HashPointMatrix.of(new double[][] { { 1, 2, 3 }, { 4, 5, 6 } });
var b = HashPointMatrix.of(new double[][] { { 7, 10 }, { 8, 11 }, { 9, 12 } });
JuliaSolver solver = new JuliaSolver();
DenseMatrix m = solver.multiply(a, b);
assertEquals(m.get(0, 0), 50, 1e-10);
}
use of org.openlca.core.matrix.format.DenseMatrix 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.openlca.core.matrix.format.DenseMatrix in project olca-modules by GreenDelta.
the class NpyTest method testLoad.
@Test
public void testLoad() {
DenseMatrix copy = (DenseMatrix) NpyMatrix.read(npy);
assertEquals(matrix.rows, copy.rows());
assertEquals(matrix.columns, copy.columns());
assertArrayEquals(matrix.data, copy.data, 1e-10);
}
use of org.openlca.core.matrix.format.DenseMatrix in project olca-modules by GreenDelta.
the class BlasTest method testSparseMatrixMatrixMult.
@Test
public void testSparseMatrixMatrixMult() {
// currently auto-conversion to a dense matrix
var a = HashPointMatrix.of(new double[][] { { 1, 2, 3 }, { 4, 5, 6 } });
var b = HashPointMatrix.of(new double[][] { { 7, 10 }, { 8, 11 }, { 9, 12 } });
var solver = new NativeSolver();
DenseMatrix m = solver.multiply(a, b);
assertEquals(m.get(0, 0), 50, 1e-10);
}
use of org.openlca.core.matrix.format.DenseMatrix in project olca-modules by GreenDelta.
the class NativeSolver method multiply.
@Override
public DenseMatrix multiply(MatrixReader a, MatrixReader b) {
DenseMatrix _a = MatrixConverter.dense(a);
DenseMatrix _b = MatrixConverter.dense(b);
int rowsA = _a.rows();
int colsB = _b.columns();
int k = _a.columns();
DenseMatrix c = new DenseMatrix(rowsA, colsB);
if (colsB == 1) {
Julia.mvmult(rowsA, k, _a.data, _b.data, c.data);
} else {
Julia.mmult(rowsA, colsB, k, _a.data, _b.data, c.data);
}
return c;
}
Aggregations