From 78dad786100eb9081f96f52044f590182f7bbc85 Mon Sep 17 00:00:00 2001 From: Wilber Date: Tue, 15 Dec 2020 18:58:23 +0800 Subject: [PATCH] fix none-contiguous bug for python api. (#29615) --- paddle/fluid/pybind/inference_api.cc | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/paddle/fluid/pybind/inference_api.cc b/paddle/fluid/pybind/inference_api.cc index 7f3fe410464..389beb41054 100644 --- a/paddle/fluid/pybind/inference_api.cc +++ b/paddle/fluid/pybind/inference_api.cc @@ -69,7 +69,8 @@ void BindMkldnnQuantizerConfig(py::module *m); #endif template -PaddleBuf PaddleBufCreate(py::array_t data) { +PaddleBuf PaddleBufCreate( + py::array_t data) { PaddleBuf buf(data.size() * sizeof(T)); std::copy_n(static_cast(data.data()), data.size(), static_cast(buf.data())); @@ -77,7 +78,9 @@ PaddleBuf PaddleBufCreate(py::array_t data) { } template -void PaddleBufReset(PaddleBuf &buf, py::array_t data) { // NOLINT +void PaddleBufReset( + PaddleBuf &buf, // NOLINT + py::array_t data) { // NOLINT buf.Resize(data.size() * sizeof(T)); std::copy_n(static_cast(data.data()), data.size(), static_cast(buf.data())); @@ -85,7 +88,8 @@ void PaddleBufReset(PaddleBuf &buf, py::array_t data) { // NOLINT template PaddleTensor PaddleTensorCreate( - py::array_t data, const std::string name = "", + py::array_t data, + const std::string name = "", const std::vector> &lod = {}, bool copy = true) { PaddleTensor tensor; @@ -137,8 +141,9 @@ py::array PaddleTensorGetData(PaddleTensor &tensor) { // NOLINT } template -void ZeroCopyTensorCreate(ZeroCopyTensor &tensor, // NOLINT - py::array_t data) { +void ZeroCopyTensorCreate( + ZeroCopyTensor &tensor, // NOLINT + py::array_t data) { std::vector shape; std::copy_n(data.shape(), data.ndim(), std::back_inserter(shape)); tensor.Reshape(std::move(shape)); @@ -146,8 +151,9 @@ void ZeroCopyTensorCreate(ZeroCopyTensor &tensor, // NOLINT } template -void PaddleInferTensorCreate(paddle_infer::Tensor &tensor, // NOLINT - py::array_t data) { +void PaddleInferTensorCreate( + paddle_infer::Tensor &tensor, // NOLINT + py::array_t data) { std::vector shape; std::copy_n(data.shape(), data.ndim(), std::back_inserter(shape)); tensor.Reshape(std::move(shape)); -- GitLab