Accepting request 1224949 from devel:languages:python:numeric

OBS-URL: https://build.opensuse.org/request/show/1224949
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-pythran?expand=0&rev=21
This commit is contained in:
Ana Guerrero 2024-11-20 15:58:45 +00:00 committed by Git OBS Bridge
commit 4632f56ec3
7 changed files with 21 additions and 222 deletions

View File

@ -1,33 +0,0 @@
From 6b61e8a6b3dddab13b88e51309cbdf2f28247960 Mon Sep 17 00:00:00 2001
From: serge-sans-paille <serge.guelton@telecom-bretagne.eu>
Date: Thu, 22 Aug 2024 08:20:25 +0200
Subject: [PATCH] Fix docstring and implementation of Interval.power
This makes the code more resilient to future numpy changes.
---
pythran/interval.py | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/pythran/interval.py b/pythran/interval.py
index 4e5dff8fd..b8ef42e69 100644
--- a/pythran/interval.py
+++ b/pythran/interval.py
@@ -196,13 +196,15 @@ def __pow__(range1, range2):
>>> Interval(1, 5) ** Interval(-5, -4)
Interval(low=1.0, high=1.0)
>>> Interval(-1, 5) ** Interval(-5, 3)
- Interval(low=-1.0, high=125.0)
+ Interval(low=-1.0, high=125)
>>> Interval(1, 5) ** Interval(3, 8)
- Interval(low=1.0, high=390625.0)
+ Interval(low=1, high=390625)
"""
res = [v1 ** v2 for v1, v2 in
itertools.product(range1.bounds(), range2.bounds())]
- return Interval(numpy.ceil(min(res)), numpy.floor(max(res)))
+ minres, maxres = min(res), max(res)
+ return Interval(type(minres)(numpy.ceil(minres)),
+ type(maxres)(numpy.floor(maxres)))
def __lshift__(range1, range2):
"""

View File

@ -1,105 +0,0 @@
From 9261d30aa9618cb2a5a698d39752263b076f2d4b Mon Sep 17 00:00:00 2001
From: serge-sans-paille <serge.guelton@telecom-bretagne.eu>
Date: Tue, 20 Aug 2024 23:50:55 +0200
Subject: [PATCH] Fix numpy.fix output type
This one changed with recent numpy upgrade, see
https://github.com/numpy/numpy/pull/26766
---
pythran/pythonic/include/numpy/fix.hpp | 17 ++++++++++++++---
pythran/pythonic/numpy/fix.hpp | 6 +++---
pythran/tests/test_numpy_func0.py | 5 +++++
3 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/pythran/pythonic/include/numpy/fix.hpp b/pythran/pythonic/include/numpy/fix.hpp
index 2708930d6c..e4a85a5049 100644
--- a/pythran/pythonic/include/numpy/fix.hpp
+++ b/pythran/pythonic/include/numpy/fix.hpp
@@ -1,18 +1,29 @@
#ifndef PYTHONIC_INCLUDE_NUMPY_FIX_HPP
#define PYTHONIC_INCLUDE_NUMPY_FIX_HPP
-#include "pythonic/include/utils/functor.hpp"
#include "pythonic/include/types/ndarray.hpp"
+#include "pythonic/include/utils/functor.hpp"
#include "pythonic/include/utils/numpy_traits.hpp"
PYTHONIC_NS_BEGIN
namespace numpy
{
+ namespace wrapper
+ {
+ template <class E>
+ E fix(E const &e)
+ {
+ if (std::is_integral<E>::value)
+ return e;
+ else
+ return std::trunc(e);
+ }
+ } // namespace wrapper
#define NUMPY_NARY_FUNC_NAME fix
-#define NUMPY_NARY_FUNC_SYM std::trunc
+#define NUMPY_NARY_FUNC_SYM wrapper::fix
#include "pythonic/include/types/numpy_nary_expr.hpp"
-}
+} // namespace numpy
PYTHONIC_NS_END
#endif
diff --git a/pythran/pythonic/numpy/fix.hpp b/pythran/pythonic/numpy/fix.hpp
index 5b1b020dc2..84773b61cf 100644
--- a/pythran/pythonic/numpy/fix.hpp
+++ b/pythran/pythonic/numpy/fix.hpp
@@ -3,8 +3,8 @@
#include "pythonic/include/numpy/fix.hpp"
-#include "pythonic/utils/functor.hpp"
#include "pythonic/types/ndarray.hpp"
+#include "pythonic/utils/functor.hpp"
#include "pythonic/utils/numpy_traits.hpp"
PYTHONIC_NS_BEGIN
@@ -13,9 +13,9 @@ namespace numpy
{
#define NUMPY_NARY_FUNC_NAME fix
-#define NUMPY_NARY_FUNC_SYM std::trunc
+#define NUMPY_NARY_FUNC_SYM wrapper::fix
#include "pythonic/types/numpy_nary_expr.hpp"
-}
+} // namespace numpy
PYTHONIC_NS_END
#endif
diff --git a/pythran/tests/test_numpy_func0.py b/pythran/tests/test_numpy_func0.py
index 3e11133fec..41f716d900 100644
--- a/pythran/tests/test_numpy_func0.py
+++ b/pythran/tests/test_numpy_func0.py
@@ -1,12 +1,16 @@
import unittest
from pythran.tests import TestEnv
import numpy
+from packaging import version
import tempfile
import os
from pythran.typing import NDArray, List, Tuple
+np_version = version.parse(numpy.version.version)
+
+
class TestNumpyFunc0(TestEnv):
def test_extended_sum0(self):
@@ -910,6 +914,7 @@ def test_flatnonzero1(self):
def test_fix0(self):
self.run_test("def np_fix0(x): from numpy import fix ; return fix(x)", 3.14, np_fix0=[float])
+ @unittest.skipIf(np_version <= version.Version("2.1"), reason="np.fix used to return float on integral input")
def test_fix1(self):
self.run_test("def np_fix1(x): from numpy import fix ; return fix(x)", 3, np_fix1=[int])

View File

@ -1,3 +1,20 @@
-------------------------------------------------------------------
Mon Nov 18 18:01:06 UTC 2024 - Ben Greiner <code@bnavigator.de>
- Update to 0.17.0
* Support parsing annotated statement
* Document and test Meson integration
* Update / improve Blas detection, including scipy-openblas
* Fix usage of Blas library
* Improve error reporting
* Support array module
* Reduce dependency on setuptools
* Faster forward substitution
* Enforce default optimization level to `-O2`
- Drop upstreamed numpy-2.1-interval.patch
- Drop upstreamed numpy-2.1-support.patch
- Drop upstreamed support-gast-0.6.patch
-------------------------------------------------------------------
Sun Sep 1 13:28:40 UTC 2024 - Dirk Müller <dmueller@suse.com>

View File

@ -47,7 +47,7 @@ ExclusiveArch: x86_64
%endif
Name: python-pythran%{psuffix}
Version: 0.16.1
Version: 0.17.0
Release: 0
Summary: Ahead of Time compiler for numeric kernels
License: BSD-3-Clause
@ -55,10 +55,6 @@ URL: https://github.com/serge-sans-paille/pythran
# Tests are only availble from the github archive
Source0: https://github.com/serge-sans-paille/pythran/archive/refs/tags/%{version}.tar.gz#/pythran-%{version}-gh.tar.gz
Source99: python-pythran-rpmlintrc
# PATCH-FIX-UPSTREAM gh#serge-sans-paille/pythran#840a0e706ec39963aec6bcd1f118bf33177c20b4
Patch0: support-gast-0.6.patch
Patch1: https://github.com/serge-sans-paille/pythran/pull/2231/commits/9261d30aa9618cb2a5a698d39752263b076f2d4b.patch#/numpy-2.1-support.patch
Patch2: https://github.com/serge-sans-paille/pythran/commit/6b61e8a6b3dddab13b88e51309cbdf2f28247960.patch#/numpy-2.1-interval.patch
BuildRequires: %{python_module pip}
BuildRequires: %{python_module setuptools}
BuildRequires: %{python_module wheel}

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a2510f370a7d62761844daa112a455785e5a6a216cf9ae704c3926fe68eb65ce
size 3680817

3
pythran-0.17.0-gh.tar.gz Normal file
View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b1f13ca239625579a92bc915bd0abae3747d96063ce55790eead2a072667fcb3
size 3697173

View File

@ -1,76 +0,0 @@
From 840a0e706ec39963aec6bcd1f118bf33177c20b4 Mon Sep 17 00:00:00 2001
From: serge-sans-paille <serge.guelton@telecom-bretagne.eu>
Date: Sat, 29 Jun 2024 19:13:02 +0200
Subject: [PATCH] Bump gast requirement to 0.6.0
This mostly helps for harmonious behavior wrt. gast.dump
---
docs/TUTORIAL.rst | 8 ++++----
pythran/utils.py | 2 +-
requirements.txt | 2 +-
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/docs/TUTORIAL.rst b/docs/TUTORIAL.rst
index 09f6902f9..7692547eb 100644
--- a/docs/TUTORIAL.rst
+++ b/docs/TUTORIAL.rst
@@ -20,7 +20,7 @@ Python ships a standard module, ``ast`` to turn Python code into an AST. For ins
>>> code = "a=1"
>>> tree = ast.parse(code) # turn the code into an AST
>>> print(ast.dump(tree)) # view it as a string
- Module(body=[Assign(targets=[Name(id='a', ctx=Store(), annotation=None, type_comment=None)], value=Constant(value=1, kind=None), type_comment=None)], type_ignores=[])
+ Module(body=[Assign(targets=[Name(id='a', ctx=Store())], value=Constant(value=1, kind=None))])
Deciphering the above line, one learns that the single assignment is parsed as
a module containing a single statement, which is an assignment to a single
@@ -33,7 +33,7 @@ Eventually, one needs to parse more complex codes, and things get a bit more cry
... return n if n< 2 else fib(n-1) + fib(n-2)"""
>>> tree = ast.parse(fib_src)
>>> print(ast.dump(tree))
- Module(body=[FunctionDef(name='fib', args=arguments(args=[Name(id='n', ctx=Param(), annotation=None, type_comment=None)], posonlyargs=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[]), body=[Return(value=IfExp(test=Compare(left=Name(id='n', ctx=Load(), annotation=None, type_comment=None), ops=[Lt()], comparators=[Constant(value=2, kind=None)]), body=Name(id='n', ctx=Load(), annotation=None, type_comment=None), orelse=BinOp(left=Call(func=Name(id='fib', ctx=Load(), annotation=None, type_comment=None), args=[BinOp(left=Name(id='n', ctx=Load(), annotation=None, type_comment=None), op=Sub(), right=Constant(value=1, kind=None))], keywords=[]), op=Add(), right=Call(func=Name(id='fib', ctx=Load(), annotation=None, type_comment=None), args=[BinOp(left=Name(id='n', ctx=Load(), annotation=None, type_comment=None), op=Sub(), right=Constant(value=2, kind=None))], keywords=[]))))], decorator_list=[], returns=None, type_comment=None)], type_ignores=[])
+ Module(body=[FunctionDef(name='fib', args=arguments(args=[Name(id='n', ctx=Param())]), body=[Return(value=IfExp(test=Compare(left=Name(id='n', ctx=Load()), ops=[Lt()], comparators=[Constant(value=2, kind=None)]), body=Name(id='n', ctx=Load()), orelse=BinOp(left=Call(func=Name(id='fib', ctx=Load()), args=[BinOp(left=Name(id='n', ctx=Load()), op=Sub(), right=Constant(value=1, kind=None))]), op=Add(), right=Call(func=Name(id='fib', ctx=Load()), args=[BinOp(left=Name(id='n', ctx=Load()), op=Sub(), right=Constant(value=2, kind=None))]))))])])
The idea remains the same. The whole Python syntax is described in
http://docs.python.org/2/library/ast.html and is worth a glance, otherwise
@@ -199,7 +199,7 @@ constant expressions. In the previous code, there is only two constant
>>> ce = pm.gather(analyses.ConstantExpressions, tree)
>>> sorted(map(ast.dump, ce))
- ["Attribute(value=Name(id='math', ctx=Load(), annotation=None, type_comment=None), attr='cos', ctx=Load())", 'Constant(value=3, kind=None)']
+ ["Attribute(value=Name(id='math', ctx=Load()), attr='cos', ctx=Load())", 'Constant(value=3, kind=None)']
One of the most critical analyse of Pythran is the points-to analysis. There
are two flavors of this analyse, one that computes an over-set of the aliased
@@ -210,7 +210,7 @@ variable, and one that computes an under set. ``Aliases`` computes an over-set::
>>> al = pm.gather(analyses.Aliases, tree)
>>> returned = tree.body[-1].body[-1].value
>>> print(ast.dump(returned))
- Name(id='b', ctx=Load(), annotation=None, type_comment=None)
+ Name(id='b', ctx=Load())
>>> sorted(a.id for a in al[returned])
['c', 'd']
diff --git a/pythran/utils.py b/pythran/utils.py
index 2d7a67327..55a7e8ad6 100644
--- a/pythran/utils.py
+++ b/pythran/utils.py
@@ -106,7 +106,7 @@ def get_variable(assignable):
... slice=ast.Name('j', ast.Load(), None, None),
... ctx=ast.Load())
>>> ast.dump(get_variable(ref))
- "Name(id='a', ctx=Load(), annotation=None, type_comment=None)"
+ "Name(id='a', ctx=Load())"
"""
msg = "Only name and subscript can be assigned."
assert isinstance(assignable, (ast.Name, ast.Subscript)), msg
diff --git a/requirements.txt b/requirements.txt
index fd6a738e5..c7a25c52a 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,5 +1,5 @@
ply>=3.4
setuptools
-gast~=0.5.0
+gast~=0.6.0
numpy
beniget~=0.4.0