use of org.openlca.core.matrix.format.DenseMatrix in project olca-modules by GreenDelta.
the class SimpleBinTest method testMatrixIO.
@Test
public void testMatrixIO() throws Exception {
var f = Files.createTempFile("olcamat-", ".bin").toFile();
Matrix m = new DenseMatrix(2, 3);
m.setValues(new double[][] { { 1, 2, 3 }, { 4, 5, 6 } });
SimpleBin.write(m, f);
m = SimpleBin.read(f);
Assert.assertArrayEquals(new double[] { 1, 4 }, m.getColumn(0), 1e-16);
Assert.assertArrayEquals(new double[] { 2, 5 }, m.getColumn(1), 1e-16);
Assert.assertArrayEquals(new double[] { 3, 6 }, m.getColumn(2), 1e-16);
// Files.delete(f.toPath());
if (!f.delete()) {
f.deleteOnExit();
}
}
use of org.openlca.core.matrix.format.DenseMatrix in project olca-modules by GreenDelta.
the class NpyTest method setup.
@Before
public void setup() throws Exception {
matrix = new DenseMatrix(2, 3);
matrix.setValues(new double[][] { { 1., 2., 3. }, { 4., 5., 6. } });
var dir = Files.createTempDirectory("_olca_tests").toFile();
npy = NpyMatrix.write(dir, "M", matrix);
}
use of org.openlca.core.matrix.format.DenseMatrix in project olca-modules by GreenDelta.
the class JuliaSolver 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;
}
use of org.openlca.core.matrix.format.DenseMatrix 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