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

mat: rewrite extractions and solves as methods on factorising types #113

Merged
merged 7 commits into from Jul 6, 2017

Conversation

kortschak
Copy link
Member

@kortschak kortschak commented Jun 30, 2017

@btracey Please take a look.

Fixes #101.
Fixes #102.

@kortschak kortschak changed the title mat: rewrite cholesky extractions and To rather than From mat: rewrite extractions and solves as methods on factorising types Jun 30, 2017
@kortschak kortschak requested a review from btracey June 30, 2017 05:24
@kortschak kortschak force-pushed the cholesky-extraction branch 3 times, most recently from 8a18df8 to 5358abf Compare June 30, 2017 07:06
@btracey
Copy link
Member

btracey commented Jun 30, 2017

Here's a meta comment, just to make sure I'm thinking about this correctly in the code review.

I would love to figure out how to make higher-level libraries be efficient with their use of matrix types. Let's say (in a future gonum), we have var a mat.Diag, and we have filled in a. I would love if cholesky.Factorize just takes the square root of the matrix entries and stores a diagonal matrix. This could happen, for instance, in distmv.Normal, passing in a diagonal covariance matrix (very common).

I believe moving the Solve routines into Cholesky allows this. Cholesky can somehow maintain the inner matrix type, and so when we call chol.SolveVec, we can call the diagonal SolveVec routine (which would be trivial). Similarly, by providing a chol.MulVec, we have now reduced all operations on Normal from N^3 to just O(N), a huge speedup.

I also think if we do this properly, this opens the door for really nice interoperability with sparse matrices. For instance, our current linear programming implementation forces using dense matrices, which means it'll never compete with "real" lp solvers. But, we could create some interface that's like

type LPMatrix struct {
      SolveVec(v, b *Vector) error
      MulVec(a,b *Vector)
}

This interface can now be implemented by Cholesky (for Dense LPs, or structured sparse LPs), and then by some outside/future package that provides those routines for a sparse matrix and Cholesky decomposition.

This is the opportunity I think we can provide with a potentially huge benefit. I'd like to see if we're on the same page.

@kortschak
Copy link
Member Author

kortschak commented Jul 1, 2017 via email

mat/cholesky.go Outdated
// A = U^T * U.
func (t *TriDense) UFromCholesky(chol *Cholesky) {
func (chol *Cholesky) UTo(dst *TriDense) *TriDense {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please unify the name of the receiver.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Done.

@kortschak
Copy link
Member Author

I have not made errorable methods (inverse and solve) able to allocate a destination and return it. This can be done later if people want it.

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

Successfully merging this pull request may close these issues.

None yet

3 participants