Skip to content

Custom types for decompositions #40

Description

@Andlon

Rulinalg has implementations of a number of decompositions. Currently these are returned as Result<tuple, Error>, where tuple is a tuple of Matrix<T>. This is in itself useful, as it gives the user easy access to the decomposed parts. However, often you are not necessarily so interested in the decomposed parts themselves, but rather what you can do with them.

For example, in the case of LU or QR and a linear system Ax = b, you may want to perform the decomposition once, and then use it many times over to solve for different instances of b. In this case, as a user, you don't want to have to perform the transposition of Q and the solution of the triangular system. Rather, it would be convenient if you could do something along the lines of (ignoring error handling for to make my point more clear):

let qr = A.qr();
for b in right_hand_sides {
    let x = qr.solve(b);
    do_something(x);
}

This is possible if qr() returns a struct QR that has a specialized solve method, as well as accessors to the decomposed parts Q and R. Similarly for LU. In my opinion, you would not lose anything over the current API, but you'd make it easier to use, and it could also open up for optimizations in how the decompositions are stored, and how they are used to perform certain actions.

For SVD, you could have convenient methods to retrieve the singular values, perhaps for least squares solution etc. In addition to accessors to the decomposed parts, of course.

Eigen (C++ library) does something like this. I'll be quick to add that I do not want rulinalg to mirror Eigen's API too closely, as it is... perhaps overly complex at times.

Do you think this style of API could be suitable for rulinalg? I'd be interested to hear your opinions!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions