Skip to content

Commit

Permalink
Delete Tensor::swap(), replace with pointer swap (pytorch#12730)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch#12730

i-am-not-moving-c2-to-c10

Reviewed By: smessmer

Differential Revision: D10415430

fbshipit-source-id: 8a2ce8611c5fa77bbbd73fb6788c1baa3b370f07
  • Loading branch information
ezyang authored and facebook-github-bot committed Jan 25, 2019
1 parent 4aae89f commit 45602ce
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 9 deletions.
8 changes: 0 additions & 8 deletions caffe2/core/tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,6 @@ class CAFFE2_API Tensor final {
return ss.str();
}

// NB: a.swap(b) is not equivalent to std::swap(a, b);
// swap method swaps the CONTENTS of the tensors, while std::swap
// swaps the POINTERS.
void swap(const Tensor& other) const noexcept {
// NB: use get() to get a non-const pointer!
std::swap(*impl_.get(), *other.impl_.get());
}

void ShareData(const Tensor& src) const {
impl_.get()->ShareData(*src.impl_.get());
}
Expand Down
2 changes: 1 addition & 1 deletion caffe2/utils/filler.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TensorFiller {
CAFFE_ENFORCE_LE(min, max);

Tensor temp_tensor(shape_, Context::GetDeviceType());
tensor->swap(temp_tensor);
std::swap(*tensor, temp_tensor);
Type* data = tensor->template mutable_data<Type>();

// select distribution
Expand Down

0 comments on commit 45602ce

Please sign in to comment.