Skip to content

Commit 0e2b9e5

Browse files
allow copy from any xtensor container (#29)
1 parent 300bd1a commit 0e2b9e5

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

lib/memory/astensor.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ Tensor<T, 1> astensor(const std::vector<T>& vector, const Order order = Order::C
3737
* @param arr: The xarray object.
3838
* @return Tensor: The tensor from the xarray.
3939
*/
40-
template <typename T, size_t N, xt::layout_type L>
41-
Tensor<T, N> astensor(const xt::xarray<T, L>& arr) {
40+
template <typename T, size_t N, typename C>
41+
Tensor<T, N> astensor(const C& arr) {
4242
Order order;
43-
if constexpr (L == xt::layout_type::row_major) {
43+
const auto L = arr.layout();
44+
if (L == xt::layout_type::row_major) {
4445
order = Order::C;
45-
} else if constexpr (L == xt::layout_type::column_major) {
46+
} else if (L == xt::layout_type::column_major) {
4647
order = Order::F;
47-
} else {
48-
static_assert(L == xt::layout_type::row_major || L == xt::layout_type::column_major, "Unsupported layout type.");
49-
}
48+
}
49+
5050
auto sh = arr.shape();
5151
vt::Shape<N> shape;
5252
assert(sh.size() == N);

0 commit comments

Comments
 (0)