Separate linear operator from matrix trait
- Dominant language
- Rust
- Stars
- 201
- Forks
- 40
- PR merge metrics
- No merged PRs in 30d
Description
For context, this idea is motivated by vbarielle/sprs#118.
The matrix trait is rather large at the moment:
```rust
pub trait Matrix: Sized + Clone + Mul {
type Field: Field;
type Row: FiniteDimVectorSpace;
type Column: FiniteDimVectorSpace;
type Transpose: Matrix;
fn nrows(&self) -> usize;
fn ncolumns(&self) -> usize;
fn row(&self, i: usize) -> Self::Row;
fn column(&self, i: usize) -> Self::Column;
unsafe fn get_unchecked(&self, i: usize, j: usize) -> Self::Field;
fn transpose(&self) -> Self::Transpose;
fn get(&self, i: usize, j: usize) -> Self::Field { ... }
}
```
For many algorithms, access to the internal structure of the matrix is not necessary. It also does put some burden on trait implementors that may be possible to avoid.
A suggested solution would be to introduce a more abstract linear operator inspired by SciPy's [interface with the same name](https://docs.scipy.org/doc/scipy-1.0.0/reference/generated/scipy.sparse.linalg.LinearOperator.html) as a supertrait.
```rust
pub trait LinearOperator: Sized + Clone + Mul {
type Field: Field;
type Row: FiniteDimVectorSpace;
type Column: FiniteDimVectorSpace;
type Transpose: LinearOperator;
fn nrows(&self) -> usize;
fn ncolumns(&self) -> usize;
fn transpose(&self) -> Self::Transpose;
}
pub trait Matrix: LinearOperator {
fn row(&self, i: usize) -> Self::Row;
fn column(&self, i: usize) -> Self::Column;
unsafe fn get_unchecked(&self, i: usize, j: usize) -> Self::Field;
fn get(&self, i: usize, j: usize) -> Self::Field { ... }
}
```
It would be useful to include matrix multiplication there as well, but I have a feeling that this is hard to express in today's Rust. It also seems like a separate issue as the original matrix trait does not include this either.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.