| 91 | }; |
| 92 | |
| 93 | struct TensorWrapper { |
| 94 | public: |
| 95 | std::optional<Tensor> m_tensor; |
| 96 | |
| 97 | inline TensorWrapper(ValueRef value) { m_tensor.emplace(value); } |
| 98 | TensorWrapper(PyObject* args, PyObject* kwargs); |
| 99 | ~TensorWrapper() = default; |
| 100 | |
| 101 | static constexpr auto tp_name = pybind11::detail::_("Tensor"); |
| 102 | |
| 103 | using wrap_t = pyext17::wrap<TensorWrapper>; |
| 104 | friend wrap_t; |
| 105 | |
| 106 | inline static TensorWrapper* cast(PyObject* obj) { |
| 107 | return reinterpret_cast<wrap_t*>(obj)->inst(); |
| 108 | } |
| 109 | inline static TensorWrapper* try_cast(PyObject* obj) { |
| 110 | if (!wrap_t::type().isinstance(obj)) |
| 111 | return nullptr; |
| 112 | return cast(obj); |
| 113 | } |
| 114 | inline ObjectPtr<TensorWrapper, pybind11::handle> self() { |
| 115 | return wrap_t::pycast(this); |
| 116 | } |
| 117 | |
| 118 | template <typename... Args> |
| 119 | static ObjectPtr<Tensor> make(Args&&... args) { |
| 120 | auto* op = wrap_t::cnew(std::forward<Args>(args)...); |
| 121 | return pybind11::reinterpret_steal<ObjectPtr<Tensor>>(op); |
| 122 | } |
| 123 | |
| 124 | template <typename... Args> |
| 125 | static ObjectPtr<Tensor> make(PyTypeObject* pytype, Args&&... args) { |
| 126 | auto* op = wrap_t::cnew_with_type(pytype, std::forward<Args>(args)...); |
| 127 | return pybind11::reinterpret_steal<ObjectPtr<Tensor>>(op); |
| 128 | } |
| 129 | |
| 130 | PyObject* shape(); |
| 131 | PyObject* dtype(); |
| 132 | PyObject* device(); |
| 133 | PyObject* format(); |
| 134 | PyObject* numpy(); |
| 135 | void reset(PyObject*); |
| 136 | PyObject* detach(); |
| 137 | PyObject* isscalar(); |
| 138 | PyObject* value_id(); |
| 139 | PyObject* _dev_tensor(); |
| 140 | void _drop(); |
| 141 | PyObject* varnode(); |
| 142 | PyObject* recording(); |
| 143 | PyObject* copied(); |
| 144 | PyObject* module_trace_info(); |
| 145 | void set_module_trace_info(PyObject*); |
| 146 | void _set_format(PyObject*); |
| 147 | void _as_format(PyObject*); |
| 148 | void _set_name(PyObject*); |
| 149 | PyObject* _detail(); |
| 150 | PyObject* _var(); |