forked from kscience/kmath
div operator
This commit is contained in:
parent
559e8b24ab
commit
287e2aeba2
@ -8,6 +8,7 @@ package space.kscience.kmath.tensors.api
|
|||||||
// https://proofwiki.org/wiki/Definition:Division_Algebra
|
// https://proofwiki.org/wiki/Definition:Division_Algebra
|
||||||
public interface TensorPartialDivisionAlgebra<T> :
|
public interface TensorPartialDivisionAlgebra<T> :
|
||||||
TensorAlgebra<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(value: T): TensorStructure<T>
|
||||||
public operator fun TensorStructure<T>.div(other: TensorStructure<T>): TensorStructure<T>
|
public operator fun TensorStructure<T>.div(other: TensorStructure<T>): TensorStructure<T>
|
||||||
public operator fun TensorStructure<T>.divAssign(value: 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 {
|
override fun Double.div(other: TensorStructure<Double>): DoubleTensor {
|
||||||
val resBuffer = DoubleArray(tensor.numElements) { i ->
|
val resBuffer = DoubleArray(other.tensor.numElements) { i ->
|
||||||
tensor.buffer.array()[tensor.bufferStart + i] / value
|
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 {
|
override fun TensorStructure<Double>.div(other: TensorStructure<Double>): DoubleTensor {
|
||||||
checkShapesCompatible(tensor, other)
|
checkShapesCompatible(tensor, other)
|
||||||
val resBuffer = DoubleArray(tensor.numElements) { i ->
|
val resBuffer = DoubleArray(tensor.numElements) { i ->
|
||||||
|
Loading…
Reference in New Issue
Block a user