std::bad_cast
on returning ndarray of vector
#570
-
I have a class using BytesVector = std::vector<uint8_t>;
using BytesArray = nb::ndarray<nb::numpy, uint8_t, nb::shape<-1>, nb::c_contig>;
class SOEM_wrapper {
public:
BytesVector iomap;
SOEM_wrapper(uint16_t maxslave_, uint8_t maxgroup_, size_t iomap_size_bytes){
if (maxslave_ == 0) {
throw std::invalid_argument("maxslave cannot be zero.");
}
if (maxgroup_ == 0) {
throw std::invalid_argument("maxgroup cannot be zero.");
}
if (iomap_size_bytes == 0) {
throw std::invalid_argument("iomap_size_bytes cannot be zero.");
}
iomap.resize(iomap_size_bytes, 0);
}
}
binding .def_prop_ro("iomap", [](SOEM_wrapper &wrapper){
size_t shape[1] = {wrapper.iomap.size()};
return BytesArray(wrapper.iomap.data(), 1, shape, nb::handle());
}, nb::rv_policy::reference_internal) python code that produces the error main_device = SOEM(maxslave=512, maxgroup=2, iomap_size_bytes=4096)
print(main_device.iomap) error
|
Beta Was this translation helpful? Give feedback.
Answered by
jeffective
May 9, 2024
Replies: 1 comment 4 replies
-
whats odd is this doesnt happen has part of a test def test_iomap_mutability():
context = SOEM(maxslave=512, maxgroup=2, iomap_size_bytes=4096)
print(context.iomap) |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i'm not able to repeat the error after rebuilding my vscode dev container. perhaps the 100's of
pip install .
during development caught up to me. closing