| 556 | } |
| 557 | |
| 558 | std::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 | |
| 586 | std::pair<py::UniquePObj<LDAModelObject>, std::vector<uint8_t>> LDAModelObject::loads(PyObject* cls, const std::vector<uint8_t>& data) |
| 587 | { |
nothing calls this directly
no test coverage detected