| 100 | } |
| 101 | |
| 102 | void bindMatrixOperator(nanobind::module_ &mod) { |
| 103 | |
| 104 | auto matrix_op_class = nanobind::class_<matrix_op>(mod, "MatrixOperator"); |
| 105 | auto matrix_op_term_class = |
| 106 | nanobind::class_<matrix_op_term>(mod, "MatrixOperatorTerm"); |
| 107 | |
| 108 | matrix_op_class |
| 109 | .def( |
| 110 | "__iter__", |
| 111 | [](matrix_op &self) { |
| 112 | nanobind::list items; |
| 113 | for (auto it = self.begin(); it != self.end(); ++it) |
| 114 | items.append(nanobind::cast(*it)); |
| 115 | return items.attr("__iter__")(); |
| 116 | }, |
| 117 | "Loop through each term of the operator.") |
| 118 | |
| 119 | // properties |
| 120 | |
| 121 | .def_prop_ro("parameters", &matrix_op::get_parameter_descriptions, |
| 122 | "Returns a dictionary that maps each parameter " |
| 123 | "name to its description.") |
| 124 | .def_prop_ro("degrees", &matrix_op::degrees, |
| 125 | "Returns a vector that lists all degrees of " |
| 126 | "freedom that the operator targets.") |
| 127 | .def_prop_ro("min_degree", &matrix_op::min_degree, |
| 128 | "Returns the smallest index of the degrees of " |
| 129 | "freedom that the operator targets.") |
| 130 | .def_prop_ro("max_degree", &matrix_op::max_degree, |
| 131 | "Returns the smallest index of the degrees of " |
| 132 | "freedom that the operator targets.") |
| 133 | .def_prop_ro("term_count", &matrix_op::num_terms, |
| 134 | "Returns the number of terms in the operator.") |
| 135 | |
| 136 | // constructors |
| 137 | |
| 138 | .def(nanobind::init<>(), |
| 139 | "Creates a default instantiated sum. A default instantiated " |
| 140 | "sum has no value; it will take a value the first time an " |
| 141 | "arithmetic operation " |
| 142 | "is applied to it. In that sense, it acts as both the additive and " |
| 143 | "multiplicative " |
| 144 | "identity. To construct a `0` value in the mathematical sense " |
| 145 | "(neutral element " |
| 146 | "for addition), use `empty()` instead.") |
| 147 | .def(nanobind::init<std::size_t>(), |
| 148 | "Creates a sum operator with no terms, reserving " |
| 149 | "space for the given number of terms.") |
| 150 | .def(nanobind::init<spin_op>()) |
| 151 | .def(nanobind::init<fermion_op>()) |
| 152 | .def(nanobind::init<boson_op>()) |
| 153 | .def(nanobind::init<const matrix_op_term &>(), |
| 154 | "Creates a sum operator with the given term.") |
| 155 | .def(nanobind::init<const matrix_op &>(), "Copy constructor.") |
| 156 | .def( |
| 157 | "copy", [](const matrix_op &self) { return matrix_op(self); }, |
| 158 | "Creates a copy of the operator.") |
| 159 |
no test coverage detected