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

Weird behavior of exponentiate when trying to use inplace behavior #89

Closed
DavidWellnitz opened this issue Jun 7, 2024 · 4 comments
Closed

Comments

@DavidWellnitz
Copy link

DavidWellnitz commented Jun 7, 2024

I am trying to use exponentiate to compute a matrix exponential of an inplace defined function. The simplest way to reproduce the problem which I found is

exponentiate(x -> x, 1, ones(2))

which returns [3.95..., 3.95...] instead of [2.71..., 2.71...]. In contrast

exponentiate(x -> deepcopy(x), 1, ones(2))

works fine. Is there a reason why method 1 should not work?

@Jutho
Copy link
Owner

Jutho commented Jun 7, 2024

Yes, KrylovKit currently assumes that applying the operator creates a result that is memorywise independent from the input. If at some point inplace operators would be supported, it would be with two-argument versions f!(y, x) where the result is stored iny. I might be mistaken, but in my typical applications, there would be very few linear operators where it would make sense to apply them inplace in the sense of overwriting the input.

@DavidWellnitz
Copy link
Author

There is probably a way around it. I had originally written an inplace function to use with DifferentialEquations, but when I realized my problem is linear, I thought KrylovKit should be more efficient (and it seems to be). I was wondering if there is a way to pre-allocate the output vector (in the way you suggested), in order to improve efficiency, but from your comment that seems to not be the case.

@Jutho
Copy link
Owner

Jutho commented Jun 11, 2024

Can I close this? Supporting in place functions and reducing memory allocation is certainly on the TODO list so I don't think this needs to stay open as an extra reminder.

@DavidWellnitz
Copy link
Author

Yes, go ahead!

@Jutho Jutho closed this as completed Jun 11, 2024
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

2 participants