Skip to content

Commit cb159ae

Browse files
Allow tuple with combinable items as array initializer
Fix #2245
1 parent 4479f5a commit cb159ae

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

pythran/pythonic/include/numpy/array.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ namespace numpy
5353
typename types::array_base<T, N, V>::shape_t>
5454
array(types::array_base<T, N, V> &&, dtype d = dtype());
5555

56+
template <class... Ts>
57+
auto array(std::tuple<Ts...> t)
58+
-> decltype(array(types::to_array<typename __combined<Ts...>::type>(t)))
59+
{
60+
return array(types::to_array<typename __combined<Ts...>::type>(t));
61+
}
62+
5663
DEFINE_FUNCTOR(pythonic::numpy, array);
5764
} // namespace numpy
5865
PYTHONIC_NS_END

pythran/tests/test_numpy_func2.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,9 @@ def test_array2D_(self):
737737
def test_array_iter(self):
738738
self.run_test("def np_array_iter():\n from numpy import array\n return array(list(reversed(range(0, 300)))) + 3", np_array_iter=[])
739739

740+
def test_array_tuple(self):
741+
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])
742+
740743
def test_array_typed(self):
741744
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]])
742745

0 commit comments

Comments
 (0)