2020-04-27 15:43:03 +03:00
|
|
|
package scientifik.dimensions
|
2019-06-21 12:34:04 +03:00
|
|
|
|
2020-04-27 15:43:03 +03:00
|
|
|
import scientifik.kmath.dimensions.D2
|
|
|
|
import scientifik.kmath.dimensions.D3
|
|
|
|
import scientifik.kmath.dimensions.DMatrixContext
|
2019-06-21 12:34:04 +03:00
|
|
|
import kotlin.test.Test
|
|
|
|
|
|
|
|
|
|
|
|
class DMatrixContextTest {
|
|
|
|
@Test
|
|
|
|
fun testDimensionSafeMatrix() {
|
|
|
|
val res = DMatrixContext.real.run {
|
|
|
|
val m = produce<D2, D2> { i, j -> (i + j).toDouble() }
|
|
|
|
|
|
|
|
//The dimension of `one()` is inferred from type
|
|
|
|
(m + one())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun testTypeCheck() {
|
|
|
|
val res = DMatrixContext.real.run {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|