From 25e60f85b803a50ef78ad3261dc037e29030d591 Mon Sep 17 00:00:00 2001 From: Roland Grinis Date: Wed, 6 Apr 2022 12:32:41 +0100 Subject: [PATCH] cholesky fix --- .../space/kscience/kmath/tensors/core/DoubleTensorAlgebra.kt | 2 +- .../kmath/tensors/core/TestDoubleAnalyticTensorAlgebra.kt | 5 +++-- .../space/kscience/kmath/tensors/core/TestDoubleTensor.kt | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) 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 e9dc34748..06e34e724 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 @@ -810,7 +810,7 @@ public open class DoubleTensorAlgebra : val lTensor = zeroesLike() for ((a, l) in tensor.matrixSequence().zip(lTensor.matrixSequence())) - for (i in 0 until n) choleskyHelper(a.as2D(), l.as2D(), n) + choleskyHelper(a.as2D(), l.as2D(), n) return lTensor } diff --git a/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleAnalyticTensorAlgebra.kt b/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleAnalyticTensorAlgebra.kt index d51702403..c1e8f6b63 100644 --- a/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleAnalyticTensorAlgebra.kt +++ b/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleAnalyticTensorAlgebra.kt @@ -8,6 +8,7 @@ package space.kscience.kmath.tensors.core import space.kscience.kmath.operations.invoke import kotlin.math.* import kotlin.test.Test +import kotlin.test.assertEquals import kotlin.test.assertTrue internal class TestDoubleAnalyticTensorAlgebra { @@ -302,11 +303,11 @@ internal class TestDoubleAnalyticTensorAlgebra { @Test fun testStd() = DoubleTensorAlgebra { - assertTrue { floor(tensor5.std() * 10000 ) / 10000 == 2.9439 } + assertEquals(2.9439, floor(tensor5.std() * 10000 ) / 10000) } @Test fun testVariance() = DoubleTensorAlgebra { - assertTrue { floor(tensor5.variance() * 10000 ) / 10000 == 8.6666 } + assertEquals(8.6666, floor(tensor5.variance() * 10000 ) / 10000) } } diff --git a/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleTensor.kt b/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleTensor.kt index 7a38e5b7d..7d0873238 100644 --- a/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleTensor.kt +++ b/kmath-tensors/src/commonTest/kotlin/space/kscience/kmath/tensors/core/TestDoubleTensor.kt @@ -55,7 +55,7 @@ internal class TestDoubleTensor { val buffer = doubleArrayOf(1.0, 2.0, -3.0, 4.0) val tensor = DoubleTensor(shape, buffer) val value = 3 - assertTrue { tensor.times(value).toBufferedTensor() eq DoubleTensor(shape, buffer.map { x -> 3 * x }.toDoubleArray()) } + assertTrue { tensor.times(value).toBufferedTensor() eq DoubleTensor(shape, buffer.map { x -> value * x }.toDoubleArray()) } val buffer2 = doubleArrayOf(7.0, -8.0, -5.0, 2.0) val tensor2 = DoubleTensor(shape, buffer2) assertTrue {tensor.times(tensor2).toBufferedTensor() eq DoubleTensor(shape, doubleArrayOf(7.0, -16.0, 15.0, 8.0)) }