Skip to content
Closed
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
9 changes: 8 additions & 1 deletion include/xtensor-python/pyarray.hpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,8 +42,15 @@ namespace pybind11
{
using type = xt::pyarray<T>

bool load(handle src, bool)
bool load(handle src, bool convert)
{
if (!convert){
if (!PyArray_Check(src.ptr()))
return false;
int type_num = xt::detail::numpy_traits<T>::type_num;
if (PyArray_TYPE(reinterpret_cast<PyArrayObject*>(src.ptr())) != type_num)
return false;
}
value = type::ensure(src);
return static_cast<bool>(value);
}
Expand Down
11 changes: 9 additions & 2 deletions include/xtensor-python/pytensor.hpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,9 +43,16 @@ namespace pybind11
{
using type = xt::pytensor<T, N>

bool load(handle src, bool)
bool load(handle src, bool convert)
{
value = type::ensure(src);
if (!convert){
if (!PyArray_Check(src.ptr()))
return false;
int type_num = xt::detail::numpy_traits<T>::type_num;
if (PyArray_TYPE(reinterpret_cast<PyArrayObject*>(src.ptr())) != type_num)
return false;
}
value = type::ensure(src);
return static_cast<bool>(value);
}

Expand Down