Copy framework of incoming nb::ndarray #813
Unanswered
RaulPPelaez
asked this question in
Q&A
Replies: 1 comment 1 reply
-
This is my current approach to identify the framework of an void process_array_generic(nb::ndarray<float> &a) {
nb::object obj = nb::find(a);
std::string tn =nb::str(nb::getattr(obj.release(), "__class__")).c_str();
bool isnp = tn.find("numpy") != std::string::npos;
bool istorch = tn.find("torch") != std::string::npos;
bool iscupy = tn.find("cupy") != std::string::npos;
bool isjax = tn.find("jax") != std::string::npos;
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to create a C++ extension that will return an ndarray with the same framework as the received one. So that I can do something like:
With an extension similar to one of the examples:
AFAICT, the information about the framework is lost when C++ receives the buffer. I could return a DLPack and deal with the cast python side, but I wonder if there is a "sane" way to achieve it C++-side.
Beta Was this translation helpful? Give feedback.
All reactions