MCPcopy Create free account
hub / github.com/bab2min/tomotopy / makeDoc

Method makeDoc

src/python/handler/py_SLDA.cpp:143–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

141}
142
143py::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
171py::UniqueObj SLDAModelObject::getRegressionCoef(PyObject* varId) const
172{

Callers

nothing calls this directly

Calls 5

buildRawDocFunction · 0.85
toCppFunction · 0.85
getDocumentClsFunction · 0.85
copyMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected