From 9936b9e4b790bbe7a3a606d1375e8b18badb6c8e Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 9 Dec 2019 17:37:17 +0300 Subject: [PATCH] Viktor prototype with inline --- .../scientifik/kmath/structures/VictorTest.kt | 21 +++++++++++++++ .../kmath/viktor/ViktorNDStructure.kt | 26 ++++++++++--------- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/examples/src/main/kotlin/scientifik/kmath/structures/VictorTest.kt b/examples/src/main/kotlin/scientifik/kmath/structures/VictorTest.kt index 8d710c584..19469ca72 100644 --- a/examples/src/main/kotlin/scientifik/kmath/structures/VictorTest.kt +++ b/examples/src/main/kotlin/scientifik/kmath/structures/VictorTest.kt @@ -4,12 +4,14 @@ import org.jetbrains.bio.viktor.F64Array import scientifik.kmath.operations.RealField import scientifik.kmath.viktor.ViktorNDField + fun main() { val dim = 1000 val n = 400 // automatically build context most suited for given type. val autoField = NDField.auto(RealField, dim, dim) + val realField = NDField.real(dim,dim) val viktorField = ViktorNDField(intArrayOf(dim, dim)) @@ -52,4 +54,23 @@ fun main() { res = res + one } } + + measureAndPrint("Automatic field log") { + realField.run { + val fortyTwo = produce { 42.0 } + var res = one + + repeat(n) { + res = ln(fortyTwo) + } + } + } + + measureAndPrint("Raw Viktor log") { + val fortyTwo = F64Array.full(dim, dim, init = 42.0) + var res: F64Array + repeat(n) { + res = fortyTwo.log() + } + } } \ No newline at end of file diff --git a/kmath-viktor/src/main/kotlin/scientifik/kmath/viktor/ViktorNDStructure.kt b/kmath-viktor/src/main/kotlin/scientifik/kmath/viktor/ViktorNDStructure.kt index 9654ba283..84e927721 100644 --- a/kmath-viktor/src/main/kotlin/scientifik/kmath/viktor/ViktorNDStructure.kt +++ b/kmath-viktor/src/main/kotlin/scientifik/kmath/viktor/ViktorNDStructure.kt @@ -6,14 +6,15 @@ import scientifik.kmath.structures.DefaultStrides import scientifik.kmath.structures.MutableNDStructure import scientifik.kmath.structures.NDField +@Suppress("OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE") inline class ViktorNDStructure(val f64Buffer: F64Array) : MutableNDStructure { override val shape: IntArray get() = f64Buffer.shape - override fun get(index: IntArray): Double = f64Buffer.get(*index) + override inline fun get(index: IntArray): Double = f64Buffer.get(*index) - override fun set(index: IntArray, value: Double) { - f64Buffer.set(value = value, indices = *index) + override inline fun set(index: IntArray, value: Double) { + f64Buffer.set(*index, value = value) } override fun elements(): Sequence> { @@ -23,6 +24,7 @@ inline class ViktorNDStructure(val f64Buffer: F64Array) : MutableNDStructure { override val zero: ViktorNDStructure get() = F64Array.full(init = 0.0, shape = *shape).asStructure() @@ -69,16 +71,16 @@ class ViktorNDField(override val shape: IntArray) : NDField