From cc00e1dee58f5ebe7b40c11758ce84c869d4e232 Mon Sep 17 00:00:00 2001 From: Margarita Date: Wed, 23 Mar 2022 00:25:17 +0300 Subject: [PATCH] added tests for fullLike, onesLike, rowsByIndices --- .../kmath/tensors/core/TestDoubleTensor.kt | 26 +++++++++++++++++++ 1 file changed, 26 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 d808637c7..bebaed32f 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 @@ -23,6 +23,32 @@ import kotlin.test.assertTrue internal class TestDoubleTensor { + @Test + fun testFullLike() = DoubleTensorAlgebra { + val shape = intArrayOf(2, 3) + val buffer = doubleArrayOf(1.0, 2.0, 3.0, 4.0, 5.0, 6.0) + val tensor = DoubleTensor(shape, buffer) + val value = 12.5 + assertTrue { tensor.fullLike(value) eq DoubleTensor(shape, buffer.map { value }.toDoubleArray() ) } + } + + @Test + fun testOnesLike() = DoubleTensorAlgebra { + val shape = intArrayOf(2, 3) + val buffer = doubleArrayOf(1.0, 2.0, 3.0, 4.0, 5.0, 6.0) + val tensor = DoubleTensor(shape, buffer) + assertTrue { tensor.onesLike() eq DoubleTensor(shape, buffer.map { 1.0 }.toDoubleArray() ) } + } + + @Test + fun testRowsByIndices() = DoubleTensorAlgebra { + val shape = intArrayOf(2, 2) + val buffer = doubleArrayOf(1.0, 2.0, -3.0, 4.0) + val tensor = fromArray(shape, buffer) + assertTrue { tensor.rowsByIndices(intArrayOf(0)) eq DoubleTensor(intArrayOf(1, 2), doubleArrayOf(1.0, 2.0)) } + assertTrue { tensor.rowsByIndices(intArrayOf(0, 1)) eq tensor } + } + @Test fun testValue() = DoubleTensorAlgebra { val value = 12.5