Complete lu + buffered tensor #240

Merged
AndreiKingsley merged 5 commits from andrew into feature/tensor-algebra 2021-03-13 22:16:23 +03:00
2 changed files with 35 additions and 7 deletions
Showing only changes of commit f9500f44ec - Show all commits

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 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.MutableNDBuffer
import space.kscience.kmath.nd.as2D
import space.kscience.kmath.structures.Buffer
import space.kscience.kmath.structures.RealBuffer import space.kscience.kmath.structures.RealBuffer
import space.kscience.kmath.structures.array import space.kscience.kmath.structures.array
import space.kscience.kmath.structures.toList
public class RealTensor( public class RealTensor(
override val shape: IntArray, shape: IntArray,
buffer: DoubleArray buffer: DoubleArray
) : ) : BufferTensor<Double>(shape, RealBuffer(buffer))
TensorStructure<Double>,
MutableNDBuffer<Double>(
TensorStrides(shape),
RealBuffer(buffer)
)
public class RealTensorAlgebra : TensorPartialDivisionAlgebra<Double, RealTensor> { public class RealTensorAlgebra : TensorPartialDivisionAlgebra<Double, RealTensor> {