forked from kscience/kmath
e9c31b7827
# Conflicts: # README.md # build.gradle.kts # examples/src/main/kotlin/space/kscience/kmath/stat/DistributionBenchmark.kt # examples/src/main/kotlin/space/kscience/kmath/structures/ParallelRealNDField.kt # kmath-ast/README.md # kmath-ast/build.gradle.kts # kmath-ast/src/commonMain/kotlin/space/kscience/kmath/ast/MstExpression.kt # kmath-complex/README.md # kmath-complex/build.gradle.kts # kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/ComplexNDField.kt # kmath-core/README.md # kmath-core/build.gradle.kts # kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MST.kt # kmath-core/src/commonMain/kotlin/space/kscience/kmath/expressions/MstAlgebra.kt # kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/RealNDField.kt # kmath-core/src/commonMain/kotlin/space/kscience/kmath/structures/RealBufferField.kt # kmath-coroutines/build.gradle.kts # kmath-coroutines/src/commonMain/kotlin/space/kscience/kmath/chains/BlockingRealChain.kt # kmath-coroutines/src/jvmMain/kotlin/space/kscience/kmath/structures/LazyNDStructure.kt # kmath-dimensions/src/commonTest/kotlin/kscience/dimensions/DMatrixContextTest.kt # kmath-for-real/README.md # kmath-functions/README.md # kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/Interpolator.kt # kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/LoessInterpolator.kt # kmath-functions/src/commonMain/kotlin/space/kscience/kmath/interpolation/XYPointSet.kt # kmath-geometry/build.gradle.kts # kmath-nd4j/README.md # kmath-nd4j/build.gradle.kts # kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/FactorizedDistribution.kt # kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Distribution.kt # kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/Fitting.kt # kmath-stat/src/commonMain/kotlin/space/kscience/kmath/stat/OptimizationProblem.kt # kmath-stat/src/jvmMain/kotlin/space/kscience/kmath/stat/distributions.kt # kmath-viktor/src/main/kotlin/space/kscience/kmath/viktor/ViktorNDStructure.kt
37 lines
1.0 KiB
Kotlin
37 lines
1.0 KiB
Kotlin
/*
|
|
* Copyright 2018-2021 KMath contributors.
|
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
*/
|
|
|
|
package space.kscience.dimensions
|
|
|
|
import space.kscience.kmath.dimensions.D2
|
|
import space.kscience.kmath.dimensions.D3
|
|
import space.kscience.kmath.dimensions.DMatrixContext
|
|
import space.kscience.kmath.dimensions.one
|
|
import kotlin.test.Test
|
|
|
|
@Suppress("UNUSED_VARIABLE")
|
|
internal class DMatrixContextTest {
|
|
@Test
|
|
fun testDimensionSafeMatrix() {
|
|
val res = with(DMatrixContext.real) {
|
|
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 = with(DMatrixContext.real) {
|
|
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
|
|
}
|
|
}
|
|
}
|