Skip to content

Commit

Permalink
Correctly handle overlapping detection between gexpr and vexpr
Browse files Browse the repository at this point in the history
Fix #2158
  • Loading branch information
serge-sans-paille committed Dec 12, 2023
1 parent 3529a55 commit 011a3a6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pythran/pythonic/types/numpy_gexpr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ namespace types
return false;
}

template <class E0, class E1, class E2>
bool may_overlap(E0 const &e0, types::numpy_vexpr<E1, E2> const &e1)
{
return may_overlap(e0, e1.data_);
}

template <class E0, class Op, class... Args, size_t... Is>
bool may_overlap(E0 const &e0, types::numpy_expr<Op, Args...> const &e1,
utils::index_sequence<Is...>)
Expand Down
19 changes: 19 additions & 0 deletions pythran/tests/test_ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,25 @@ def test_gexpr_composition22(self):
30,
gexpr_composition22=[int])

def test_gexpr_vexpr0(self):
self.run_test("def gexpr_vexpr0(x, y): x[1:3] = x[y]",
numpy.arange(10), numpy.array([0, 1]),
gexpr_vexpr0=[NDArray[int,:], NDArray[int, :]])

def test_gexpr_vexpr1(self):
self.run_test("def gexpr_vexpr1(x, y): x[1:3] = y[y]",
numpy.arange(10), numpy.array([0, 1]),
gexpr_vexpr1=[NDArray[int,:], NDArray[int, :]])

def test_gexpr_baseid0(self):
self.run_test("def gexpr_baseid0(x, y): x[1:3] = y[0]",
numpy.arange(10), numpy.array([[0, 1]]),
gexpr_baseid0=[NDArray[int,:], NDArray[int, :, :]])

def test_gexpr_baseid1(self):
self.run_test("def gexpr_baseid1(x, y): x[:] = y.T",
numpy.arange(4).reshape(2,2), numpy.array([[0, 1], [2, 3]]),
gexpr_baseid1=[NDArray[int,:,:], NDArray[int, :, :]])

def test_gexpr_copy0(self):
self.run_test("def gexpr_copy0(a,b): a[:,0] = b[:,0]; return a",
Expand Down

0 comments on commit 011a3a6

Please sign in to comment.