| 13 | } |
| 14 | |
| 15 | SLDAModelObject::SLDAModelObject(size_t tw, size_t minCnt, size_t minDf, size_t rmTop, |
| 16 | size_t k, PyObject* vars, PyObject* alpha, float eta, |
| 17 | PyObject* mu, PyObject* nuSq, PyObject* glmCoef, |
| 18 | PyObject* seed, PyObject* corpus, PyObject* transform) |
| 19 | { |
| 20 | tomoto::SLDAArgs margs; |
| 21 | margs.k = k; |
| 22 | if (alpha) |
| 23 | { |
| 24 | margs.alpha = broadcastObj<tomoto::Float>(alpha, margs.k, |
| 25 | [&]() { return "`alpha` must be an instance of `float` or `List[float]` with length `k` (given " + py::repr(alpha) + ")"; } |
| 26 | ); |
| 27 | } |
| 28 | margs.eta = eta; |
| 29 | if (seed && seed != Py_None && !py::toCpp<size_t>(seed, margs.seed)) |
| 30 | { |
| 31 | throw py::ValueError{ "`seed` must be an integer or None." }; |
| 32 | } |
| 33 | |
| 34 | vector<string> varTypeStrs; |
| 35 | if (vars && vars != Py_None && !py::toCpp<vector<string>>(vars, varTypeStrs)) |
| 36 | { |
| 37 | throw py::ValueError{ "`vars` must be an iterable of str." }; |
| 38 | } |
| 39 | for (auto& s : varTypeStrs) |
| 40 | { |
| 41 | tomoto::ISLDAModel::GLM t; |
| 42 | if (s == "l") t = tomoto::ISLDAModel::GLM::linear; |
| 43 | else if (s == "b") t = tomoto::ISLDAModel::GLM::binary_logistic; |
| 44 | else throw py::ValueError{ "Unknown var type '" + s + "'" }; |
| 45 | margs.vars.emplace_back(t); |
| 46 | } |
| 47 | |
| 48 | float fTemp; |
| 49 | if (mu) |
| 50 | { |
| 51 | if (py::toCpp<float>(mu, fTemp)) |
| 52 | { |
| 53 | margs.mu.resize(varTypeStrs.size(), fTemp); |
| 54 | } |
| 55 | else if (py::clearError(), py::toCpp<vector<tomoto::Float>>(mu, margs.mu)) |
| 56 | { |
| 57 | |
| 58 | } |
| 59 | else |
| 60 | { |
| 61 | throw py::ValueError{ "`mu` must be a float or an iterable of float with length same as `vars`." }; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | if (nuSq) |
| 66 | { |
| 67 | if (py::toCpp<float>(nuSq, fTemp)) |
| 68 | { |
| 69 | margs.nuSq.resize(varTypeStrs.size(), fTemp); |
| 70 | } |
| 71 | else if (py::clearError(), py::toCpp<vector<tomoto::Float>>(nuSq, margs.nuSq)) |
| 72 | { |
nothing calls this directly
no test coverage detected