altavir/diff #494
@ -4,6 +4,8 @@
|
||||
### Added
|
||||
|
||||
### Changed
|
||||
- Kotlin 1.7
|
||||
- `LazyStructure` `deffered` -> `async` to comply with coroutines code style
|
||||
|
||||
### Deprecated
|
||||
|
||||
|
@ -11,7 +11,7 @@ allprojects {
|
||||
}
|
||||
|
||||
group = "space.kscience"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
}
|
||||
|
||||
subprojects {
|
||||
|
@ -1,4 +1,5 @@
|
||||
plugins {
|
||||
kotlin("jvm") version "1.7.0-RC"
|
||||
`kotlin-dsl`
|
||||
`version-catalog`
|
||||
alias(miptNpmLibs.plugins.kotlin.plugin.serialization)
|
||||
|
@ -4,4 +4,4 @@
|
||||
#
|
||||
|
||||
kotlin.code.style=official
|
||||
toolsVersion=0.11.2-kotlin-1.6.10
|
||||
toolsVersion=0.11.5-kotlin-1.7.0-RC
|
||||
|
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright 2018-2021 KMath contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package space.kscience.kmath.nd
|
||||
|
||||
public open class VirtualStructureND<T>(
|
||||
override val shape: Shape,
|
||||
public val producer: (IntArray) -> T,
|
||||
) : StructureND<T> {
|
||||
override fun get(index: IntArray): T {
|
||||
require(check that index is in the shape boundaries)
|
||||
return producer(index)
|
||||
}
|
||||
}
|
@ -18,12 +18,12 @@ public class LazyStructureND<out T>(
|
||||
) : StructureND<T> {
|
||||
private val cache: MutableMap<IntArray, Deferred<T>> = HashMap()
|
||||
|
||||
public fun deferred(index: IntArray): Deferred<T> = cache.getOrPut(index) {
|
||||
public fun async(index: IntArray): Deferred<T> = cache.getOrPut(index) {
|
||||
scope.async(context = Dispatchers.Math) { function(index) }
|
||||
}
|
||||
|
||||
public suspend fun await(index: IntArray): T = deferred(index).await()
|
||||
override operator fun get(index: IntArray): T = runBlocking { deferred(index).await() }
|
||||
public suspend fun await(index: IntArray): T = async(index).await()
|
||||
override operator fun get(index: IntArray): T = runBlocking { async(index).await() }
|
||||
|
||||
@OptIn(PerformancePitfall::class)
|
||||
override fun elements(): Sequence<Pair<IntArray, T>> {
|
||||
@ -33,8 +33,8 @@ public class LazyStructureND<out T>(
|
||||
}
|
||||
}
|
||||
|
||||
public fun <T> StructureND<T>.deferred(index: IntArray): Deferred<T> =
|
||||
if (this is LazyStructureND<T>) deferred(index) else CompletableDeferred(get(index))
|
||||
public fun <T> StructureND<T>.async(index: IntArray): Deferred<T> =
|
||||
if (this is LazyStructureND<T>) this@async.async(index) else CompletableDeferred(get(index))
|
||||
|
||||
public suspend fun <T> StructureND<T>.await(index: IntArray): T =
|
||||
if (this is LazyStructureND<T>) await(index) else get(index)
|
||||
|
Loading…
Reference in New Issue
Block a user