Merge remote-tracking branch 'upstream/master' into BAEL-2981
# Conflicts: # libraries-2/pom.xml
This commit is contained in:
@@ -1,113 +1,156 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>libraries2</artifactId>
|
||||
<name>libraries2</name>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>libraries2</artifactId>
|
||||
<name>libraries2</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jboss-public-repository-group</id>
|
||||
<name>JBoss Public Repository Group</name>
|
||||
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>never</updatePolicy>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>daily</updatePolicy>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jboss-public-repository-group</id>
|
||||
<name>JBoss Public Repository Group</name>
|
||||
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>never</updatePolicy>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>daily</updatePolicy>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.classgraph</groupId>
|
||||
<artifactId>classgraph</artifactId>
|
||||
<version>${classgraph.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jbpm</groupId>
|
||||
<artifactId>jbpm-test</artifactId>
|
||||
<version>${jbpm.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>info.picocli</groupId>
|
||||
<artifactId>picocli</artifactId>
|
||||
<version>${picocli.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<groupId>org.ejml</groupId>
|
||||
<artifactId>ejml-all</artifactId>
|
||||
<version>${ejml.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.nd4j</groupId>
|
||||
<artifactId>nd4j-native</artifactId>
|
||||
<version>${nd4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.la4j</groupId>
|
||||
<artifactId>la4j</artifactId>
|
||||
<version>${la4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.classgraph</groupId>
|
||||
<artifactId>classgraph</artifactId>
|
||||
<version>${classgraph.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jbpm</groupId>
|
||||
<artifactId>jbpm-test</artifactId>
|
||||
<version>${jbpm.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>info.picocli</groupId>
|
||||
<artifactId>picocli</artifactId>
|
||||
<version>${picocli.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<version>${spring-boot-starter.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.openhft</groupId>
|
||||
<artifactId>chronicle-map</artifactId>
|
||||
<version>${chronicle.map.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.sun.java</groupId>
|
||||
<artifactId>tools</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<groupId>colt</groupId>
|
||||
<artifactId>colt</artifactId>
|
||||
<version>${colt.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<version>${spring-boot-starter.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.openhft</groupId>
|
||||
<artifactId>chronicle-map</artifactId>
|
||||
<version>${chronicle.map.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.sun.java</groupId>
|
||||
<artifactId>tools</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- Dependencies for response decoder with okhttp -->
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>3.14.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.9.9</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>mockwebserver</artifactId>
|
||||
<version>3.14.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Dependencies for response decoder with okhttp -->
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>3.14.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.9.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>mockwebserver</artifactId>
|
||||
<version>3.14.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>edu.uci.ics</groupId>
|
||||
<artifactId>crawler4j</artifactId>
|
||||
<version>${crawler4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.jknack</groupId>
|
||||
<artifactId>handlebars</artifactId>
|
||||
<version>4.1.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependency>
|
||||
|
||||
<properties>
|
||||
<assertj.version>3.6.2</assertj.version>
|
||||
<classgraph.version>4.8.28</classgraph.version>
|
||||
<jbpm.version>6.0.0.Final</jbpm.version>
|
||||
<picocli.version>3.9.6</picocli.version>
|
||||
<chronicle.map.version>3.17.2</chronicle.map.version>
|
||||
<dependency>
|
||||
<groupId>com.github.jknack</groupId>
|
||||
<artifactId>handlebars</artifactId>
|
||||
<version>4.1.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Benchmarking -->
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<assertj.version>3.6.2</assertj.version>
|
||||
<classgraph.version>4.8.28</classgraph.version>
|
||||
<jbpm.version>6.0.0.Final</jbpm.version>
|
||||
<picocli.version>3.9.6</picocli.version>
|
||||
<chronicle.map.version>3.17.2</chronicle.map.version>
|
||||
<crawler4j.version>4.4.0</crawler4j.version>
|
||||
<spring-boot-starter.version>2.1.4.RELEASE</spring-boot-starter.version>
|
||||
</properties>
|
||||
<spring-boot-starter.version>2.1.4.RELEASE</spring-boot-starter.version>
|
||||
<ejml.version>0.38</ejml.version>
|
||||
<nd4j.version>1.0.0-beta4</nd4j.version>
|
||||
<colt.version>1.2.0</colt.version>
|
||||
<la4j.version>0.6.0</la4j.version>
|
||||
<jmh.version>1.19</jmh.version>
|
||||
</properties>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.baeldung.matrices;
|
||||
|
||||
public class MatrixMultiplicationBenchmarking {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
org.openjdk.jmh.Main.main(args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.baeldung.matrices.apache;
|
||||
|
||||
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
|
||||
import org.apache.commons.math3.linear.RealMatrix;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@Fork(value = 2)
|
||||
@Warmup(iterations = 5)
|
||||
@Measurement(iterations = 10)
|
||||
public class RealMatrixUnitTest {
|
||||
|
||||
@Test
|
||||
@Benchmark
|
||||
public void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() {
|
||||
RealMatrix firstMatrix = new Array2DRowRealMatrix(
|
||||
new double[][] {
|
||||
new double[] {1d, 5d},
|
||||
new double[] {2d, 3d},
|
||||
new double[] {1d ,7d}
|
||||
}
|
||||
);
|
||||
|
||||
RealMatrix secondMatrix = new Array2DRowRealMatrix(
|
||||
new double[][] {
|
||||
new double[] {1d, 2d, 3d, 7d},
|
||||
new double[] {5d, 2d, 8d, 1d}
|
||||
}
|
||||
);
|
||||
|
||||
RealMatrix expected = new Array2DRowRealMatrix(
|
||||
new double[][] {
|
||||
new double[] {26d, 12d, 43d, 12d},
|
||||
new double[] {17d, 10d, 30d, 17d},
|
||||
new double[] {36d, 16d, 59d, 14d}
|
||||
}
|
||||
);
|
||||
|
||||
RealMatrix actual = firstMatrix.multiply(secondMatrix);
|
||||
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.baeldung.matrices.colt;
|
||||
|
||||
import cern.colt.matrix.DoubleFactory2D;
|
||||
import cern.colt.matrix.DoubleMatrix2D;
|
||||
import cern.colt.matrix.linalg.Algebra;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@Fork(value = 2)
|
||||
@Warmup(iterations = 5)
|
||||
@Measurement(iterations = 10)
|
||||
public class DoubleMatrix2DUnitTest {
|
||||
|
||||
@Test
|
||||
@Benchmark
|
||||
public 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.baeldung.matrices.ejml;
|
||||
|
||||
import org.ejml.simple.SimpleMatrix;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@Fork(value = 2)
|
||||
@Warmup(iterations = 5)
|
||||
@Measurement(iterations = 10)
|
||||
public class SimpleMatrixUnitTest {
|
||||
|
||||
@Test
|
||||
@Benchmark
|
||||
public 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).matches(m -> m.isIdentical(expected, 0d));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.baeldung.matrices.homemade;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@Fork(value = 2)
|
||||
@Warmup(iterations = 5)
|
||||
@Measurement(iterations = 10)
|
||||
public class HomemadeMatrixUnitTest {
|
||||
|
||||
@Test
|
||||
@Benchmark
|
||||
public void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() {
|
||||
double[][] firstMatrix = {
|
||||
new double[]{1d, 5d},
|
||||
new double[]{2d, 3d},
|
||||
new double[]{1d, 7d}
|
||||
};
|
||||
|
||||
double[][] secondMatrix = {
|
||||
new double[]{1d, 2d, 3d, 7d},
|
||||
new double[]{5d, 2d, 8d, 1d}
|
||||
};
|
||||
|
||||
double[][] expected = {
|
||||
new double[]{26d, 12d, 43d, 12d},
|
||||
new double[]{17d, 10d, 30d, 17d},
|
||||
new double[]{36d, 16d, 59d, 14d}
|
||||
};
|
||||
|
||||
double[][] actual = multiplyMatrices(firstMatrix, secondMatrix);
|
||||
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
}
|
||||
|
||||
private double[][] multiplyMatrices(double[][] firstMatrix, double[][] secondMatrix) {
|
||||
double[][] result = new double[firstMatrix.length][secondMatrix[0].length];
|
||||
|
||||
for (int row = 0; row < result.length; row++) {
|
||||
for (int col = 0; col < result[row].length; col++) {
|
||||
result[row][col] = multiplyMatricesCell(firstMatrix, secondMatrix, row, col);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private double multiplyMatricesCell(double[][] firstMatrix, double[][] secondMatrix, int row, int col) {
|
||||
double cell = 0;
|
||||
for (int i = 0; i < secondMatrix.length; i++) {
|
||||
cell += firstMatrix[row][i] * secondMatrix[i][col];
|
||||
}
|
||||
return cell;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.baeldung.matrices.la4j;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.la4j.Matrix;
|
||||
import org.la4j.matrix.dense.Basic2DMatrix;
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@Fork(value = 2)
|
||||
@Warmup(iterations = 5)
|
||||
@Measurement(iterations = 10)
|
||||
public class Basic2DMatrixUnitTest {
|
||||
|
||||
@Test
|
||||
@Benchmark
|
||||
public 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.baeldung.matrices.nd4j;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.nd4j.linalg.api.ndarray.INDArray;
|
||||
import org.nd4j.linalg.factory.Nd4j;
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@Fork(value = 2)
|
||||
@Warmup(iterations = 5)
|
||||
@Measurement(iterations = 10)
|
||||
public class INDArrayUnitTest {
|
||||
|
||||
@Test
|
||||
public 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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user