Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/emptyflash/shapeless-matrix
Typesafe matrix operations
https://github.com/emptyflash/shapeless-matrix
math matrix scala shapeless typesafe
Last synced: 23 days ago
JSON representation
Typesafe matrix operations
- Host: GitHub
- URL: https://github.com/emptyflash/shapeless-matrix
- Owner: emptyflash
- Created: 2017-05-02T19:32:48.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-06-15T14:32:38.000Z (over 6 years ago)
- Last Synced: 2024-11-05T23:45:53.798Z (2 months ago)
- Topics: math, matrix, scala, shapeless, typesafe
- Language: Scala
- Homepage:
- Size: 5.86 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# shapeless-matrix
Typesafe matrix operations with Scala and Shapeless
### Example
Multiplication works for matrices with the correct dimensions
``` scala
import shapeless.Sized
import shapeless.nat._
import io.github.emptyflash.matrix.Matrixval matrix = new Matrix[Int, _2, _3](Sized(
Sized(1, 2, 3),
Sized(4, 5, 6)
))
val other = new Matrix[Int, _3, _2](Sized(
Sized(1, 2),
Sized(3, 4),
Sized(5, 6)
))matrix * other
// Matrix[Int,shapeless.nat._2,shapeless.nat._2] = Matrix(Sized(Sized(22, 28), Sized(49, 64)))
```But will fail at compile time for matrices with incorrect dimensions
``` scala
val matrix = new Matrix[Int, _2, _3](Sized(
Sized(1, 2, 3),
Sized(4, 5, 6)
))
val other = new Matrix[Int, _2, _2](Sized(
Sized(1, 2),
Sized(3, 4)
))matrix * other
/*
error: type mismatch;
found : io.github.emptyflash.matrix.Matrix[Int,shapeless.nat._2,shapeless.nat._2]
required: io.github.emptyflash.matrix.Matrix[Int,shapeless.nat._3,?]
matrix * other
^
*/
```