2020-09-20 22:39:27 +03:00
|
|
|
package kscience.dimensions
|
2019-06-21 12:34:04 +03:00
|
|
|
|
2020-09-20 22:39:27 +03:00
|
|
|
import kscience.kmath.dimensions.D2
|
|
|
|
import kscience.kmath.dimensions.D3
|
|
|
|
import kscience.kmath.dimensions.DMatrixContext
|
2021-01-07 18:07:00 +03:00
|
|
|
import kscience.kmath.dimensions.one
|
2019-06-21 12:34:04 +03:00
|
|
|
import kotlin.test.Test
|
|
|
|
|
2021-01-19 22:24:42 +03:00
|
|
|
@Suppress("UNUSED_VARIABLE")
|
2020-09-09 17:12:18 +03:00
|
|
|
internal class DMatrixContextTest {
|
2019-06-21 12:34:04 +03:00
|
|
|
@Test
|
|
|
|
fun testDimensionSafeMatrix() {
|
2020-08-21 22:42:59 +03:00
|
|
|
val res = with(DMatrixContext.real) {
|
2019-06-21 12:34:04 +03:00
|
|
|
val m = produce<D2, D2> { i, j -> (i + j).toDouble() }
|
|
|
|
|
|
|
|
//The dimension of `one()` is inferred from type
|
|
|
|
(m + one())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun testTypeCheck() {
|
2020-08-21 22:42:59 +03:00
|
|
|
val res = with(DMatrixContext.real) {
|
2019-06-21 12:34:04 +03:00
|
|
|
val m1 = produce<D2, D3> { i, j -> (i + j).toDouble() }
|
|
|
|
val m2 = produce<D3, D2> { i, j -> (i + j).toDouble() }
|
|
|
|
|
|
|
|
//Dimension-safe addition
|
|
|
|
m1.transpose() + m2
|
|
|
|
}
|
|
|
|
}
|
2020-09-09 17:12:18 +03:00
|
|
|
}
|