Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python3-numpy: update to 1.25.0. #44529

Merged
merged 1 commit into from
Jun 26, 2023
Merged

python3-numpy: update to 1.25.0. #44529

merged 1 commit into from
Jun 26, 2023

Conversation

tornaria
Copy link
Contributor

Testing the changes

  • I tested the changes in this PR: briefly

I enabled check, and I'm currently testing with sagemath to see what fails and fix it. So far I've only tried x86_64.

I didn't change the build-style to pep517 because that won't allow parallel build. For testing, a custom do_check() is needed in any case. Moreover, it seems numpy will soon move to meson for building so we may as well wait for that.

@ahesford

Copy link
Member

@ahesford ahesford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that moving to the pep517 build style is a waste of time. We'll have to move to meson for Python 3.12 anyway, it seems. In the meantime, let's stick with what works.

srcpkgs/python3-numpy/template Outdated Show resolved Hide resolved
@tornaria
Copy link
Contributor Author

$ sage -tp 8 --all
[...]
----------------------------------------------------------------------
sage -t --warn-long 4.0 --random-seed=305131057254283109728703750079119927823 /usr/lib/python3.11/site-packages/sage/plot/plot3d/plot3d.py  # 1 doctest failed
sage -t --warn-long 4.0 --random-seed=305131057254283109728703750079119927823 /usr/lib/python3.11/site-packages/sage/matrix/matrix2.pyx  # 1 doctest failed
sage -t --warn-long 4.0 --random-seed=305131057254283109728703750079119927823 /usr/lib/python3.11/site-packages/sage/calculus/desolvers.py  # 2 doctests failed
sage -t --warn-long 4.0 --random-seed=305131057254283109728703750079119927823 /usr/lib/python3.11/site-packages/sage/stats/distributions/discrete_gaussian_lattice.py  # 1 doctest failed
sage -t --warn-long 4.0 --random-seed=305131057254283109728703750079119927823 /usr/lib/python3.11/site-packages/sage/plot/plot3d/list_plot3d.py  # 5 doctests failed
sage -t --warn-long 4.0 --random-seed=305131057254283109728703750079119927823 /usr/lib/python3.11/site-packages/sage/matrix/matrix_numpy_dense.pyx  # 1 doctest failed
----------------------------------------------------------------------

I'll try to fix those, nothing seems too bad. Ideally we would wait until sagemath is fixed to push the numpy update.

@tornaria
Copy link
Contributor Author

i686 and musl failed, I will work on them locally before I resubmit the PR.

@tornaria
Copy link
Contributor Author

musl is this single failure:

2023-06-20T02:42:42.2859874Z ___________________ TestComplexFunctions.test_against_cmath ____________________
2023-06-20T02:42:42.2860557Z [gw1] linux -- Python 3.11.4 /usr/bin/python3
2023-06-20T02:42:42.2919785Z 
2023-06-20T02:42:42.2922623Z self = <numpy.core.tests.test_umath.TestComplexFunctions object at 0x7f525a4471d0>
2023-06-20T02:42:42.2925068Z 
2023-06-20T02:42:42.2927330Z     def test_against_cmath(self):
2023-06-20T02:42:42.2929736Z         import cmath
2023-06-20T02:42:42.2932080Z     
2023-06-20T02:42:42.2934650Z         points = [-1-1j, -1+1j, +1-1j, +1+1j]
2023-06-20T02:42:42.2937220Z         name_map = {'arcsin': 'asin', 'arccos': 'acos', 'arctan': 'atan',
2023-06-20T02:42:42.2940138Z                     'arcsinh': 'asinh', 'arccosh': 'acosh', 'arctanh': 'atanh'}
2023-06-20T02:42:42.2942626Z         atol = 4*np.finfo(complex).eps
2023-06-20T02:42:42.2945045Z         for func in self.funcs:
2023-06-20T02:42:42.2947527Z             fname = func.__name__.split('.')[-1]
2023-06-20T02:42:42.2950099Z             cname = name_map.get(fname, fname)
2023-06-20T02:42:42.2952604Z             try:
2023-06-20T02:42:42.2954975Z                 cfunc = getattr(cmath, cname)
2023-06-20T02:42:42.2957354Z             except AttributeError:
2023-06-20T02:42:42.2959699Z                 continue
2023-06-20T02:42:42.2962246Z             for p in points:
2023-06-20T02:42:42.2964704Z                 a = complex(func(np.complex_(p)))
2023-06-20T02:42:42.2967207Z                 b = cfunc(p)
2023-06-20T02:42:42.2969730Z >               assert_(abs(a - b) < atol, "%s %s: %s; cmath: %s" % (fname, p, a, b))
2023-06-20T02:42:42.2972367Z E               AssertionError: arccosh (-1-1j): (-1.0612750619050357+2.2370357592874117j); cmath: (1.0612750619050357-2.237035759287412j)
2023-06-20T02:42:42.2974705Z 
2023-06-20T02:42:42.2976981Z a          = (-1.0612750619050357+2.2370357592874117j)
2023-06-20T02:42:42.2979401Z atol       = 8.881784197001252e-16
2023-06-20T02:42:42.2981835Z b          = (1.0612750619050357-2.237035759287412j)
2023-06-20T02:42:42.2984234Z cfunc      = <built-in function acosh>
2023-06-20T02:42:42.2986844Z cmath      = <module 'cmath' from '/usr/lib/python3.11/lib-dynload/cmath.cpython-311-x86_64-linux-musl.so'>
2023-06-20T02:42:42.2989329Z cname      = 'acosh'
2023-06-20T02:42:42.2991685Z fname      = 'arccosh'
2023-06-20T02:42:42.2992415Z func       = <ufunc 'arccosh'>
2023-06-20T02:42:42.2993001Z name_map   = {'arccos': 'acos', 'arccosh': 'acosh', 'arcsin': 'asin', 'arcsinh': 'asinh', ...}
2023-06-20T02:42:42.2993512Z p          = (-1-1j)
2023-06-20T02:42:42.2993981Z points     = [(-1-1j), (-1+1j), (1-1j), (1+1j)]
2023-06-20T02:42:42.2994496Z self       = <numpy.core.tests.test_umath.TestComplexFunctions object at 0x7f525a4471d0>
2023-06-20T02:42:42.2994903Z 
2023-06-20T02:42:42.2995196Z numpy/core/tests/test_umath.py:4161: AssertionError

Can reproduce with:

$ python -c 'import cmath, numpy; print(cmath.acosh(-1-1j),numpy.arccosh(-1-1j))'
(1.0612750619050357-2.237035759287412j) (-1.0612750619050357+2.2370357592874117j)

Indeed this is "incorrect" since it should choose a branch with positive real part (i.e cmath output is ok, numpy output is incorrect).

Note this is also wrong in the 1.24.3 that is in void repo (but only on musl).

@tornaria
Copy link
Contributor Author

Actually, this seems like a bug in musl libm:

$ cat cacosh.c 
#include <complex.h>
#include <stdio.h>

void main()
{
    double complex z = -1 -I, c;

    c = cacosh(z);

    printf("cacosh(z) = %6.3f %6.3f*i\n", creal(c), cimag(c));
}
$ cc cacosh.c -o cacosh -lm && ./cacosh                          
cacosh(z) = -1.061  2.237*i

Note that cacosh(3p) says:

RETURN VALUE
       These functions shall return the complex arc hyperbolic cosine value,
       in the range of a half-strip of non-negative values along the real axis
       and in the interval [-iπ, +iπ] along the imaginary axis.

For whatever reason cmath.acosh is not catching this error (probably because it's not using C99 complex trig functions but reimplementing them from C89 real functions).

@tornaria
Copy link
Contributor Author

See here: https://git.musl-libc.org/cgit/musl/commit/?id=aa2d23e57c9c95f0ffeb80cb035e5a5be52d8ef0

I didn't try it but it seems like that would do the trick; I'm guessing our musl is older than this commit.

@ahesford
Copy link
Member

Don't worry about this failure; we can just ignore it for now.

@tornaria
Copy link
Contributor Author

I have worked out the issues with sage; I will soon make a PR for an updated sagemath 10.0 patched with support for maxima 5.47.0, singular 4.3.2p2 and numpy 1.25.0 (which are the 3 updates that break it slightly).

Ideally this PR should wait until sagemath is patched.

@tornaria
Copy link
Contributor Author

This can be merged after #44624.

@ahesford ahesford merged commit 2035433 into void-linux:master Jun 26, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants