LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
dict_vectorizer.h
Go to the documentation of this file.
1// Copyright 2021 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6#ifndef DEEPLIMA_SRC_INFERENCE_TORCH_DICT_VECTORIZER_H
7#define DEEPLIMA_SRC_INFERENCE_TORCH_DICT_VECTORIZER_H
8
9#include <vector>
10#include <cassert>
11
12namespace deeplima
13{
14
15template <class DH, class D, class Matrix>
16class DictVectorizer : public Matrix
17{
18public:
19
21
22 DictVectorizer(int64_t max_time, int64_t max_feat)
23 : Matrix(max_time, max_feat)
24 {
25 // std::cerr << "DictVectorizer::DictVectorizer()" << std::endl;
26 }
27
28 void init(const DH& dicts, int64_t max_time, int64_t max_feat)
29 {
30 set_dicts(dicts);
31 Matrix::init(max_time, max_feat);
32 }
33
34 void set_dicts(const DH& dicts)
35 {
36 assert(Matrix::get_max_feat() == dicts.size());
37 m_dicts.reserve(dicts.size());
38 for (const auto& ptr : dicts)
39 {
40 m_dicts.emplace_back(dynamic_cast<const D*>(ptr.get()));
41 }
42 }
43
44 inline void set(uint64_t time, uint64_t feat, typename D::value_t value)
45 {
46 assert(feat < m_dicts.size());
47 key_t k = m_dicts[feat]->get_idx(value);
48 Matrix::set(time, feat, k);
49 }
50
51protected:
52 std::vector<const D*> m_dicts;
53};
54
55} // namespace deeplima
56
57#endif
void set_dicts(const DH &dicts)
DictVectorizer(int64_t max_time, int64_t max_feat)
std::vector< const D * > m_dicts
void set(uint64_t time, uint64_t feat, typename D::value_t value)
void init(const DH &dicts, int64_t max_time, int64_t max_feat)