KMP library for tensors #300
@ -8,6 +8,7 @@ package space.kscience.kmath.tensors.api
|
||||
// https://proofwiki.org/wiki/Definition:Division_Algebra
|
||||
public interface TensorPartialDivisionAlgebra<T> :
|
||||
TensorAlgebra<T> {
|
||||
public operator fun T.div(other: TensorStructure<T>): TensorStructure<T>
|
||||
public operator fun TensorStructure<T>.div(value: T): TensorStructure<T>
|
||||
public operator fun TensorStructure<T>.div(other: TensorStructure<T>): TensorStructure<T>
|
||||
public operator fun TensorStructure<T>.divAssign(value: T)
|
||||
|
@ -178,13 +178,15 @@ public open class DoubleTensorAlgebra : TensorPartialDivisionAlgebra<Double> {
|
||||
}
|
||||
}
|
||||
|
||||
override fun TensorStructure<Double>.div(value: Double): DoubleTensor {
|
||||
val resBuffer = DoubleArray(tensor.numElements) { i ->
|
||||
tensor.buffer.array()[tensor.bufferStart + i] / value
|
||||
override fun Double.div(other: TensorStructure<Double>): DoubleTensor {
|
||||
val resBuffer = DoubleArray(other.tensor.numElements) { i ->
|
||||
other.tensor.buffer.array()[other.tensor.bufferStart + i] / this
|
||||
}
|
||||
return DoubleTensor(tensor.shape, resBuffer)
|
||||
return DoubleTensor(other.shape, resBuffer)
|
||||
}
|
||||
|
||||
override fun TensorStructure<Double>.div(value: Double): DoubleTensor = value / tensor
|
||||
|
||||
override fun TensorStructure<Double>.div(other: TensorStructure<Double>): DoubleTensor {
|
||||
checkShapesCompatible(tensor, other)
|
||||
val resBuffer = DoubleArray(tensor.numElements) { i ->
|
||||
|
Loading…
Reference in New Issue
Block a user