Is it possible to have a function with arbitrarily sized matricies?
- Dominant language
- Rust
- Stars
- 4.8k
- Forks
- 565
- PR merge metrics
- No merged PRs in 30d
Description
I've been trying for a few hours to create a simple generic function for arbitrary matrices, but nothing seems to work. I've been looking at [this guide](http://nalgebra.org/generic_programming/) from the documentation.
```
use na::Dim;
use na::Matrix;
type Matrixd = Matrix;
pub fn mult, VS: Storage>
(A: Matrixd, v:Matrixd) -> Matrixd {
A * v
}
```
I get the error:
```
error[E0369]: binary operation `*` cannot be applied to type `na::Matrix`
--> src/lib.rs:21:21
|
21 | A * v
| ^^^^^
|
= note: an implementation of `std::ops::Mul` might be missing for `na::Matrix`
```
When trying the `alga` crate way:
```
use alga::linear as lin;
pub fn mult
(A: M, v: V) -> V {
A * v
}
pub fn use_mult() {
let A: Matrix3 = Matrix3::identity();
let v: Vector3 = Vector3::x();
let out = mult(A, v);
}
```
I get the following errors:
```
error[E0308]: mismatched types
--> src/lib.rs:21:25
|
21 | A * v
| ^ expected associated type, found type parameter
|
= note: expected type `::Row`
found type `V`
error[E0308]: mismatched types
--> src/lib.rs:21:21
|
20 | (A: M, v: V) -> V {
| - expected `V` because of return type
21 | A * v
| ^^^^^ expected type parameter, found associated type
|
= note: expected type `V`
found type `::Column`
error[E0277]: the trait bound `na::Matrix>: alga::linear::Matrix` is not satisfied
--> src/lib.rs:28:15
|
28 | let out = mult(A, v);
| ^^^^ the trait `alga::linear::Matrix` is not implemented for `na::Matrix>`
|
note: required by `mult`
--> src/lib.rs:19:1
|
19 | / pub fn mult
20 | | (A: M, v: V) -> V {
21 | | A * v
22 | | }
| |_________________^
error[E0277]: the trait bound `na::Matrix>: alga::linear::Matrix` is not satisfied
--> src/lib.rs:28:15
|
28 | let out = mult(A, v);
| ^^^^ the trait `alga::linear::Matrix` is not implemented for `na::Matrix>`
|
note: required by `mult`
--> src/lib.rs:19:1
|
19 | / pub fn mult
20 | | (A: M, v: V) -> V {
21 | | A * v
22 | | }
| |_________________^
```
The `alga` traits don't seem to be implemented for `nalgebra::Matrix` ?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.