question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add `__complex__` to array object

See original GitHub issue

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 for array-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.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
leofangcommented, Sep 23, 2022

I think the story for __complex__ is different. In other places, we strive to avoid complex-to-real conversions, but here with __complex__ the direction is different (whatever-to-complex), so I am less concerned.

1reaction
sebergcommented, Oct 7, 2022

IMO it must work for all 0-D inputs covered by the standard (numerical and boolean). Two reasons:

  1. That is how Python does it.
  2. This would be related to casting and thus: real_arr.astype(complex_dtype). That I think must work? (This is not promotion: there are no mixed dtypes involved.)

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Add complex array of objects into another object
How can I have only unique type1 , type2 objects inside final array. const myTransform2 = arr => { // set-up empty arrays...
Read more >
Array methods - The Modern JavaScript Tutorial
Arrays provide a lot of methods. To make things easier, in this chapter they are split into groups. Add/remove items.
Read more >
Array functions - Make
Use the key argument to access properties inside complex objects. To access nested properties, use dot notation. The first item in an array...
Read more >
numpy.ndarray — NumPy v1.24 Manual
An array object represents a multidimensional, homogeneous array of ... Insert scalar into an array (scalar is cast to array's dtype, if possible)....
Read more >
CodeChallenge/Manipulating Complex Objects.md at master
This is an array of objects and the object has various pieces of metadata ... Add artist and title strings , release_year number...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found