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

Method load

src/python/handler/py_LDA.cpp:558–584  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

556}
557
558std::pair<py::UniquePObj<LDAModelObject>, std::vector<uint8_t>> LDAModelObject::load(PyObject* cls, const std::string& filename)
559{
560 ifstream str{ filename, ios_base::binary };
561 if (!str) throw ios_base::failure{ std::string("cannot open file '") + filename + std::string("'") };
562 for (size_t i = 0; i < (size_t)tomoto::TermWeight::size; ++i)
563 {
564 str.seekg(0);
565 py::UniqueObj args{ py::buildPyTuple(i) };
566 py::UniqueObj newInst{ PyObject_CallObject(cls, args.get()) };
567 if (!newInst) throw py::ExcPropagation{};
568 auto p = py::checkType<py::PObject<LDAModelObject>>(std::move(newInst));
569 auto inst = p->getInst<tomoto::ILDAModel>();
570 vector<uint8_t> extraData;
571 try
572 {
573 extraData.clear();
574 inst->loadModel(str, &extraData);
575 }
576 catch (const tomoto::serializer::UnfitException&)
577 {
578 continue;
579 }
580 p->isPrepared = true;
581 return make_pair(std::move(p), std::move(extraData));
582 }
583 throw runtime_error{ std::string("'") + filename + std::string("' is not valid model file") };
584}
585
586std::pair<py::UniquePObj<LDAModelObject>, std::vector<uint8_t>> LDAModelObject::loads(PyObject* cls, const std::vector<uint8_t>& data)
587{

Callers

nothing calls this directly

Calls 4

buildPyTupleFunction · 0.85
clearMethod · 0.80
loadModelMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected