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.

Some ERFA ufuncs do not work with float32

See original GitHub issue

I 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:

https://github.com/astropy/astropy/blob/9bffef18249f802792a81800a44efc038ca3ac4c/astropy/_erfa/ufunc.c.templ#L625-L626

And, in my case, was difficult to spot because iterating by value did work, see #8614.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
astrojuanlucommented, May 26, 2019

Checked, thanks @mhvk @pllim! 👍

0reactions
pllimcommented, May 25, 2019

@Juanlu001 and @kyleaoman , now that #8759 is in master, please check if your use case now works with the latest master. Thanks!

Read more comments on GitHub >

github_iconTop 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 >

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