| 95 | } |
| 96 | |
| 97 | PyObject* GradKeyWrapper::is_attached_to(PyObject* const* args, size_t nargs) { |
| 98 | if (nargs != 1) { |
| 99 | PyErr_SetString(PyExc_TypeError, "expect 1 argument"); |
| 100 | return nullptr; |
| 101 | } |
| 102 | auto* tw = TensorWrapper::try_cast(args[0]); |
| 103 | if (!tw) { |
| 104 | PyErr_SetString(PyExc_TypeError, "expect Tensor"); |
| 105 | return nullptr; |
| 106 | } |
| 107 | if (imperative::apply(IsAttachedTo(m_key), tw->m_tensor->data())[0] |
| 108 | .cast<BoolValue>()) { |
| 109 | Py_RETURN_TRUE; |
| 110 | } |
| 111 | Py_RETURN_FALSE; |
| 112 | } |
| 113 | |
| 114 | void GradKeyWrapper::enter() { |
| 115 | m_transformation = std::make_shared<GradTransformation>(); |
no test coverage detected