Some ERFA ufuncs do not work with float32
See original GitHub issueI found one particular function in ERFA which does not accept float32 values, although there are probably more:
In [3]: xyz = np.array([[1, 0, 0], [0.9, 0.1, 0]])
In [4]: _erfa.p2s(xyz)
Out[4]:
(array([0. , 0.11065722]),
array([0., 0.]),
array([1. , 0.90553851]))
In [5]: _erfa.p2s(xyz.astype(np.float32))
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-5-cbd078a35d7c> in <module>()
----> 1 _erfa.p2s(xyz.astype(np.float32))
~/.miniconda36/envs/py37/lib/python3.7/site-packages/astropy/_erfa/core.py in p2s(p)
18187
18188 """
> 18189 theta, phi, r = ufunc.p2s(p)
18190 return theta, phi, r
18191
RuntimeError: no relevant input found; should not happen!
This issue manifests itself in quite strange ways:
In [97]: icrs = ICRS(CartesianRepresentation(xyz.astype(np.float32), xyz_axis=-1, unit="km"))
In [98]: q = icrs.spherical
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-98-73fe0562a4ab> in <module>()
----> 1 q = icrs.spherical
~/.miniconda36/envs/py37/lib/python3.7/site-packages/astropy/coordinates/baseframe.py in spherical(self)
1661 # TODO: if representations are updated to use a full transform graph,
1662 # the representation aliases should not be hard-coded like this
-> 1663 return self.represent_as('spherical', in_frame_units=True)
1664
1665 @property
~/.miniconda36/envs/py37/lib/python3.7/site-packages/astropy/coordinates/baseframe.py in represent_as(self, base, s, in_frame_units)
1072 diff = data.differentials['s'] # TODO: assumes velocity
1073 else:
-> 1074 data = self.data.represent_as(representation_cls)
1075
1076 # If the new representation is known to this frame and has a defined
~/.miniconda36/envs/py37/lib/python3.7/site-packages/astropy/coordinates/representation.py in represent_as(self, other_class, differential_class)
688 if other_class is not self.__class__:
689 # The default is to convert via cartesian coordinates
--> 690 new_rep = other_class.from_cartesian(self.to_cartesian())
691 else:
692 new_rep = self
~/.miniconda36/envs/py37/lib/python3.7/site-packages/astropy/coordinates/representation.py in from_cartesian(cls, cart)
1664 p = cart.get_xyz(xyz_axis=-1)
1665 # erfa p2s: P-vector to spherical polar coordinates.
-> 1666 return cls(*erfa_ufunc.p2s(p), copy=False)
1667
1668 def norm(self):
~/.miniconda36/envs/py37/lib/python3.7/site-packages/astropy/units/quantity.py in __array_ufunc__(self, function, method, *inputs, **kwargs)
461
462 # Call our superclass's __array_ufunc__
--> 463 result = super().__array_ufunc__(function, method, *arrays, **kwargs)
464 # If unit is None, a plain array is expected (e.g., comparisons), which
465 # means we're done.
RuntimeError: no relevant input found; should not happen!
which comes from here:
And, in my case, was difficult to spot because iterating by value did work, see #8614.
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Have coordinate transformations preserve (float?) dtypes #8870
The way ufuncs work, float32 gets automatically converted to double and then ... I agree that for some erfa routines it really should...
Read more >I am trying to import another function from another module but ...
Hi, I am not importing a library though, I am trying to import another module that I created in the project. What would...
Read more >Full Changelog — PyERFA v2.0.0.2.dev13+gfb1f520
The underlying universal functions in erfa.ufunc now work with an out argument ... to give specific output file names has been removed, as...
Read more >Source code for astropy.time.formats
This is done both to speed up parsing of strings and to allow mixed formats where strptime does not quite work well enough....
Read more >Full Changelog — Astropy v1.0.4
[#3873]; Ensure in-place operations on float32 quantities work. ... The deprecated decorator did not correctly wrap classes that have a ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Checked, thanks @mhvk @pllim! 👍
@Juanlu001 and @kyleaoman , now that #8759 is in
master
, please check if your use case now works with the latestmaster
. Thanks!