aesara-devs / aesara

Aesara is a Python library for defining, optimizing, and efficiently evaluating mathematical expressions involving multi-dimensional arrays.

Home Page:https://aesara.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DeprecationWarning: numpy conversion of out-of-bound python integers

eganster opened this issue · comments

After a fresh install of aesara (in a new venv) I started noticing DeprecationWarnings from numpy regarding out-of-bound conversion of python integers.
I'm pretty sure that this is related/started with NumPy 1.24: https://numpy.org/doc/stable/release/1.24.0-notes.html#conversion-of-out-of-bound-python-integers

>>> import warnings
>>> warnings.filterwarnings('always', category=DeprecationWarning)
>>> from aesara import tensor
>>> tensor.gt(127, 2)
Elemwise{gt,no_inplace}.0
>>> tensor.gt(128, 2)
/home/USER/virtualenvs/test/lib/python3.10/site-packages/aesara/misc/safe_asarray.py:35: DeprecationWarning: NumPy will stop allowing conversion of out-of-bound Python integers to integer arrays.  The conversion of 128 to int8 will fail in the future.
For the old behavior, usually:
    np.array(value).astype(dtype)`
will give the desired result (the cast overflows).
  rval = np.asarray(a, dtype=dtype, order=order)
Elemwise{gt,no_inplace}.0
>>> tensor.gt(32768, 2)
/home/USER/virtualenvs/test/lib/python3.10/site-packages/aesara/misc/safe_asarray.py:35: DeprecationWarning: NumPy will stop allowing conversion of out-of-bound Python integers to integer arrays.  The conversion of 32768 to int8 will fail in the future.
For the old behavior, usually:
    np.array(value).astype(dtype)`
will give the desired result (the cast overflows).
  rval = np.asarray(a, dtype=dtype, order=order)
/home/USER/virtualenvs/test/lib/python3.10/site-packages/aesara/misc/safe_asarray.py:35: DeprecationWarning: NumPy will stop allowing conversion of out-of-bound Python integers to integer arrays.  The conversion of 32768 to int16 will fail in the future.
For the old behavior, usually:
    np.array(value).astype(dtype)`
will give the desired result (the cast overflows).
  rval = np.asarray(a, dtype=dtype, order=order)
Elemwise{gt,no_inplace}.0

Versions and main components

  • Aesara version: 2.8.12
  • Python version: 3.10
  • Operating system:
  • How did you install Aesara: pip

This is generally related to the casting policy settings (see here in the documentation). It's worth trying the same things under the "numpy+floatX" setting.

I'll take a look at this particular situation to see if it's being handled correctly (e.g. behaving like NumPy when the casting policy says it should). As well, I'm sure there is some important information missing from the docs that we'll need to add.

Thanks, changing the casting policy helped, I do not see the DeprecationWarning anymore!