Clean up a c10::optional and fix documentation (#138700)

Fixes #ISSUE_NUMBER

Pull Request resolved: https://github.com/pytorch/pytorch/pull/138700
Approved by: https://github.com/Skylion007
This commit is contained in:
Richard Barnes 2024-10-23 20:42:24 +00:00 committed by PyTorch MergeBot
parent 8aedc649bd
commit dbd6ada8c3
2 changed files with 3 additions and 7 deletions

View File

@ -878,7 +878,7 @@ Process 87741 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x00000001024e2628 libtorch_python.dylib`at::indexing::impl::applySelect(self=0x00000001004ee8a8, dim=0, index=(data_ = 3), real_dim=0, (null)=0x000000016fdfe535, self_sizes= Has Value=true ) at TensorIndexing.h:239:7
236 const at::Device& /*self_device*/,
237 const c10::optional<SymIntArrayRef>& self_sizes) {
237 const std::optional<SymIntArrayRef>& self_sizes) {
238 // See NOTE [nested tensor size for indexing]
-> 239 if (self_sizes.has_value()) {
240 auto maybe_index = index.maybe_as_int();
@ -1081,10 +1081,6 @@ Here are a few well known pitfalls and workarounds:
catch all of these problems: stay vigilant to the possibility that
your crash is due to a real memory problem.
* (NVCC) `c10::optional` does not work when used from device code. Don't use
it from kernels. Upstream issue: https://github.com/akrzemi1/Optional/issues/58
and our local issue #10329.
* `constexpr` generally works less well on MSVC.
* The idiom `static_assert(f() == f())` to test if `f` is constexpr

View File

@ -23,7 +23,7 @@ C10_API void warnDeprecatedDataPtr();
// Currently used only for storing a custom error message
// used when throwing an exception when data_ptr is accessed.
struct C10_API StorageExtraMeta {
c10::optional<std::string> custom_data_ptr_error_msg_ = c10::nullopt;
std::optional<std::string> custom_data_ptr_error_msg_ = c10::nullopt;
StorageExtraMeta() = default;
StorageExtraMeta(const StorageExtraMeta& other) {
if (other.custom_data_ptr_error_msg_) {
@ -283,7 +283,7 @@ struct C10_API StorageImpl : public c10::intrusive_ptr_target {
[[noreturn]] void throw_data_ptr_access_error() const;
void release_data_and_set_meta_custom_data_ptr_error_msg_(
c10::optional<std::string> s) {
std::optional<std::string> s) {
throw_on_immutable_data_ptr_ = true;
get_extra_meta().custom_data_ptr_error_msg_ = std::move(s);
refresh_has_data_ptr_check();