Examples for type-safe dimensions

This commit is contained in:
Alexander Nozik 2019-12-09 19:57:26 +03:00
parent 09f2f37780
commit 169801060b
2 changed files with 6 additions and 4 deletions

View File

@ -40,6 +40,8 @@ can be used for a wide variety of purposes from high performance calculations to
* **Streaming** Streaming operations on mathematical objects and objects buffers. * **Streaming** Streaming operations on mathematical objects and objects buffers.
* **Type-safe dimensions** Type-safe dimensions for matrix operations.
* **Commons-math wrapper** It is planned to gradually wrap most parts of [Apache commons-math](http://commons.apache.org/proper/commons-math/) * **Commons-math wrapper** It is planned to gradually wrap most parts of [Apache commons-math](http://commons.apache.org/proper/commons-math/)
library in Kotlin code and maybe rewrite some parts to better suit the Kotlin programming paradigm, however there is no fixed roadmap for that. Feel free library in Kotlin code and maybe rewrite some parts to better suit the Kotlin programming paradigm, however there is no fixed roadmap for that. Feel free
to submit a feature request if you want something to be done first. to submit a feature request if you want something to be done first.

View File

@ -14,14 +14,14 @@ fun DMatrixContext<Double, RealField>.simple() {
m1.transpose() + m2 m1.transpose() + m2
} }
object D5: Dimension{ object D5 : Dimension {
override val dim: UInt = 5u override val dim: UInt = 5u
} }
fun DMatrixContext<Double, RealField>.custom() { fun DMatrixContext<Double, RealField>.custom() {
val m1 = produce<D2, D5> { i, j -> (i+j).toDouble() } val m1 = produce<D2, D5> { i, j -> (i + j).toDouble() }
val m2 = produce<D5,D2> { i, j -> (i-j).toDouble() } val m2 = produce<D5, D2> { i, j -> (i - j).toDouble() }
val m3 = produce<D2,D2> { i, j -> (i-j).toDouble() } val m3 = produce<D2, D2> { i, j -> (i - j).toDouble() }
(m1 dot m2) + m3 (m1 dot m2) + m3
} }