Skip to content

Commit

Permalink
array module support: reverse()
Browse files Browse the repository at this point in the history
  • Loading branch information
serge-sans-paille committed Aug 23, 2024
1 parent 1251fd3 commit c11caeb
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pythran/pythonic/__dispatch__/reverse.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef PYTHONIC_DISPATCH_REVERSE_HPP
#define PYTHONIC_DISPATCH_REVERSE_HPP

#include "pythonic/include/__dispatch__/reverse.hpp"

#include "pythonic/utils/functor.hpp"

#include <algorithm>

PYTHONIC_NS_BEGIN

namespace __dispatch__
{

template <class Any>
types::none_type reverse(Any &&any)
{
std::reverse(any.begin(), any.end());
return {};
}
} // namespace __dispatch__
PYTHONIC_NS_END

#endif
18 changes: 18 additions & 0 deletions pythran/pythonic/include/__dispatch__/reverse.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef PYTHONIC_INCLUDE_DISPATCH_REVERSE_HPP
#define PYTHONIC_INCLUDE_DISPATCH_REVERSE_HPP

#include "pythonic/include/utils/functor.hpp"

PYTHONIC_NS_BEGIN

namespace __dispatch__
{

template <class Any>
types::none_type reverse(Any &&any);

DEFINE_FUNCTOR(pythonic::__dispatch__, reverse);
} // namespace __dispatch__
PYTHONIC_NS_END

#endif
2 changes: 2 additions & 0 deletions pythran/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def update_effects(self, node):
"insert": MethodIntr(),
"pop": MethodIntr(),
"remove": MethodIntr(),
"reverse": MethodIntr(),
},
"list": {
"append": MethodIntr(signature=Fun[[List[T0], T0], None]),
Expand Down Expand Up @@ -4530,6 +4531,7 @@ def expand_numpy_2_args(args, defaults=None, force=False):
"insert": MethodIntr(signature=Fun[[List[T0], int, T0], None]),
"pop": MethodIntr(),
"remove": MethodIntr(),
"reverse": MethodIntr(),
"sort": MethodIntr(),
"tolist": ConstMethodIntr(),
"update": MethodIntr(update_effects),
Expand Down
4 changes: 4 additions & 0 deletions pythran/tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,7 @@ def test_array_pop(self):
def test_array_remove(self):
self.run_test("def array_remove_(f): import array; x = array.array('I',[f,2,3]); x.remove(2); return x.tolist()",
3, array_remove_=[int])

def test_array_reverse(self):
self.run_test("def array_reverse_(f): import array; x = array.array('I',[f,2,3]); x.reverse(); return x.tolist()",
3, array_reverse_=[int])

0 comments on commit c11caeb

Please sign in to comment.