v0.3.0-dev-9 #324

Merged
altavir merged 265 commits from dev into master 2021-05-08 17:16:29 +03:00
Showing only changes of commit 8933c820b3 - Show all commits

View File

@ -12,7 +12,6 @@ public open class DoubleTensorAlgebra : TensorPartialDivisionAlgebra<Double, Dou
return DoubleTensor(shape, buffer, 0) return DoubleTensor(shape, buffer, 0)
} }
override operator fun DoubleTensor.get(i: Int): DoubleTensor { override operator fun DoubleTensor.get(i: Int): DoubleTensor {
val lastShape = this.shape.drop(1).toIntArray() val lastShape = this.shape.drop(1).toIntArray()
val newShape = if (lastShape.isNotEmpty()) lastShape else intArrayOf(1) val newShape = if (lastShape.isNotEmpty()) lastShape else intArrayOf(1)
@ -20,41 +19,24 @@ public open class DoubleTensorAlgebra : TensorPartialDivisionAlgebra<Double, Dou
return DoubleTensor(newShape, this.buffer.array(), newStart) return DoubleTensor(newShape, this.buffer.array(), newStart)
} }
<<<<<<< HEAD:kmath-core/src/commonMain/kotlin/space/kscience/kmath/tensors/DoubleTensorAlgebra.kt
override fun full(shape: IntArray, value: Double): DoubleTensor {
val buffer = DoubleArray(TensorStrides(shape).linearSize) { value }
return DoubleTensor(shape, buffer)
}
override fun zeros(shape: IntArray): DoubleTensor = full(shape, 0.0)
override fun ones(shape: IntArray): DoubleTensor = full(shape, 1.0)
=======
override fun full(value: Double, shape: IntArray): DoubleTensor { override fun full(value: Double, shape: IntArray): DoubleTensor {
checkEmptyShape(shape) checkEmptyShape(shape)
val buffer = DoubleArray(shape.reduce(Int::times)) { value } val buffer = DoubleArray(shape.reduce(Int::times)) { value }
return DoubleTensor(shape, buffer) return DoubleTensor(shape, buffer)
} }
>>>>>>> ups/feature/tensor-algebra:kmath-core/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensorAlgebra.kt
override fun DoubleTensor.fullLike(value: Double): DoubleTensor { override fun DoubleTensor.fullLike(value: Double): DoubleTensor {
val shape = this.shape val shape = this.shape
val buffer = DoubleArray(this.strides.linearSize) { value } val buffer = DoubleArray(this.strides.linearSize) { value }
return DoubleTensor(shape, buffer) return DoubleTensor(shape, buffer)
} }
<<<<<<< HEAD:kmath-core/src/commonMain/kotlin/space/kscience/kmath/tensors/DoubleTensorAlgebra.kt
override fun DoubleTensor.zeroesLike(): DoubleTensor = this.fullLike(0.0)
=======
override fun zeros(shape: IntArray): DoubleTensor = full(0.0, shape) override fun zeros(shape: IntArray): DoubleTensor = full(0.0, shape)
override fun DoubleTensor.zeroesLike(): DoubleTensor = this.fullLike(0.0) override fun DoubleTensor.zeroesLike(): DoubleTensor = this.fullLike(0.0)
override fun ones(shape: IntArray): DoubleTensor = full(1.0, shape) override fun ones(shape: IntArray): DoubleTensor = full(1.0, shape)
>>>>>>> ups/feature/tensor-algebra:kmath-core/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensorAlgebra.kt
override fun DoubleTensor.onesLike(): DoubleTensor = this.fullLike(1.0) override fun DoubleTensor.onesLike(): DoubleTensor = this.fullLike(1.0)
override fun eye(n: Int): DoubleTensor { override fun eye(n: Int): DoubleTensor {
@ -71,7 +53,6 @@ public open class DoubleTensorAlgebra : TensorPartialDivisionAlgebra<Double, Dou
return DoubleTensor(this.shape, this.buffer.array().copyOf(), this.bufferStart) return DoubleTensor(this.shape, this.buffer.array().copyOf(), this.bufferStart)
} }
override fun Double.plus(other: DoubleTensor): DoubleTensor { override fun Double.plus(other: DoubleTensor): DoubleTensor {
val resBuffer = DoubleArray(other.strides.linearSize) { i -> val resBuffer = DoubleArray(other.strides.linearSize) { i ->
other.buffer.array()[other.bufferStart + i] + this other.buffer.array()[other.bufferStart + i] + this