From 487a663d0fe36fcaa900a704b93f35a3989bc5cc Mon Sep 17 00:00:00 2001 From: Margarita Date: Wed, 23 Mar 2022 00:46:52 +0300 Subject: [PATCH] added test for StructureND.times --- .../kscience/kmath/tensors/core/TestDoubleTensor.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 bebaed32f..7a38e5b7d 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 @@ -49,6 +49,18 @@ internal class TestDoubleTensor { assertTrue { tensor.rowsByIndices(intArrayOf(0, 1)) eq tensor } } + @Test + fun testTimes() = DoubleTensorAlgebra { + val shape = intArrayOf(2, 2) + 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()) } + 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)) } + } + @Test fun testValue() = DoubleTensorAlgebra { val value = 12.5