forked from kscience/kmath
Fix caches on native
This commit is contained in:
parent
7d315e37d1
commit
0a71c7196d
@ -4,6 +4,7 @@ import kscience.kmath.operations.Complex
|
|||||||
import kscience.kmath.operations.Field
|
import kscience.kmath.operations.Field
|
||||||
import kscience.kmath.operations.Ring
|
import kscience.kmath.operations.Ring
|
||||||
import kscience.kmath.operations.Space
|
import kscience.kmath.operations.Space
|
||||||
|
import kotlin.native.concurrent.ThreadLocal
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An exception is thrown when the expected ans actual shape of NDArray differs
|
* 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) }
|
public operator fun T.div(arg: N): N = map(arg) { divide(it, this@div) }
|
||||||
|
|
||||||
|
@ThreadLocal
|
||||||
public companion object {
|
public companion object {
|
||||||
private val realNDFieldCache: MutableMap<IntArray, RealNDField> = hashMapOf()
|
private val realNDFieldCache: MutableMap<IntArray, RealNDField> = hashMapOf()
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package kscience.kmath.structures
|
package kscience.kmath.structures
|
||||||
|
|
||||||
import kotlin.jvm.JvmName
|
import kotlin.jvm.JvmName
|
||||||
|
import kotlin.native.concurrent.ThreadLocal
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -230,6 +231,7 @@ public class DefaultStrides private constructor(override val shape: IntArray) :
|
|||||||
|
|
||||||
override fun hashCode(): Int = shape.contentHashCode()
|
override fun hashCode(): Int = shape.contentHashCode()
|
||||||
|
|
||||||
|
@ThreadLocal
|
||||||
public companion object {
|
public companion object {
|
||||||
private val defaultStridesCache = HashMap<IntArray, Strides>()
|
private val defaultStridesCache = HashMap<IntArray, Strides>()
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package kscience.kmath.operations
|
|||||||
|
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
internal class ComplexTest {
|
internal class ComplexTest {
|
||||||
@Test
|
@Test
|
||||||
@ -13,7 +14,7 @@ internal class ComplexTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun reciprocal() {
|
fun reciprocal() {
|
||||||
assertEquals(Complex(0.5, -0.0), 2.toComplex().reciprocal)
|
assertTrue { (Complex(0.5, -0.0) - 2.toComplex().reciprocal).r < 1e-10}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user