Home / Class/ SingletonTypePtr Class — pytorch Architecture

SingletonTypePtr Class — pytorch Architecture

Architecture documentation for the SingletonTypePtr class in type_ptr.h from the pytorch codebase.

Entity Profile

Source Code

aten/src/ATen/core/type_ptr.h lines 13–42

template <typename T>
class SingletonTypePtr {
 public:
  /* implicit */ SingletonTypePtr(T* p) : repr_(p) {}

  // We need this to satisfy Pybind11, but it shouldn't be hit.
  explicit SingletonTypePtr(std::shared_ptr<T> /*unused*/) { TORCH_CHECK(false); }

  using element_type = typename std::shared_ptr<T>::element_type;

  template <typename U = T, std::enable_if_t<!std::is_same_v<std::remove_const_t<U>, void>, bool> = true>
  T& operator*() const {
    return *repr_;
  }

  T* get() const {
    return repr_;
  }

  T* operator->() const {
    return repr_;
  }

  operator bool() const {
    return repr_ != nullptr;
  }

 private:
  T* repr_{nullptr};
};

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free