8000 ENH: `cinfo()` for inspecting complex dtypes OR formalise/document complex dtype behaviour in `finfo()` · Issue #22260 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
ENH: cinfo() for inspecting complex dtypes OR formalise/document complex dtype behaviour in finfo() #22260
Closed
@honno

Description

@honno

Proposed new feature or change:

Currently we can use finfo() to get useful information for a single component (i.e. real or imag).

>>> np.finfo(np.complex64)
finfo(resolution=1e-06, min=-3.4028235e+38, max=3.4028235e+38, dtype=float32)
>>> assert np.finfo(np.complex64) == np.finfo(np.float32)

A downside is this feels a bit too implicit, but maybe more importantly is that this isn't documented behaviour (see finfo docs).

For ints we have iinfo() and floats we have finfo(), so how about a cinfo() for complex dtypes? There's an issue for the Array API for such a feature, which has some discussion on what the return info object could actually look like data-apis/array-api#433.

I think the biggest question with a "complex info object" is if it were to have separate attributes per real and imaj components, or just attributes which pertain to both. As the components should always work the same, I would prefer attributes that pertain to both... but as it'd look identical to an finfo()-returned object, personally I'd prefer just having document support of complex dtypes in finfo().

In any case, a formal way of finding info about the real/imag components of complex dtypes would be nice. I came across this need recently when experimenting with complex number support for hypothesis.extra.array_api, where we could easily grab useful info for ints and floats but not for complex numbers, resulting in an preliminary step to infer the relevant float representation of the complex components

if dtype == np.complex64:
    info = np.finfo(np.float32)
else:  # dtype == np.complex128
    info = np.finfo(np.float64)

... I mean not the worst thing in the world, but just didn't feel good! 😅

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0