Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow tuple with combinable items as array initializer #2262

Merged
merged 1 commit into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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