Golub-Kahan SVD algorithm for KMP tensors #499

Closed
grinisrit wants to merge 64 commits from dev into dev
Showing only changes of commit 93b62c5bf6 - Show all commits

View File

@ -23,6 +23,32 @@ import kotlin.test.assertTrue
internal class TestDoubleTensor { 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 @Test
fun testValue() = DoubleTensorAlgebra { fun testValue() = DoubleTensorAlgebra {
val value = 12.5 val value = 12.5