Search in sources :

Example 1 with DenseMatrix

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);
}
Also used : DenseMatrix(org.openlca.core.matrix.format.DenseMatrix) Test(org.junit.Test)

Example 2 with DenseMatrix

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;
}
Also used : SingularMatrixException(org.apache.commons.math3.linear.SingularMatrixException) InsufficientDataException(org.apache.commons.math3.exception.InsufficientDataException) NonSquareMatrixException(org.apache.commons.math3.linear.NonSquareMatrixException) DenseMatrix(org.openlca.core.matrix.format.DenseMatrix)

Example 3 with DenseMatrix

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);
}
Also used : DenseMatrix(org.openlca.core.matrix.format.DenseMatrix) Test(org.junit.Test)

Example 4 with DenseMatrix

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);
}
Also used : DenseMatrix(org.openlca.core.matrix.format.DenseMatrix) Test(org.junit.Test)

Example 5 with DenseMatrix

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;
}
Also used : DenseMatrix(org.openlca.core.matrix.format.DenseMatrix)

Aggregations

DenseMatrix (org.openlca.core.matrix.format.DenseMatrix)9 Test (org.junit.Test)4 InsufficientDataException (org.apache.commons.math3.exception.InsufficientDataException)2 NonSquareMatrixException (org.apache.commons.math3.linear.NonSquareMatrixException)2 SingularMatrixException (org.apache.commons.math3.linear.SingularMatrixException)2 Before (org.junit.Before)1 Matrix (org.openlca.core.matrix.format.Matrix)1