[BAEL-2996] Added ND4J dependency and matrices multiplication test
This commit is contained in:
parent
8a8f880d33
commit
e885264b5f
|
@ -54,6 +54,11 @@
|
||||||
<groupId>org.ejml</groupId>
|
<groupId>org.ejml</groupId>
|
||||||
<artifactId>ejml-all</artifactId>
|
<artifactId>ejml-all</artifactId>
|
||||||
<version>${ejml.version}</version>
|
<version>${ejml.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.nd4j</groupId>
|
||||||
|
<artifactId>nd4j-native</artifactId>
|
||||||
|
<version>${nd4j.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>colt</groupId>
|
<groupId>colt</groupId>
|
||||||
|
@ -124,7 +129,8 @@
|
||||||
<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>
|
<ejml.version>0.38</ejml.version>
|
||||||
|
<nd4j.version>1.0.0-beta4</nd4j.version>
|
||||||
<colt.version>1.2.0</colt.version>
|
<colt.version>1.2.0</colt.version>
|
||||||
<la4j.version>0.6.0</la4j.version>
|
<la4j.version>0.6.0</la4j.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.baeldung.nd4j;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.nd4j.linalg.api.ndarray.INDArray;
|
||||||
|
import org.nd4j.linalg.factory.Nd4j;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
class INDArrayUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() {
|
||||||
|
INDArray firstMatrix = Nd4j.create(
|
||||||
|
new double[][]{
|
||||||
|
new double[]{1d, 5d},
|
||||||
|
new double[]{2d, 3d},
|
||||||
|
new double[]{1d, 7d}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
INDArray secondMatrix = Nd4j.create(
|
||||||
|
new double[][] {
|
||||||
|
new double[] {1d, 2d, 3d, 7d},
|
||||||
|
new double[] {5d, 2d, 8d, 1d}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
INDArray expected = Nd4j.create(
|
||||||
|
new double[][] {
|
||||||
|
new double[] {26d, 12d, 43d, 12d},
|
||||||
|
new double[] {17d, 10d, 30d, 17d},
|
||||||
|
new double[] {36d, 16d, 59d, 14d}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
INDArray actual = firstMatrix.mmul(secondMatrix);
|
||||||
|
|
||||||
|
assertThat(actual).isEqualTo(expected);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue