Browse Source

!6028 Fix codedex issues in tensor_py.cc

Merge pull request !6028 from hewei/fix_codedex_0911
tags/v1.0.0
mindspore-ci-bot Gitee 5 years ago
parent
commit
fda52b50df
1 changed files with 4 additions and 2 deletions
  1. +4
    -2
      mindspore/ccsrc/pybind_api/ir/tensor_py.cc

+ 4
- 2
mindspore/ccsrc/pybind_api/ir/tensor_py.cc View File

@@ -122,6 +122,8 @@ class TensorDataNumpy : public TensorData {
public:
explicit TensorDataNumpy(py::buffer_info &&buffer) : buffer_(std::move(buffer)) {}

~TensorDataNumpy() override = default;

/// Total number of elements.
ssize_t size() const override { return buffer_.size; }

@@ -160,7 +162,7 @@ class TensorDataNumpy : public TensorData {
return py::array(py::dtype(buffer_), buffer_.shape, buffer_.strides, buffer_.ptr, dummyOwner);
}

private:
// The internal buffer.
py::buffer_info buffer_;
};

@@ -258,7 +260,7 @@ py::array TensorPy::SyncAsNumpy(const Tensor &tensor) {

py::array TensorPy::AsNumpy(const Tensor &tensor) {
auto data_numpy = dynamic_cast<const TensorDataNumpy *>(&tensor.data());
if (data_numpy) {
if (data_numpy != nullptr) {
// Return internal numpy array if tensor data is implemented base on it.
return data_numpy->py_array();
}


Loading…
Cancel
Save