Skip to content

Add InverseMap for lazy inverse of a linear map. #184

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

Merged
merged 1 commit into from
Jun 24, 2022
Merged

Conversation

fredrikekre
Copy link
Member

@codecov
Copy link

codecov bot commented Jun 21, 2022

Codecov Report

Merging #184 (9d67671) into master (99bbc0e) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 9d67671 differs from pull request most recent head 63f290f. Consider uploading reports for the commit 63f290f to get more accurate results

@@           Coverage Diff           @@
##           master     #184   +/-   ##
=======================================
  Coverage   98.60%   98.61%           
=======================================
  Files          16       17    +1     
  Lines        1365     1373    +8     
=======================================
+ Hits         1346     1354    +8     
  Misses         19       19           
Impacted Files Coverage Δ
src/LinearMaps.jl 100.00% <ø> (ø)
src/inversemap.jl 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 99bbc0e...63f290f. Read the comment docs.

@fredrikekre fredrikekre force-pushed the fe/inverse-map branch 2 times, most recently from 9d67671 to c75d541 Compare June 21, 2022 20:25
@fredrikekre fredrikekre requested a review from dkarrasch June 21, 2022 20:25
Copy link
Member

@dkarrasch dkarrasch left a comment

Choose a reason for hiding this comment

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

Thanks for that very nice contribution! I have a few requests:

  • Could you please add a short feature announcement in the history.md, perhaps together with the two verbal examples from the docstring: factorization and ldiv!, or LinearMap and iterative solver.
  • Speaking of these two use cases, it would be nice to add two such examples to the title page of the documentation, where we currently briefly demonstrate how to use iterative eigensolvers.
  • This PR currently adds very few methods for InverseMap, and therefore relies on many generic fallbacks: issymmetric, ishermitian, isposdef, transpose and adjoint. I wonder if we can do a little better. The first three should inherit that property from A; transpose and adjoint can be thrown on A because inversion and transposition commute. It would be good then to test that these work properly under multiplication.

@fredrikekre
Copy link
Member Author

Thanks for the review, I think I updated everything (also took the liberty to bump the version number).

@fredrikekre fredrikekre force-pushed the fe/inverse-map branch 3 times, most recently from 85c65b7 to 8cd2807 Compare June 22, 2022 13:24
@dkarrasch
Copy link
Member

Should we add a little convenience with

InverseMap(A::AbstractMatrix) = InverseMap(factorize(A))

? I know it may not work in all cases, but as a default maybe not too bad?

@fredrikekre
Copy link
Member Author

fredrikekre commented Jun 22, 2022

I thought about it too. However, ldiv! itself doesn't support it deliberately and forces you to factorize yourself (I can't find a reference to this now, but I believe that method even threw a descriptive error message about this in some version of Julia). Maybe the same argumentation doesn't apply here though.

Edit:
And also, that would remove some control from the user, and wouldn't let you do e.g.

iA = InverseMap(A::AbstractMatrix; solver=IterativeSolvers.cg!)

since that would try to factorize A.

Edit 2: I guess you could do

iA = InverseMap(LinearMap(A::AbstractMatrix); solver=IterativeSolvers.cg!)

to avoid it, but I feel like it is better to ask the user to provide an appropriate factorization.

@fredrikekre fredrikekre force-pushed the fe/inverse-map branch 2 times, most recently from 2071753 to d3d46db Compare June 22, 2022 19:08
@dkarrasch
Copy link
Member

That's all true. Also, implicit conversion/modification is not done anywhere in this package (only wrapping), and factorize is even an expensive operation, so that was a pretty stupid idea of mine. 🤦

@fredrikekre fredrikekre force-pushed the fe/inverse-map branch 3 times, most recently from 42209e3 to 6d777a9 Compare June 23, 2022 10:07
@fredrikekre
Copy link
Member Author

I added some tests for 3- and 5 arg mul! too.

@dkarrasch
Copy link
Member

Thanks Fredrik once again. The tests are awesome, especially the last test example which showcases the seamless integration with IterativeSolvers.jl nicely. I wonder if we should make that one more visible? Otherwise this is good to go.

@fredrikekre
Copy link
Member Author

It is basically the same as the example I included on the index page. I can expand on it I suppose.

@dkarrasch
Copy link
Member

I liked the extra preconditioner bit and the "context", i.e., the comparison to the original blocked problem. But I guess you're right. That relates more to IterativeSolvers.jl, and interested users will very likely know that context anyway.

@fredrikekre
Copy link
Member Author

I'm happy to write a more comprehensive example, but doesn't feel like it fits on the index page where you just quickly want to showcase the package.

@dkarrasch
Copy link
Member

If you don't mind the effort, then you could perhaps add a new page to the documentation on which we demonstrate in some more detail "advanced applications" (or something like this). That would be cool. The "original" blocked operator, for instance, could be built both as a matrix or as a LinearMap (the latter may be advantageous when the building matrices are of very inhomogeneous type, sparse and dense etc.). There are a few other nice applications that we don't demonstrate, that users need to see themselves by looking at the bare offered functionality/docstrings.

@dkarrasch
Copy link
Member

@fredrikekre I think I was asking for too much. Let's keep the PR as is. We should pursuit the tutorial idea further, but perhaps first collect ideas on how to do it and what to present. One option could be to keep the presentation short and reference downstream packages. Another option could be to present some nice examples explicitly and in detail without necessarily being relevant in concrete use cases. In any case, I think some more thought is required on how to make it useful.

@fredrikekre
Copy link
Member Author

I started on it already, but I will make a follow up PR instead then :)

@fredrikekre fredrikekre merged commit 710a0d3 into master Jun 24, 2022
@fredrikekre fredrikekre deleted the fe/inverse-map branch June 24, 2022 09:42
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.

2 participants