Skip to content

Commit

Permalink
Allow tuple with combinable items as array initializer
Browse files Browse the repository at this point in the history
Fix #2245
  • Loading branch information
serge-sans-paille committed Nov 30, 2024
1 parent 4479f5a commit cb159ae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pythran/pythonic/include/numpy/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ namespace numpy
typename types::array_base<T, N, V>::shape_t>
array(types::array_base<T, N, V> &&, dtype d = dtype());

template <class... Ts>
auto array(std::tuple<Ts...> t)
-> decltype(array(types::to_array<typename __combined<Ts...>::type>(t)))
{
return array(types::to_array<typename __combined<Ts...>::type>(t));
}

DEFINE_FUNCTOR(pythonic::numpy, array);
} // namespace numpy
PYTHONIC_NS_END
Expand Down
3 changes: 3 additions & 0 deletions pythran/tests/test_numpy_func2.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,9 @@ def test_array2D_(self):
def test_array_iter(self):
self.run_test("def np_array_iter():\n from numpy import array\n return array(list(reversed(range(0, 300)))) + 3", np_array_iter=[])

def test_array_tuple(self):
self.run_test("def np_array_tuple(x):\n from numpy import array\n return array((1, 2, x))", 3.5, np_array_tuple=[float])

def test_array_typed(self):
self.run_test("def np_array_typed(a):\n from numpy import array, int64\n return array(a, int64)", [1.,2.,3.], np_array_typed=[List[float]])

Expand Down

0 comments on commit cb159ae

Please sign in to comment.