diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensorAlgebra.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensorAlgebra.kt index 6f6cebdc9..e49119a6f 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensorAlgebra.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensorAlgebra.kt @@ -8,7 +8,6 @@ package space.kscience.kmath.tensors.core import space.kscience.kmath.structures.MutableBuffer import space.kscience.kmath.nd.as1D import space.kscience.kmath.nd.as2D -import space.kscience.kmath.structures.asMutableBuffer import space.kscience.kmath.tensors.api.AnalyticTensorAlgebra import space.kscience.kmath.tensors.api.LinearOpsTensorAlgebra import space.kscience.kmath.tensors.api.Tensor @@ -539,7 +538,7 @@ public open class DoubleTensorAlgebra : internal fun Tensor.fold(foldFunction: (DoubleArray) -> Double): Double = foldFunction(tensor.toDoubleArray()) - internal fun Tensor.foldDim( + internal inline fun Tensor.foldDim( foldFunction: (DoubleArray) -> R, dim: Int, keepDim: Boolean, @@ -553,7 +552,9 @@ public open class DoubleTensorAlgebra : val resNumElements = resShape.reduce(Int::times) val init = foldFunction(DoubleArray(1){0.0}) val resTensor = BufferedTensor(resShape, - MutableList(resNumElements) { init }.asMutableBuffer(), 0) + MutableBuffer.auto(resNumElements) { init }, + //MutableList(resNumElements) { init }.asMutableBuffer(), + 0) for (index in resTensor.linearStructure.indices()) { val prefix = index.take(dim).toIntArray() val suffix = index.takeLast(dimension - dim - 1).toIntArray() @@ -564,7 +565,6 @@ public open class DoubleTensorAlgebra : return resTensor } - override fun Tensor.sum(): Double = tensor.fold { it.sum() } override fun Tensor.sum(dim: Int, keepDim: Boolean): DoubleTensor =