-
Notifications
You must be signed in to change notification settings - Fork 50
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
Add __complex__
to array object
#486
Comments
It should be specified for all types where casting to complexes is defined:
|
Yeah that makes sense, my only concern is it might end up looking slightly inconsistent. Currently:
|
I think the story for |
Right now |
It is worth noting that all of these methods coerce an Array to a Python |
As @honno noted we do already have |
+1 for adding
This we don't have to decide here. The spec should simply say that it must work for a 0-D complex array, and follow the type promotion rules for other dtypes. Whether real is going to be required to work is discussed in gh-478, so I suggest not to have that discussion here. |
IMO it must work for all 0-D inputs covered by the standard (numerical and boolean). Two reasons:
I could see a point against boolean, but it seems no worse than for int/float, so unless that is exclused there, it should not be here I think. |
OK, I guess the standard bails on defining |
Indeed, it should be consistent with
That's another reasonable choice I'd say. I think I agree that this is an improvement over what the spec currently says. It does mean that |
Why does it need to be limited to 0-D? We could allow this for any array of |
NumPy is planning to deprecate scalar conversions for higher rank arrays. See numpy/numpy#10404 for a discussion on why it's problematic. |
So I wrote #497 to add what I think is obvious and uncontroversial:
I don't require support for cross-kind casting for any of these casting methods in the PR, although ready to follow-up. It's just a bit annoying to document as there are numerous casting scenarios that need noting (i.e. note allowing bool casting non-bools and require raises for casting unpresentable values). I think it's best to just get the easy stuff in first, so it's simpler to deliberate on awkward things afterwards. |
On the 20th Oct meeting, no one opposed to going beyond unrestricted casting and explicitly support (most) cross-kind casting, emulating how Python's own builtins' cast to different kinds just like NumPy already does. So I'll try summarizing the full extent of Python's cross-kind casting behaviour (I'll write a dirty script to verify edge cases), and update #497 accordingly. Interestingly Athan made the point that the philosophy at least early on is to avoid undefined behaviour and then expand as-and-when necessary, relevant here by usage of "Must" as opposed to "Should" for same-kind inputs. |
We currently have respective dunder methods for bool/ints/floats, so if just for consistency
x.__complex__()
seems nice. Personally I've found the other methods hella useful forarray-api-tests
and Hypothesis, so imagine this will prove useful too.I think we'd want to specify this just for complex-valued floating-point arrays, and adopters can choose to support real-valud float arrays if-and-however they so wish.
The text was updated successfully, but these errors were encountered: