use const_data_ptr as source of std::copy (#100885)
use const_data_ptr as source of std::copy
Test Plan: Rely on CI.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/100885
Approved by: https://github.com/Skylion007
diff --git a/torch/csrc/api/src/data/samplers/random.cpp b/torch/csrc/api/src/data/samplers/random.cpp
index 20997f6..fdb1fc0 100644
--- a/torch/csrc/api/src/data/samplers/random.cpp
+++ b/torch/csrc/api/src/data/samplers/random.cpp
@@ -36,7 +36,7 @@
// will be two allocations: one for the upcast slice, and one for the
// returned `index_batch` vector.
slice = slice.to(torch::kInt64);
- const auto* data = slice.data_ptr<int64_t>();
+ const auto* data = slice.const_data_ptr<int64_t>();
std::copy(data, data + index_batch.size(), index_batch.begin());
index_ += index_batch.size();
return index_batch;
diff --git a/torch/csrc/jit/mobile/train/random.cpp b/torch/csrc/jit/mobile/train/random.cpp
index b8448ed..b11d8e9 100644
--- a/torch/csrc/jit/mobile/train/random.cpp
+++ b/torch/csrc/jit/mobile/train/random.cpp
@@ -36,7 +36,7 @@
// will be two allocations: one for the upcast slice, and one for the
// returned `index_batch` vector.
slice = slice.to(torch::kInt64);
- const auto* data = slice.data_ptr<int64_t>();
+ const auto* data = slice.const_data_ptr<int64_t>();
std::copy(data, data + index_batch.size(), index_batch.begin());
index_ += index_batch.size();
return index_batch;