Fix caches on native

This commit is contained in:
Alexander Nozik 2020-09-27 11:43:03 +03:00
parent 7d315e37d1
commit 0a71c7196d
3 changed files with 6 additions and 1 deletions

View File

@ -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<T, F : Field<T>, N : NDStructure<T>> : Field<N>, NDRing
public operator fun T.div(arg: N): N = map(arg) { divide(it, this@div) }
@ThreadLocal
public companion object {
private val realNDFieldCache: MutableMap<IntArray, RealNDField> = hashMapOf()

View File

@ -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<IntArray, Strides>()

View File

@ -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