How to detect input lumpy from python side is c-order or f-order or either of them? #4211
lucasjinreal
started this conversation in
General
Replies: 2 comments 2 replies
-
@jinfagang it is fairly simple when using pybind's numpy interface // Create some alias for the value
#define C_CONTIGUOUS py::detail::npy_api::constants::NPY_ARRAY_C_CONTIGUOUS_
return_value func(py::array array) {
// This check is kind of "low-level" approach
if (!(C_CONTIGUOUS == (array.flags() & C_CONTIGUOUS))) {
// Actual casting, notice that type needs to be known and adding `c_style` is required to force memory alignment
auto c_array = array.cast<py::array_t<double, py::array::c_style | py::array::forcecast>>();
}
// ...
} I leave details of casting mechanism up to you, it depends on your actual problem. Let me know if it helps 😉 |
Beta Was this translation helpful? Give feedback.
0 replies
-
@jiwaszki thanks. My usage is like this: users send in a list of numpy arrays, these arrays needs to normalize: Do u think my modification should work? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I want normalize the data to c-order, users sometimes send f-prder, sometimes non of them.
How to normalize it?
Beta Was this translation helpful? Give feedback.
All reactions