Skip to content

Commit bcd0d3b

Browse files
committed
Make xrange a numpy_expr.
1 parent 34b28f1 commit bcd0d3b

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

pythran/pythonic/include/__builtin__/xrange.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ namespace pythonic
5151
using const_iterator = xrange_iterator;
5252
using reverse_iterator = xrange_riterator;
5353
using const_reverse_iterator = xrange_riterator;
54+
using dtype = value_type;
55+
static constexpr bool is_vectorizable = false;
56+
static constexpr size_t value = 1;
5457

5558
long _begin;
5659
long _end;

pythran/pythonic/include/utils/numpy_traits.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ namespace pythonic
1717
}
1818
}
1919

20+
namespace __builtin__
21+
{
22+
struct xrange;
23+
}
24+
2025
namespace types
2126
{
2227

@@ -144,6 +149,10 @@ namespace pythonic
144149
struct is_numexpr_arg<itertools::details::izip<F, V...>> : std::true_type {
145150
};
146151

152+
template <>
153+
struct is_numexpr_arg<__builtin__::xrange> : std::true_type {
154+
};
155+
147156
template <class E>
148157
struct dtype_of {
149158
template <class T>

pythran/tests/test_numpy_func1.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ def np_sum_izip(a):
6666
return np.sum(izip(a, a))
6767
""", range(10), np_sum_izip=[[int]])
6868

69+
def test_sum_xrange(self):
70+
self.run_test("""
71+
def np_sum_xrange(a):
72+
import numpy as np
73+
return np.sum(xrange(a))
74+
""", 10, np_sum_xrange=[int])
75+
6976
def test_prod_(self):
7077
""" Check prod function for numpy array. """
7178
self.run_test("""

0 commit comments

Comments
 (0)