From 5ec4c8690c4e1ab752368c3b3887f7cb1ab003e3 Mon Sep 17 00:00:00 2001 From: Burkhard Mittelbach Date: Tue, 1 May 2018 17:12:19 +0200 Subject: [PATCH 1/2] Added test for generating realNDArrays Signed-off-by: Burkhard Mittelbach --- .../scientifik/kmath/structures/RealNDFieldTest.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/jvm/src/test/kotlin/scientifik/kmath/structures/RealNDFieldTest.kt b/jvm/src/test/kotlin/scientifik/kmath/structures/RealNDFieldTest.kt index 90af41a71..85737ba2a 100644 --- a/jvm/src/test/kotlin/scientifik/kmath/structures/RealNDFieldTest.kt +++ b/jvm/src/test/kotlin/scientifik/kmath/structures/RealNDFieldTest.kt @@ -18,4 +18,17 @@ class RealNDFieldTest { val product = array1*array2 assertEquals(0.0, product[2, 2].toDouble(), 0.1) } + + @Test + fun testGeneration() { + + val array = real2DArray(3, 3) { i, j -> (i * 10 + j).toDouble() } + + for(i in 0..2){ + for(j in 0..2){ + val expected= (i * 10 + j).toDouble() + assertEquals("Error at index [$i, $j]", expected, array[i,j].value) + } + } + } } \ No newline at end of file -- 2.34.1 From da037aa879264e961943ddeb99df339462f518c4 Mon Sep 17 00:00:00 2001 From: Burkhard Mittelbach Date: Tue, 1 May 2018 17:41:42 +0200 Subject: [PATCH 2/2] Fixed stride for RealNDArray Signed-off-by: Burkhard Mittelbach --- jvm/src/main/kotlin/scientifik/kmath/structures/RealNDArray.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jvm/src/main/kotlin/scientifik/kmath/structures/RealNDArray.kt b/jvm/src/main/kotlin/scientifik/kmath/structures/RealNDArray.kt index c25dcde07..4d16f493d 100644 --- a/jvm/src/main/kotlin/scientifik/kmath/structures/RealNDArray.kt +++ b/jvm/src/main/kotlin/scientifik/kmath/structures/RealNDArray.kt @@ -12,7 +12,7 @@ private class RealNDField(shape: List) : NDField(shape, RealField) { private val strides: List by lazy { ArrayList(shape.size).apply { var current = 1 - add(0) + add(1) shape.forEach { current *= it add(current) -- 2.34.1