From a384b323c3cc0002fb9b9475c8688353313c153f Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Thu, 11 Feb 2021 11:17:44 +0300 Subject: [PATCH] Update examples to use `with` instead of `invoke` on algebras --- .../kscience/kmath/benchmarks/LinearAlgebraBenchmark.kt | 5 ++--- .../kotlin/kscience/kmath/benchmarks/NDFieldBenchmark.kt | 7 +++---- .../kotlin/kscience/kmath/benchmarks/ViktorBenchmark.kt | 7 +++---- .../kotlin/kscience/kmath/benchmarks/ViktorLogBenchmark.kt | 5 ++--- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/LinearAlgebraBenchmark.kt b/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/LinearAlgebraBenchmark.kt index b54cff926..2ebfee2e7 100644 --- a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/LinearAlgebraBenchmark.kt +++ b/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/LinearAlgebraBenchmark.kt @@ -10,7 +10,6 @@ import kscience.kmath.linear.Matrix import kscience.kmath.linear.MatrixContext import kscience.kmath.linear.inverseWithLup import kscience.kmath.linear.real -import kscience.kmath.operations.invoke import org.openjdk.jmh.annotations.Scope import org.openjdk.jmh.annotations.State import kotlin.random.Random @@ -34,14 +33,14 @@ internal class LinearAlgebraBenchmark { @Benchmark fun cmLUPInversion() { - CMMatrixContext { + with(CMMatrixContext) { inverse(matrix) } } @Benchmark fun ejmlInverse() { - EjmlMatrixContext { + with(EjmlMatrixContext) { inverse(matrix) } } diff --git a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/NDFieldBenchmark.kt b/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/NDFieldBenchmark.kt index 5f7559d02..caebf0497 100644 --- a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/NDFieldBenchmark.kt +++ b/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/NDFieldBenchmark.kt @@ -2,7 +2,6 @@ package kscience.kmath.benchmarks import kscience.kmath.nd.* import kscience.kmath.operations.RealField -import kscience.kmath.operations.invoke import kscience.kmath.structures.Buffer import org.openjdk.jmh.annotations.Benchmark import org.openjdk.jmh.annotations.Scope @@ -12,7 +11,7 @@ import org.openjdk.jmh.annotations.State internal class NDFieldBenchmark { @Benchmark fun autoFieldAdd() { - autoField { + with(autoField) { var res: NDStructure = one repeat(n) { res += one } } @@ -20,7 +19,7 @@ internal class NDFieldBenchmark { @Benchmark fun specializedFieldAdd() { - specializedField { + with(specializedField) { var res: NDStructure = one repeat(n) { res += 1.0 } } @@ -29,7 +28,7 @@ internal class NDFieldBenchmark { @Benchmark fun boxingFieldAdd() { - genericField { + with(genericField) { var res: NDStructure = one repeat(n) { res += 1.0 } } diff --git a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/ViktorBenchmark.kt b/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/ViktorBenchmark.kt index 5cf6c2ab8..3f08481b3 100644 --- a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/ViktorBenchmark.kt +++ b/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/ViktorBenchmark.kt @@ -2,7 +2,6 @@ package kscience.kmath.benchmarks import kscience.kmath.nd.* import kscience.kmath.operations.RealField -import kscience.kmath.operations.invoke import kscience.kmath.viktor.ViktorNDField import org.jetbrains.bio.viktor.F64Array import org.openjdk.jmh.annotations.Benchmark @@ -21,7 +20,7 @@ internal class ViktorBenchmark { @Benchmark fun automaticFieldAddition() { - autoField { + with(autoField) { var res: NDStructure = one repeat(n) { res += 1.0 } } @@ -29,7 +28,7 @@ internal class ViktorBenchmark { @Benchmark fun realFieldAddition() { - realField { + with(realField) { var res: NDStructure = one repeat(n) { res += 1.0 } } @@ -37,7 +36,7 @@ internal class ViktorBenchmark { @Benchmark fun viktorFieldAddition() { - viktorField { + with(viktorField) { var res = one repeat(n) { res += 1.0 } } diff --git a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/ViktorLogBenchmark.kt b/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/ViktorLogBenchmark.kt index 914584b8e..57f556e9e 100644 --- a/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/ViktorLogBenchmark.kt +++ b/examples/src/benchmarks/kotlin/kscience/kmath/benchmarks/ViktorLogBenchmark.kt @@ -2,7 +2,6 @@ package kscience.kmath.benchmarks import kscience.kmath.nd.* import kscience.kmath.operations.RealField -import kscience.kmath.operations.invoke import kscience.kmath.viktor.ViktorNDField import org.jetbrains.bio.viktor.F64Array import org.openjdk.jmh.annotations.Benchmark @@ -22,7 +21,7 @@ internal class ViktorLogBenchmark { @Benchmark fun realFieldLog() { - realField { + with(realField) { val fortyTwo = produce { 42.0 } var res = one repeat(n) { res = ln(fortyTwo) } @@ -31,7 +30,7 @@ internal class ViktorLogBenchmark { @Benchmark fun viktorFieldLog() { - viktorField { + with(viktorField) { val fortyTwo = produce { 42.0 } var res = one repeat(n) { res = ln(fortyTwo) }