File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed
Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -257,14 +257,23 @@ inline Tensor to(
257257
258258inline Tensor Tensor::to (Device device, ScalarType dtype, bool non_blocking)
259259 const {
260+ if (this ->device () == device && this ->dtype () == dtype) {
261+ return *this ;
262+ }
260263 return detail::to (*this , options ().device (device).dtype (dtype), non_blocking);
261264}
262265
263266inline Tensor Tensor::to (ScalarType dtype, bool non_blocking) const {
267+ if (this ->dtype () == dtype) {
268+ return *this ;
269+ }
264270 return detail::to (*this , options ().dtype (dtype), non_blocking);
265271}
266272
267273inline Tensor Tensor::to (Device device, bool non_blocking) const {
274+ if (this ->device () == device) {
275+ return *this ;
276+ }
268277 return detail::to (*this , options ().device (device), non_blocking);
269278}
270279} // namespace at
You can’t perform that action at this time.
0 commit comments