Skip to content

Numpy 1.18 from conda ignores __array_function__ override on Windows #15378

Closed

Description

@pllim

Reproducing code example:

This code snippet was provided by @mhvk in astropy/astropy#9871 (comment)

import numpy as np

class A:
   def __array_function__(self, *args, **kwargs):
        return 'Ha!'

np.fft.fft(A())
# 'Ha!'

Error message:

Using Numpy 1.18.1 installed from the defaults channel from conda under a clean Python 3.7 environment on Windows:

~\Miniconda3\envs\test-conda-numpy\lib\site-packages\mkl_fft\_numpy_fft.py in ff
t(a, n, axis, norm)
    158     """
    159     x = _float_utils.__downcast_float128_array(a)
--> 160     output = mkl_fft.fft(x, n, axis)
    161     if _unitary(norm):
    162         output *= 1 / sqrt(output.shape[axis])

mkl_fft\_pydfti.pyx in mkl_fft._pydfti.fft()

mkl_fft\_pydfti.pyx in mkl_fft._pydfti._fft1d_impl()

mkl_fft\_pydfti.pyx in mkl_fft._pydfti.__process_arguments()

ValueError: Invalid axis (-1) specified.

For more information, please see astropy/astropy#9871

Numpy/Python version information:

  • Windows 10
  • Miniconda
  • Python 3.7
  • Numpy 1.18.1

Activity

  1. rgommers commented on Jan 21, 2020

    @rgommers
    Member

    This is a known issue, since mkl-fft monkeypatches numpy.fft.

    Not much to be done here except avoiding installing mkl-fft if you rely on __array_function__.

    Also note that this monkeypatching predates the introdunction of __array_function__, and we've discussed with the MKL authors switching away from it. Pyfftw monkeypatched in the same way back then (and probably still does). The consensus at that point was that we need a backend system for numpy.fft. Which is something that _array_function__ is not.

  2. rgommers commented on Jan 21, 2020

    @rgommers
    Member
  3. rgommers commented on Jan 21, 2020

    @rgommers
    Member

    Actually there's one difference: Pyfftw does the monkeypatching on import: https://github.com/hgomersall/pyFFTW/blob/master/pyfftw/interfaces/numpy_fft.py

    mkl-fft in this case, according to the report, overwrites at install time. That's something Anaconda has said they'd get rid of.

  4. pllim commented on Jan 21, 2020

    @pllim
    ContributorAuthor

    FWIW when we pinned to Numpy 1.17 in conda, the error went away.

    And for the record, this is not blocking anything on Astropy, as we have workarounds such as:

    • Install Numpy from PyPI
    • Install Numpy from conda-forge, which is still 1.17
    • Pin Numpy to 1.17 if we must grab it from the defaults channel
  5. rgommers commented on Jan 21, 2020

    @rgommers
    Member

    Hmm, then Anaconda undid the fixes of this "Intel patches" stuff probably. Unclear if on purpose or by accident. https://github.com/ContinuumIO/anaconda-issues/issues is the right place to complain about that. If you want to do that, that'd be very welcome. Otherwise I can do it tomorrow.

  6. pllim commented on Jan 21, 2020

    @pllim
    ContributorAuthor

    Okay, also reported to ContinuumIO/anaconda-issues#11568

  7. mhvk commented on Jan 21, 2020

    @mhvk
    Contributor

    Thanks all! It just goes to show that monkey-patching a distribution is really bad form, wasting time that could be better spend solving real problems. With the bottom line that we have now changed all our documentation to suggesting to just use pip instead of conda, which surely was not the hope.

    Anyway, the backend option would be one very nice way to solve this.

  8. rgommers commented on Jan 22, 2020

    @rgommers
    Member

    You could also recommend conda-forge, which is anyway starting to get the more attractive alternative. Given conda's performance problems, the full Anaconda install should be for beginners only - and once you use Miniconda, may as well go all in on conda-forge.

  9. rgommers commented on Jan 22, 2020

    @rgommers
    Member

    There'll be new packages in defaults with the offending fft (and random) patches removed:)

  10. pllim commented on Jan 22, 2020

    @pllim
    ContributorAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions