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
Support complex data in NumpyVectorArray / NumpyMatrixOperator #131
Comments
Just from a quick glance I would suggest to rather change the initialization than the operations, since there is often good reason to use |
I tend to agree with @ftalbrecht that in your first example the best solution would be to have all matrices have complex dtype in the first place. Of course, this throws away memory and involves some performance penalty. @pmli, would doing so be a serious issue for you? For the second example: I guess we need a more systematic approach for handling complex data. We could do so by adding the dtype to the subtype of NumpyVectorArray. However, this would again raise the issue if I am allowed to apply an operator with source subtype '(complex, dim)' to an array with source subtype '(float, dim)'. (See our discussion in #56.) If we decide to add the dtype to the subtype (which sounds reasonable to me), there seem to be two ways to go:
|
Regarding the first example: I think the memory efficiency depends on numpys implementation of |
@ftalbrecht, I am not sure if I understand your comment. If operators[0]._matrix if stored as complex even though it is real, we need twice as much memory ... |
Ah, sorry for not being clear enough! Consider the All I propose is
If any of the I do not propose to just store all matrices as complex (or convert them)... |
I agree with @ftalbrecht, I would prefer to only use complex values when necessary. @sdrave About dtype as subtype, multiplying a real matrix and a complex vector and vice versa both make sense, and both can occur in practice. Also: |
Ok, so after some sleep, I agree that we probably should not overengineer things. If we get everything working with some additional checks, we should go that route. However, I am not sure if I am aware of all consequences. My proposal would therefore be to make some tweaks in the |
@pmli, pull requests are always appreciated. I do not have any code here working with complex numbers ... |
Sounds reasonable, agreed! |
Sounds good! |
I've made some changes in the complex branch for NumpyMatrixOperator and NumpyVectorArray. Now I'm wondering about scalar products ( |
I know that some libraries support both scalar products (with complex conjugation and without). As I do not see a lot of use for the variant without conjugation, I would say the conjugation should always be performed. And, yes of course, scalar products are antilinear in the second variable! 😀 |
Ok 😃 While working with vector arrays, I noticed that it would be nice if they had |
I think that having |
Looking at the examples in NumPy docs, it seems that |
Regarding |
@sdrave No, I don't have use cases when I need references (I never change real or imaginary part), and I would prefer to work with copies. |
Copies would also make it easier to support |
@pmli, I have just rebased the complex branch on current pyMOR master. Could you take another look if the branch contains all the changes you need? If so, I would take one more look at performance and then merge .. |
@sdrave I no longer have |
I have just merged the 'complex_merge' branch into master. |
The issue is that Numpy/Scipy doesn't allow a matrix to change type inplace, so a
ComplexWarning: Casting complex values to real discards the imaginary part
is raised in several places:in
NumpyMatrixOperator.assemble_lincomb
in the line withwhen the first coefficient is real and some later one is complex.
Options here would be to use
or do a check at the beginning and initialize
matrix
appropriately (or always put complex coefficients first).in
pymor.operators.numpy._apply_inverse
in the line withThe problem is that
R
is initialized withAn option here would be to add
dtype=complex
innp.empty
ifmatrix
orV
is complex.The text was updated successfully, but these errors were encountered: