KMP library for tensors #300

Merged
grinisrit merged 215 commits from feature/tensor-algebra into dev 2021-05-08 09:48:04 +03:00
Showing only changes of commit 35928e7960 - Show all commits

View File

@ -5,7 +5,7 @@ import space.kscience.kmath.tensors.api.Tensor
import space.kscience.kmath.tensors.core.algebras.TensorLinearStructure
/**
* [Tensor] implementation provided with [MutableBuffer]
* Represents [Tensor] over a [MutableBuffer] intended to be used through [DoubleTensor] and [IntTensor]
*/
public open class BufferedTensor<T> internal constructor(
override val shape: IntArray,
@ -14,7 +14,7 @@ public open class BufferedTensor<T> internal constructor(
) : Tensor<T> {
/**
* [TensorLinearStructure] with the same shape
* Buffer strides based on [TensorLinearStructure] implementation
*/
public val linearStructure: TensorLinearStructure
get() = TensorLinearStructure(shape)
@ -25,23 +25,12 @@ public open class BufferedTensor<T> internal constructor(
public val numElements: Int
get() = linearStructure.linearSize
/**
* @param index [IntArray] with size equal to tensor dimension
* @return the element by multidimensional index
*/
override fun get(index: IntArray): T = mutableBuffer[bufferStart + linearStructure.offset(index)]
/**
* @param index the [IntArray] with size equal to tensor dimension
* @param value the value to set
*/
override fun set(index: IntArray, value: T) {
mutableBuffer[bufferStart + linearStructure.offset(index)] = value
}
/**
* @return the sequence of pairs multidimensional indices and values
*/
override fun elements(): Sequence<Pair<IntArray, T>> = linearStructure.indices().map {
it to this[it]
}