[BAEL-2996] Added Colt library example
This commit is contained in:
parent
7d71c3ac94
commit
4b14001cb3
@ -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>colt</groupId>
|
||||||
|
<artifactId>colt</artifactId>
|
||||||
|
<version>${colt.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@ -115,5 +120,6 @@
|
|||||||
<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.37.1</ejml.version>
|
||||||
|
<colt.version>1.2.0</colt.version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
package com.baeldung.colt;
|
||||||
|
|
||||||
|
import cern.colt.matrix.DoubleFactory2D;
|
||||||
|
import cern.colt.matrix.DoubleMatrix2D;
|
||||||
|
import cern.colt.matrix.linalg.Algebra;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
class DoubleMatrix2DUniTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() {
|
||||||
|
DoubleFactory2D doubleFactory2D = DoubleFactory2D.dense;
|
||||||
|
|
||||||
|
DoubleMatrix2D firstMatrix = doubleFactory2D.make(
|
||||||
|
new double[][] {
|
||||||
|
new double[] {1d, 5d},
|
||||||
|
new double[] {2d, 3d},
|
||||||
|
new double[] {1d ,7d}
|
||||||
|
});
|
||||||
|
|
||||||
|
DoubleMatrix2D secondMatrix = doubleFactory2D.make(
|
||||||
|
new double[][] {
|
||||||
|
new double[] {1d, 2d, 3d, 7d},
|
||||||
|
new double[] {5d, 2d, 8d, 1d}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
DoubleMatrix2D expected = doubleFactory2D.make(
|
||||||
|
new double[][] {
|
||||||
|
new double[] {26d, 12d, 43d, 12d},
|
||||||
|
new double[] {17d, 10d, 30d, 17d},
|
||||||
|
new double[] {36d, 16d, 59d, 14d}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
Algebra algebra = new Algebra();
|
||||||
|
DoubleMatrix2D actual = algebra.mult(firstMatrix, secondMatrix);
|
||||||
|
|
||||||
|
assertThat(actual).isEqualTo(expected);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user