From 9eb953228afc50ba3243a703d9f6ace328cdae1e Mon Sep 17 00:00:00 2001 From: margarita0303 Date: Tue, 2 Aug 2022 19:40:10 +0300 Subject: [PATCH] mutableBuffer setter method now is used in PowerMethod --- .../kmath/tensors/core/internal/linUtils.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/linUtils.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/linUtils.kt index 9724fc335..825c15006 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/linUtils.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/internal/linUtils.kt @@ -308,6 +308,14 @@ internal fun DoubleTensorAlgebra.svdPowerMethodHelper( val res = ArrayList>(0) val (matrixU, matrixS, matrixV) = USV + val matrixUStart = matrixU.bufferStart + val matrixSStart = matrixS.bufferStart + val matrixVStart = matrixV.bufferStart + + val matrixUBuffer = matrixU.mutableBuffer + val matrixSBuffer = matrixS.mutableBuffer + val matrixVBuffer = matrixV.mutableBuffer + for (k in 0 until min(n, m)) { var a = matrix.copy() for ((singularValue, u, v) in res.slice(0 until k)) { @@ -341,13 +349,13 @@ internal fun DoubleTensorAlgebra.svdPowerMethodHelper( val uBuffer = res.map { it.second }.flatMap { it.mutableBuffer.array().toList() }.toDoubleArray() val vBuffer = res.map { it.third }.flatMap { it.mutableBuffer.array().toList() }.toDoubleArray() for (i in uBuffer.indices) { - matrixU.mutableBuffer.array()[matrixU.bufferStart + i] = uBuffer[i] + matrixUBuffer[matrixUStart + i] = uBuffer[i] } for (i in s.indices) { - matrixS.mutableBuffer.array()[matrixS.bufferStart + i] = s[i] + matrixSBuffer[matrixSStart + i] = s[i] } for (i in vBuffer.indices) { - matrixV.mutableBuffer.array()[matrixV.bufferStart + i] = vBuffer[i] + matrixVBuffer[matrixVStart + i] = vBuffer[i] } }