3

While using NumPy, I have noticed that it supports np.float16 but there is no np.complex32. Why is it so? Low priority feature planned for a future release? Is there a straightforward way to implement a complex representation based on np.float16 that I am ignoring?

I was not able to find much online about this. Thanks!

E.g., the following code works for a, but fails for b.

import numpy as np

a = np.array([0, 1], dtype=np.float16)
print(a)

b = np.array([0, 1], dtype=np.complex32)
print(b)

Mark Dickinson
  • 29,088
  • 9
  • 83
  • 120
kl31n
  • 31
  • 1
  • 2
  • 2
    If I had to guess, it's because float16 is already a huge PITA to implement, and no one ever needed complex32 bad enough to do anything about it. You can implement your own dtype with two half elements, but you'd have to do all the complex stuff manually. – Mad Physicist Dec 04 '19 at 06:35
  • See https://github.com/numpy/numpy/issues/14753. Also https://stackoverflow.com/questions/56777807/why-is-half-precision-complex-float-arithmetic-not-supported-in-python-and-cuda – Mark Dickinson Dec 04 '19 at 08:07
  • Thanks, Mark! I was aware of the StackOverflow discussion at the URL you mentioned, but the GitHub thread is new. Unfortunately, I do not see support for complex32 in the NumPy roadmap (here: https://numpy.org/neps/roadmap.html). – kl31n Dec 05 '19 at 01:01

0 Answers0