KMP library for tensors #300
@ -1881,15 +1881,6 @@ public final class space/kscience/kmath/structures/MutableBuffer$Companion {
|
|||||||
public final fun short-1yRgbGw (ILkotlin/jvm/functions/Function1;)[S
|
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 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 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;
|
public static fun constructor-impl (ILkotlin/jvm/functions/Function1;)Ljava/util/List;
|
||||||
|
@ -8,7 +8,7 @@ package space.kscience.kmath.nd
|
|||||||
import space.kscience.kmath.misc.UnstableKMathAPI
|
import space.kscience.kmath.misc.UnstableKMathAPI
|
||||||
import space.kscience.kmath.structures.Buffer
|
import space.kscience.kmath.structures.Buffer
|
||||||
import space.kscience.kmath.structures.VirtualBuffer
|
import space.kscience.kmath.structures.VirtualBuffer
|
||||||
import space.kscience.kmath.structures.MutableBufferFromGenerator
|
import space.kscience.kmath.structures.MutableListBuffer
|
||||||
import kotlin.jvm.JvmInline
|
import kotlin.jvm.JvmInline
|
||||||
import kotlin.reflect.KClass
|
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.
|
* The buffer of rows of this structure. It gets elements from the structure dynamically.
|
||||||
*/
|
*/
|
||||||
override val rows: List<MutableStructure1D<T>>
|
override val rows: List<MutableStructure1D<T>>
|
||||||
get() = List(rowNum) { i -> MutableBuffer1DWrapper(MutableBufferFromGenerator(colNum) { j -> get(i, j) })}
|
get() = List(rowNum) { i -> MutableBuffer1DWrapper(MutableListBuffer(colNum) { j -> get(i, j) })}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The buffer of columns of this structure. It gets elements from the structure dynamically.
|
* The buffer of columns of this structure. It gets elements from the structure dynamically.
|
||||||
*/
|
*/
|
||||||
override val columns: List<MutableStructure1D<T>>
|
override val columns: List<MutableStructure1D<T>>
|
||||||
get() = List(colNum) { j -> MutableBuffer1DWrapper(MutableBufferFromGenerator(rowNum) { i -> get(i, j) }) }
|
get() = List(colNum) { j -> MutableBuffer1DWrapper(MutableListBuffer(rowNum) { i -> get(i, j) }) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -292,24 +292,6 @@ 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()
|
override operator fun iterator(): Iterator<T> = (0 until size).asSequence().map(generator).iterator()
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
|
||||||
|
|
||||||
override operator fun get(index: Int): T {
|
|
||||||
if (index < 0 || index >= size) throw IndexOutOfBoundsException("Expected index from 0 to ${size - 1}, but found $index")
|
|
||||||
return bufferHolder[index]
|
|
||||||
}
|
|
||||||
|
|
||||||
override operator fun iterator(): Iterator<T> = bufferHolder.iterator()
|
|
||||||
|
|
||||||
override fun set(index: Int, value: T) {
|
|
||||||
bufferHolder[index] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun copy(): MutableBuffer<T> = bufferHolder.copy()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert this buffer to read-only buffer.
|
* Convert this buffer to read-only buffer.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user