2019-04-15 20:50:50 +03:00
|
|
|
## Basic linear algebra layout
|
|
|
|
|
2024-03-27 09:11:12 +03:00
|
|
|
KMath support for linear algebra organized in a context-oriented way, which means that operations are in most cases
|
|
|
|
declared in context classes, and are not the members of classes that store data. This allows more flexible approach to
|
|
|
|
maintain multiple back-ends. The new operations added as extensions to contexts instead of being member functions of
|
|
|
|
data structures.
|
2019-04-15 20:50:50 +03:00
|
|
|
|
2024-03-27 09:11:12 +03:00
|
|
|
The main context for linear algebra over matrices and vectors is `LinearSpace`, which defines addition and dot products
|
|
|
|
of matrices and vectors:
|
2019-04-15 20:50:50 +03:00
|
|
|
|
2021-05-07 15:59:21 +03:00
|
|
|
```kotlin
|
|
|
|
import space.kscience.kmath.linear.*
|
2019-04-15 20:50:50 +03:00
|
|
|
|
2021-05-07 15:59:21 +03:00
|
|
|
LinearSpace.Companion.real {
|
|
|
|
val vec = buildVector(10) { i -> i.toDouble() }
|
|
|
|
val mat = buildMatrix(10, 10) { i, j -> i.toDouble() + j }
|
2019-04-15 20:50:50 +03:00
|
|
|
|
2021-05-07 15:59:21 +03:00
|
|
|
// Addition
|
|
|
|
vec + vec
|
|
|
|
mat + mat
|
2019-04-15 20:50:50 +03:00
|
|
|
|
2021-05-07 15:59:21 +03:00
|
|
|
// Multiplication by scalar
|
|
|
|
vec * 2.0
|
|
|
|
mat * 2.0
|
2019-04-15 20:50:50 +03:00
|
|
|
|
2021-05-07 15:59:21 +03:00
|
|
|
// Dot product
|
|
|
|
mat dot vec
|
|
|
|
mat dot mat
|
|
|
|
}
|
|
|
|
```
|
2019-04-15 20:50:50 +03:00
|
|
|
|
2021-05-07 15:59:21 +03:00
|
|
|
## Backends overview
|
|
|
|
|
|
|
|
### EJML
|
2024-03-27 09:11:12 +03:00
|
|
|
|
2021-05-07 15:59:21 +03:00
|
|
|
### Commons Math
|