[BAEL-2996] Added ejml example
This commit is contained in:
parent
ddc85d20b9
commit
7d71c3ac94
|
@ -50,6 +50,11 @@
|
||||||
<artifactId>picocli</artifactId>
|
<artifactId>picocli</artifactId>
|
||||||
<version>${picocli.version}</version>
|
<version>${picocli.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.ejml</groupId>
|
||||||
|
<artifactId>ejml-all</artifactId>
|
||||||
|
<version>${ejml.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter</artifactId>
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
|
@ -109,5 +114,6 @@
|
||||||
<chronicle.map.version>3.17.2</chronicle.map.version>
|
<chronicle.map.version>3.17.2</chronicle.map.version>
|
||||||
<crawler4j.version>4.4.0</crawler4j.version>
|
<crawler4j.version>4.4.0</crawler4j.version>
|
||||||
<spring-boot-starter.version>2.1.4.RELEASE</spring-boot-starter.version>
|
<spring-boot-starter.version>2.1.4.RELEASE</spring-boot-starter.version>
|
||||||
|
<ejml.version>0.37.1</ejml.version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
package com.baeldung.ejml;
|
||||||
|
|
||||||
|
import org.ejml.simple.SimpleMatrix;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
class SimpleMatrixUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() {
|
||||||
|
SimpleMatrix firstMatrix = new SimpleMatrix(
|
||||||
|
new double[][] {
|
||||||
|
new double[] {1d, 5d},
|
||||||
|
new double[] {2d, 3d},
|
||||||
|
new double[] {1d ,7d}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
SimpleMatrix secondMatrix = new SimpleMatrix(
|
||||||
|
new double[][] {
|
||||||
|
new double[] {1d, 2d, 3d, 7d},
|
||||||
|
new double[] {5d, 2d, 8d, 1d}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
SimpleMatrix expected = new SimpleMatrix(
|
||||||
|
new double[][] {
|
||||||
|
new double[] {26d, 12d, 43d, 12d},
|
||||||
|
new double[] {17d, 10d, 30d, 17d},
|
||||||
|
new double[] {36d, 16d, 59d, 14d}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
SimpleMatrix actual = firstMatrix.mult(secondMatrix);
|
||||||
|
|
||||||
|
assertThat(actual.numRows()).isEqualTo(expected.numRows());
|
||||||
|
assertThat(actual.numCols()).isEqualTo(expected.numCols());
|
||||||
|
for (int row = 0; row < actual.numRows(); row++) {
|
||||||
|
for (int col = 0; col < actual.numCols(); col++) {
|
||||||
|
assertThat(actual.get(row, col))
|
||||||
|
.describedAs("Cells at [%d, %d] don't match", row, col)
|
||||||
|
.isEqualTo(expected.get(row, col));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue