[BAEL-2996] Added la4j library example

This commit is contained in:
dupirefr 2019-06-08 22:19:02 +02:00
parent 4b14001cb3
commit 082aa7d0a6
3 changed files with 46 additions and 1 deletions

View File

@ -60,6 +60,11 @@
<artifactId>colt</artifactId>
<version>${colt.version}</version>
</dependency>
<dependency>
<groupId>org.la4j</groupId>
<artifactId>la4j</artifactId>
<version>${la4j.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
@ -121,5 +126,6 @@
<spring-boot-starter.version>2.1.4.RELEASE</spring-boot-starter.version>
<ejml.version>0.37.1</ejml.version>
<colt.version>1.2.0</colt.version>
<la4j.version>0.6.0</la4j.version>
</properties>
</project>

View File

@ -7,7 +7,7 @@ import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
class DoubleMatrix2DUniTest {
class DoubleMatrix2DUnitTest {
@Test
void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() {

View File

@ -0,0 +1,39 @@
package com.baeldung.la4j;
import org.junit.jupiter.api.Test;
import org.la4j.Matrix;
import org.la4j.matrix.dense.Basic2DMatrix;
import static org.assertj.core.api.Assertions.assertThat;
class Basic2DMatrixUnitTest {
@Test
void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() {
Matrix firstMatrix = new Basic2DMatrix(
new double[][]{
new double[]{1d, 5d},
new double[]{2d, 3d},
new double[]{1d, 7d}
});
Matrix secondMatrix = new Basic2DMatrix(
new double[][]{
new double[]{1d, 2d, 3d, 7d},
new double[]{5d, 2d, 8d, 1d}
}
);
Matrix expected = new Basic2DMatrix(
new double[][]{
new double[]{26d, 12d, 43d, 12d},
new double[]{17d, 10d, 30d, 17d},
new double[]{36d, 16d, 59d, 14d}
}
);
Matrix actual = firstMatrix.multiply(secondMatrix);
assertThat(actual).isEqualTo(expected);
}
}