Closed theXYZT closed 3 years ago
Hi @theXYZT, thanks for reporting this.
I think you may have found something a bit more subtle that just a warning. It looks like that we use np.all(np.isreal(xx)):
to check if an array has complex numbers and in that case compute its abs value before passing it to oneprojector
. However np.isreal(np.array(np.ones(4)+1j*np.zeros(4)))
gives True which matematically makes sense but it doesnt do what we want. I changed all not np.all(np.isreal(xx))
into np.iscomplexobj(x)
and the Warning is now gone :)
Basically in your problem the data is complex valued so when the code enters oneprojector
the first thing that this routines does is:
s = np.sign(b)
b = np.abs(b)
Now b
is complex valued but the sign of a complex-value number is not uniquely defined. Numpy seems to use this convention: For complex inputs, the
signfunction returns``sign(x.real) + 0j if x.real != 0 else sign(x.imag) + 0j``.
. But we should have never got to the point if we stopped complex array to pass through :)
I am trying to use SPGL1 and noticed that line 204 of
spgl1.py
throws a ComplexWarning over dtype casting when running complex-valued problems: https://github.com/drrelyea/spgl1/blob/master/spgl1/spgl1.py#L204Here's a toy example (a simple noisy DFT):
This returns the output:
The printed output reveals that the problem was solved correctly (I get the expected coefficient at the right spot). But this also returns a ComplexWarning that might be worth dealing with in case it leads to unintended effects down the road.