Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/16176
This makes PyTorch and Caffe2's data() method line up.
Historically, PyTorch made no distinction between tensors
with const or non-const data, and thus provided a
non-const pointer with data() member. Changing the API to
return a const-pointer would break all mutable code, whereas
changing the Caffe2 API to change a pointer doesn't break
any code, *except* for code which required an exact match
on const-ness (e.g., in template arguments). Since the latter
is less disruptive, we've opted for it here.
The few places downstream that broke due to this are fixed
in this patch.
Reviewed By: smessmer
Differential Revision:
D13742916
fbshipit-source-id:
baa4b4544cfdf7c1f369f4d69a1e0d5953c1bd99
}
/**
- * Returns a const raw void* pointer of the underlying storage. mutable_data()
+ * Returns a raw void* pointer of the underlying storage. mutable_data()
* or raw_mutable_data() must have been called prior to this function call.
*/
- inline const void* raw_data() const {
+ inline void* raw_data() const {
return impl_->data();
}
template <typename T>
- inline const T* data() const {
+ inline T* data() const {
return impl_.get()->data<T>();
}