added tests for fullLike, onesLike, rowsByIndices

This commit is contained in:
Margarita 2022-03-23 00:25:17 +03:00
parent 0440764cd3
commit 93b62c5bf6

View File

@ -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