diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDAlgebra.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDAlgebra.kt index 28eaef2f1..03c601717 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDAlgebra.kt @@ -4,6 +4,7 @@ import kscience.kmath.operations.Complex import kscience.kmath.operations.Field import kscience.kmath.operations.Ring import kscience.kmath.operations.Space +import kotlin.native.concurrent.ThreadLocal /** * An exception is thrown when the expected ans actual shape of NDArray differs @@ -115,6 +116,7 @@ public interface NDField, N : NDStructure> : Field, NDRing public operator fun T.div(arg: N): N = map(arg) { divide(it, this@div) } + @ThreadLocal public companion object { private val realNDFieldCache: MutableMap = hashMapOf() diff --git a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt b/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt index 4ab49c9bc..fd679d073 100644 --- a/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt +++ b/kmath-core/src/commonMain/kotlin/kscience/kmath/structures/NDStructure.kt @@ -1,6 +1,7 @@ package kscience.kmath.structures import kotlin.jvm.JvmName +import kotlin.native.concurrent.ThreadLocal import kotlin.reflect.KClass /** @@ -230,6 +231,7 @@ public class DefaultStrides private constructor(override val shape: IntArray) : override fun hashCode(): Int = shape.contentHashCode() + @ThreadLocal public companion object { private val defaultStridesCache = HashMap() diff --git a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/ComplexTest.kt b/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/ComplexTest.kt index f8b9b7262..456e41467 100644 --- a/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/ComplexTest.kt +++ b/kmath-core/src/commonTest/kotlin/kscience/kmath/operations/ComplexTest.kt @@ -2,6 +2,7 @@ package kscience.kmath.operations import kotlin.test.Test import kotlin.test.assertEquals +import kotlin.test.assertTrue internal class ComplexTest { @Test @@ -13,7 +14,7 @@ internal class ComplexTest { @Test fun reciprocal() { - assertEquals(Complex(0.5, -0.0), 2.toComplex().reciprocal) + assertTrue { (Complex(0.5, -0.0) - 2.toComplex().reciprocal).r < 1e-10} } @Test