未验证 提交 147fa621 编写于 作者: W Wilber 提交者: GitHub

Fix none-contiguous bug for python api (#29616)

上级 ab5cc042
...@@ -69,7 +69,8 @@ void BindMkldnnQuantizerConfig(py::module *m); ...@@ -69,7 +69,8 @@ void BindMkldnnQuantizerConfig(py::module *m);
#endif #endif
template <typename T> template <typename T>
PaddleBuf PaddleBufCreate(py::array_t<T> data) { PaddleBuf PaddleBufCreate(
py::array_t<T, py::array::c_style | py::array::forcecast> data) {
PaddleBuf buf(data.size() * sizeof(T)); PaddleBuf buf(data.size() * sizeof(T));
std::copy_n(static_cast<const T *>(data.data()), data.size(), std::copy_n(static_cast<const T *>(data.data()), data.size(),
static_cast<T *>(buf.data())); static_cast<T *>(buf.data()));
...@@ -77,7 +78,9 @@ PaddleBuf PaddleBufCreate(py::array_t<T> data) { ...@@ -77,7 +78,9 @@ PaddleBuf PaddleBufCreate(py::array_t<T> data) {
} }
template <typename T> template <typename T>
void PaddleBufReset(PaddleBuf &buf, py::array_t<T> data) { // NOLINT void PaddleBufReset(
PaddleBuf &buf, // NOLINT
py::array_t<T, py::array::c_style | py::array::forcecast> data) { // NOLINT
buf.Resize(data.size() * sizeof(T)); buf.Resize(data.size() * sizeof(T));
std::copy_n(static_cast<const T *>(data.data()), data.size(), std::copy_n(static_cast<const T *>(data.data()), data.size(),
static_cast<T *>(buf.data())); static_cast<T *>(buf.data()));
...@@ -85,7 +88,8 @@ void PaddleBufReset(PaddleBuf &buf, py::array_t<T> data) { // NOLINT ...@@ -85,7 +88,8 @@ void PaddleBufReset(PaddleBuf &buf, py::array_t<T> data) { // NOLINT
template <typename T> template <typename T>
PaddleTensor PaddleTensorCreate( PaddleTensor PaddleTensorCreate(
py::array_t<T> data, const std::string name = "", py::array_t<T, py::array::c_style | py::array::forcecast> data,
const std::string name = "",
const std::vector<std::vector<size_t>> &lod = {}, bool copy = true) { const std::vector<std::vector<size_t>> &lod = {}, bool copy = true) {
PaddleTensor tensor; PaddleTensor tensor;
...@@ -137,8 +141,9 @@ py::array PaddleTensorGetData(PaddleTensor &tensor) { // NOLINT ...@@ -137,8 +141,9 @@ py::array PaddleTensorGetData(PaddleTensor &tensor) { // NOLINT
} }
template <typename T> template <typename T>
void ZeroCopyTensorCreate(ZeroCopyTensor &tensor, // NOLINT void ZeroCopyTensorCreate(
py::array_t<T> data) { ZeroCopyTensor &tensor, // NOLINT
py::array_t<T, py::array::c_style | py::array::forcecast> data) {
std::vector<int> shape; std::vector<int> shape;
std::copy_n(data.shape(), data.ndim(), std::back_inserter(shape)); std::copy_n(data.shape(), data.ndim(), std::back_inserter(shape));
tensor.Reshape(std::move(shape)); tensor.Reshape(std::move(shape));
...@@ -146,8 +151,9 @@ void ZeroCopyTensorCreate(ZeroCopyTensor &tensor, // NOLINT ...@@ -146,8 +151,9 @@ void ZeroCopyTensorCreate(ZeroCopyTensor &tensor, // NOLINT
} }
template <typename T> template <typename T>
void PaddleInferTensorCreate(paddle_infer::Tensor &tensor, // NOLINT void PaddleInferTensorCreate(
py::array_t<T> data) { paddle_infer::Tensor &tensor, // NOLINT
py::array_t<T, py::array::c_style | py::array::forcecast> data) {
std::vector<int> shape; std::vector<int> shape;
std::copy_n(data.shape(), data.ndim(), std::back_inserter(shape)); std::copy_n(data.shape(), data.ndim(), std::back_inserter(shape));
tensor.Reshape(std::move(shape)); tensor.Reshape(std::move(shape));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册