MutableBufferFromGenerator

This commit is contained in:
Roland Grinis 2021-04-30 15:08:32 +01:00
parent 86c2816cfd
commit 42ddd2e569
4 changed files with 15 additions and 15 deletions

View File

@ -1882,6 +1882,15 @@ public final class space/kscience/kmath/structures/MutableBuffer$Companion {
public final fun short-1yRgbGw (ILkotlin/jvm/functions/Function1;)[S
}
public final class space/kscience/kmath/structures/MutableBufferFromGenerator : space/kscience/kmath/structures/MutableBuffer {
public fun <init> (ILkotlin/jvm/functions/Function1;)V
public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer;
public fun get (I)Ljava/lang/Object;
public fun getSize ()I
public fun iterator ()Ljava/util/Iterator;
public fun set (ILjava/lang/Object;)V
}
public final class space/kscience/kmath/structures/MutableListBuffer : space/kscience/kmath/structures/MutableBuffer {
public static final synthetic fun box-impl (Ljava/util/List;)Lspace/kscience/kmath/structures/MutableListBuffer;
public static fun constructor-impl (ILkotlin/jvm/functions/Function1;)Ljava/util/List;
@ -1990,12 +1999,3 @@ public final class space/kscience/kmath/structures/VirtualBuffer : space/kscienc
public fun iterator ()Ljava/util/Iterator;
}
public final class space/kscience/kmath/structures/VirtualMutableBuffer : space/kscience/kmath/structures/MutableBuffer {
public fun <init> (ILkotlin/jvm/functions/Function1;)V
public fun copy ()Lspace/kscience/kmath/structures/MutableBuffer;
public fun get (I)Ljava/lang/Object;
public fun getSize ()I
public fun iterator ()Ljava/util/Iterator;
public fun set (ILjava/lang/Object;)V
}

View File

@ -52,7 +52,7 @@ private value class Structure1DWrapper<T>(val structure: StructureND<T>) : Struc
/**
* A 1D wrapper for a mutable nd-structure
*/
private inline class MutableStructure1DWrapper<T>(val structure: MutableStructureND<T>) : MutableStructure1D<T> {
private class MutableStructure1DWrapper<T>(val structure: MutableStructureND<T>) : MutableStructure1D<T> {
override val shape: IntArray get() = structure.shape
override val size: Int get() = structure.shape[0]
override fun elements(): Sequence<Pair<IntArray, T>> = structure.elements()
@ -81,7 +81,7 @@ private value class Buffer1DWrapper<T>(val buffer: Buffer<T>) : Structure1D<T> {
override operator fun get(index: Int): T = buffer[index]
}
internal inline class MutableBuffer1DWrapper<T>(val buffer: MutableBuffer<T>) : MutableStructure1D<T> {
internal class MutableBuffer1DWrapper<T>(val buffer: MutableBuffer<T>) : MutableStructure1D<T> {
override val shape: IntArray get() = intArrayOf(buffer.size)
override val size: Int get() = buffer.size

View File

@ -8,7 +8,7 @@ package space.kscience.kmath.nd
import space.kscience.kmath.misc.UnstableKMathAPI
import space.kscience.kmath.structures.Buffer
import space.kscience.kmath.structures.VirtualBuffer
import space.kscience.kmath.structures.VirtualMutableBuffer
import space.kscience.kmath.structures.MutableBufferFromGenerator
import kotlin.jvm.JvmInline
import kotlin.reflect.KClass
@ -81,13 +81,13 @@ public interface MutableStructure2D<T> : Structure2D<T>, MutableStructureND<T> {
* The buffer of rows of this structure. It gets elements from the structure dynamically.
*/
override val rows: List<MutableStructure1D<T>>
get() = List(rowNum) { i -> MutableBuffer1DWrapper(VirtualMutableBuffer(colNum) { j -> get(i, j) })}
get() = List(rowNum) { i -> MutableBuffer1DWrapper(MutableBufferFromGenerator(colNum) { j -> get(i, j) })}
/**
* The buffer of columns of this structure. It gets elements from the structure dynamically.
*/
override val columns: List<MutableStructure1D<T>>
get() = List(colNum) { j -> MutableBuffer1DWrapper(VirtualMutableBuffer(rowNum) { i -> get(i, j) }) }
get() = List(colNum) { j -> MutableBuffer1DWrapper(MutableBufferFromGenerator(rowNum) { i -> get(i, j) }) }
}
/**

View File

@ -292,7 +292,7 @@ public class VirtualBuffer<T>(override val size: Int, private val generator: (In
override operator fun iterator(): Iterator<T> = (0 until size).asSequence().map(generator).iterator()
}
public class VirtualMutableBuffer<T>(override val size: Int, private val generator: (Int) -> T) : MutableBuffer<T> {
public class MutableBufferFromGenerator<T>(override val size: Int, private val generator: (Int) -> T) : MutableBuffer<T> {
private val bufferHolder: MutableListBuffer<T> = (0 until size).map(generator).toMutableList().asMutableBuffer()