new tensor def

This commit is contained in:
Andrei Kislitsyn 2021-03-12 13:50:06 +03:00
parent 723e0e458e
commit f9500f44ec
2 changed files with 35 additions and 7 deletions

View File

@ -0,0 +1,28 @@
package space.kscience.kmath.tensors
import space.kscience.kmath.linear.BufferMatrix
import space.kscience.kmath.linear.RealMatrixContext.toBufferMatrix
import space.kscience.kmath.nd.MutableNDBuffer
import space.kscience.kmath.nd.as2D
import space.kscience.kmath.structures.MutableBuffer
import space.kscience.kmath.structures.toList
public open class BufferTensor<T>(
override val shape: IntArray,
buffer: MutableBuffer<T>
) :
TensorStructure<T>,
MutableNDBuffer<T>(
TensorStrides(shape),
buffer
)
public fun <T : Any> BufferTensor<T>.toBufferMatrix(): BufferMatrix<T> {
return BufferMatrix(shape[0], shape[1], this.buffer)
}
public fun <T : Any> BufferMatrix<T>.BufferTensor(): BufferTensor<T> {
return BufferTensor(intArrayOf(rowNum, colNum), buffer)
}

View File

@ -1,19 +1,19 @@
package space.kscience.kmath.tensors
import space.kscience.kmath.linear.BufferMatrix
import space.kscience.kmath.linear.RealMatrixContext.toBufferMatrix
import space.kscience.kmath.nd.MutableNDBuffer
import space.kscience.kmath.nd.as2D
import space.kscience.kmath.structures.Buffer
import space.kscience.kmath.structures.RealBuffer
import space.kscience.kmath.structures.array
import space.kscience.kmath.structures.toList
public class RealTensor(
override val shape: IntArray,
shape: IntArray,
buffer: DoubleArray
) :
TensorStructure<Double>,
MutableNDBuffer<Double>(
TensorStrides(shape),
RealBuffer(buffer)
)
) : BufferTensor<Double>(shape, RealBuffer(buffer))
public class RealTensorAlgebra : TensorPartialDivisionAlgebra<Double, RealTensor> {