[BAEL-2996] Added ND4J dependency and matrices multiplication test

This commit is contained in:
dupirefr
2019-06-16 15:58:30 +02:00
parent 8a8f880d33
commit e885264b5f
2 changed files with 47 additions and 1 deletions

View File

@@ -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);
}
}