From 0baec140593ceaf32eeef23d0969d64807ba062e Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 23 Jan 2021 21:50:48 +0300 Subject: [PATCH] [WIP] Refactor NDStructures --- .../commonMain/kotlin/kscience/kmath/nd/BufferNDAlgebra.kt | 2 +- .../src/commonMain/kotlin/kscience/kmath/nd/NDStructure.kt | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/nd/BufferNDAlgebra.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/nd/BufferNDAlgebra.kt index cc1764643..c07726ad6 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/nd/BufferNDAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/kscience/kmath/nd/BufferNDAlgebra.kt @@ -50,7 +50,7 @@ public interface BufferNDAlgebra : NDAlgebra { val aBuffer = a.ndBuffer val bBuffer = b.ndBuffer val buffer = bufferFactory(strides.linearSize) { offset -> - elementContext.transform(aBuffer.buffer[offset], bBuffer[offset]) + elementContext.transform(aBuffer.buffer[offset], bBuffer.buffer[offset]) } return NDBuffer(strides, buffer) } diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/nd/NDStructure.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/nd/NDStructure.kt index 09c6fa198..4aa1c7d52 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/nd/NDStructure.kt +++ b/kmath-core/src/commonMain/kotlin/kscience/kmath/nd/NDStructure.kt @@ -217,9 +217,7 @@ public class DefaultStrides private constructor(override val shape: IntArray) : } override fun offset(index: IntArray): Int = index.mapIndexed { i, value -> - if (value < 0 || value >= shape[i]) - throw IndexOutOfBoundsException("Index $value out of shape bounds: (0,${this.shape[i]})") - + if (value < 0 || value >= shape[i]) throw IndexOutOfBoundsException("Index $value out of shape bounds: (0,${this.shape[i]})") value * strides[i] }.sum() @@ -332,7 +330,7 @@ public inline fun NDStructure.mapToBuffer( public class MutableNDBuffer( strides: Strides, buffer: MutableBuffer, -) : NDBuffer(strides,buffer), MutableNDStructure { +) : NDBuffer(strides, buffer), MutableNDStructure { init { require(strides.linearSize == buffer.size) {