added matrix benchmark
This commit is contained in:
18
jmath-benchmark/build.gradle
Normal file
18
jmath-benchmark/build.gradle
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
plugins {
|
||||||
|
id 'java-library'
|
||||||
|
alias(catalog.plugins.lombok)
|
||||||
|
alias(catalog.plugins.envelope)
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation project(':jmath')
|
||||||
|
}
|
||||||
|
|
||||||
|
envelopeJar {
|
||||||
|
mainClass = 'net.woggioni.jmath.benchmark.Main'
|
||||||
|
}
|
||||||
|
|
@@ -0,0 +1,33 @@
|
|||||||
|
package net.woggioni.jmath.benchmark;
|
||||||
|
|
||||||
|
import net.woggioni.jmath.Matrix;
|
||||||
|
import net.woggioni.jmath.NumericTypeFactory;
|
||||||
|
import net.woggioni.jmath.Rational;
|
||||||
|
import net.woggioni.jmath.RationalFactory;
|
||||||
|
import net.woggioni.jmath.Vector;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.function.IntFunction;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int size = Optional.of(args)
|
||||||
|
.filter(it -> it.length > 0)
|
||||||
|
.map(it -> it[0])
|
||||||
|
.map(Integer::parseInt)
|
||||||
|
.orElse(3);
|
||||||
|
Random rnd = new Random(101325);
|
||||||
|
NumericTypeFactory<Rational> numericTypeFactory = RationalFactory.getInstance();
|
||||||
|
Matrix.ValueGenerator<Rational> init = (i, j) ->
|
||||||
|
Rational.of(rnd.nextInt(-1000 * size, 1000 * size), (long) 1000 * size);
|
||||||
|
Matrix<Rational> mtx = Matrix.of(numericTypeFactory, size, size, init);
|
||||||
|
Matrix<Rational> lu = mtx.clone();
|
||||||
|
Matrix.Pivot pivot = lu.lup();
|
||||||
|
IntFunction<Rational> initVector = (i) -> Rational.of(rnd.nextInt(0, size), size);
|
||||||
|
Vector<Rational> b = Vector.of(numericTypeFactory, size, initVector);
|
||||||
|
Vector<Rational> x = lu.luSolve(b, pivot);
|
||||||
|
Vector<Rational> error = mtx.mmul(x).sub(b);
|
||||||
|
System.out.println(error.norm());
|
||||||
|
}
|
||||||
|
}
|
@@ -32,3 +32,4 @@ rootProject.name = 'jwo'
|
|||||||
|
|
||||||
include('benchmark')
|
include('benchmark')
|
||||||
include('jmath')
|
include('jmath')
|
||||||
|
include('jmath-benchmark')
|
||||||
|
Reference in New Issue
Block a user