| 141 | } |
| 142 | |
| 143 | py::UniqueCObj<DocumentObject> SLDAModelObject::makeDoc(PyObject* words, PyObject* y) |
| 144 | { |
| 145 | if (!isPrepared) throw py::RuntimeError{ "`train()` should be called before `make_doc()`." }; |
| 146 | auto* inst = getInst<tomoto::ISLDAModel>(); |
| 147 | if (PyUnicode_Check(words)) |
| 148 | { |
| 149 | if (PyErr_WarnEx(PyExc_RuntimeWarning, "`words` should be an iterable of str.", 1)) throw py::ExcPropagation{}; |
| 150 | } |
| 151 | tomoto::RawDoc raw = buildRawDoc(words); |
| 152 | |
| 153 | if (y) |
| 154 | { |
| 155 | vector<tomoto::Float> yVec; |
| 156 | if (!py::toCpp(y, yVec)) |
| 157 | { |
| 158 | throw py::ValueError{ "`y` must be an iterable of float." }; |
| 159 | } |
| 160 | raw.misc["y"] = yVec; |
| 161 | } |
| 162 | auto doc = inst->makeDoc(raw); |
| 163 | py::UniqueCObj<CorpusObject> corpus{ (CorpusObject*)PyObject_CallFunctionObjArgs((PyObject*)py::Type<CorpusObject>, Py_None, getObject(), nullptr) }; |
| 164 | auto ret = py::makeNewObject<DocumentObject>(getDocumentCls()); |
| 165 | ret->corpus = corpus.copy(); |
| 166 | ret->doc = doc.release(); |
| 167 | ret->owner = true; |
| 168 | return ret; |
| 169 | } |
| 170 | |
| 171 | py::UniqueObj SLDAModelObject::getRegressionCoef(PyObject* varId) const |
| 172 | { |
nothing calls this directly
no test coverage detected