Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate linear operator from matrix trait #32

Open
milibopp opened this issue Oct 27, 2017 · 0 comments
Open

Separate linear operator from matrix trait #32

milibopp opened this issue Oct 27, 2017 · 0 comments

Comments

@milibopp
Copy link

For context, this idea is motivated by vbarielle/sprs#118.

The matrix trait is rather large at the moment:

pub trait Matrix: Sized + Clone + Mul<Self::Row, Output = Self::Column> {
    type Field: Field;
    type Row: FiniteDimVectorSpace<Field = Self::Field>;
    type Column: FiniteDimVectorSpace<Field = Self::Field>;
    type Transpose: Matrix<Field = Self::Field, Row = Self::Column, Column = Self::Row>;
    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 as a supertrait.

pub trait LinearOperator: Sized + Clone + Mul<Self::Row, Output = Self::Column> {
    type Field: Field;
    type Row: FiniteDimVectorSpace<Field = Self::Field>;
    type Column: FiniteDimVectorSpace<Field = Self::Field>;
    type Transpose: LinearOperator<Field = Self::Field, Row = Self::Column, Column = Self::Row>;
    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant