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