data-apis / array-api

RFC document, tooling and other content related to the array API standard
https://data-apis.github.io/array-api/latest/
MIT License
205 stars 42 forks source link

`isrealobj()` #738

Closed nschloe closed 5 months ago

nschloe commented 5 months ago

I sometimes perform an operation of two arguments that I know will always return a real-valued object, even if the input arrays are complex-valued. (Think inner products <z, z>.) I usually confirm its realness up to a tolerance and clip off the imaginary part. For return values of real data type, this is not necessary, so I shortcut with

if np.isrealobj(val):
     return val

in NumPy.

Is something similar available in the Array API yet?

lucascolley commented 5 months ago

You can do xp.isdtype(val.dtype, 'real floating').

nschloe commented 5 months ago

That works, thanks!