LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
eigen_matrix.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_EIGEN_EIGEN_MATRIX_H
7#define DEEPLIMA_SRC_INFERENCE_EIGEN_EIGEN_MATRIX_H
8
9#include <eigen3/Eigen/Dense>
10
11namespace deeplima
12{
13namespace eigen_wrp
14{
15
16template <class M>
18{
19public:
20 typedef M matrix_t;
21 typedef typename M::Scalar value_t;
22
24 : m_start_time(0),
25 m_max_time(0)
26 {}
27
28 EigenMatrix(int64_t max_time, int64_t max_feat)
29 : m_start_time(0),
30 m_max_time(max_time)
31 {
32 assert(m_start_time >= 0);
33 assert(m_max_time > m_start_time);
34 assert(max_feat > 0);
35 assert(max_feat < std::numeric_limits<int64_t>::max());
36
37 m_tensor.resize(max_feat, m_max_time - m_start_time);
38 }
39
40 void init(int64_t max_time, int64_t max_feat)
41 {
42 assert(m_start_time >= 0);
43 assert(max_time > m_start_time);
44 assert(max_feat > 0);
45 assert(max_feat < std::numeric_limits<int64_t>::max());
46
47 m_max_time = max_time;
48 m_tensor = M::Zero(max_feat, m_max_time - m_start_time);
49 }
50
51 inline void set(uint64_t time, uint64_t feat, value_t value)
52 {
53 assert(feat < std::numeric_limits<int64_t>::max());
54 assert(time < std::numeric_limits<int64_t>::max() - m_start_time);
55 assert(time < m_tensor.cols());
56
57 m_tensor(feat, m_start_time + time) = value;
58 }
59
60 inline void set(uint64_t time, EigenMatrix<M>& src, uint64_t src_time)
61 {
62 m_tensor.col(time) = src.m_tensor.col(src_time);
63 }
64
65 inline value_t get(uint64_t time, uint64_t feat)
66 {
67 assert(feat < std::numeric_limits<int64_t>::max());
68 assert(time < std::numeric_limits<int64_t>::max() - m_start_time);
69
70 return m_tensor(feat, m_start_time + time);
71 }
72
73 inline uint64_t size() const
74 {
75 return m_max_time - m_start_time;
76 }
77
78 inline uint64_t get_max_feat() const
79 {
80 return m_tensor.rows();
81 }
82
83 inline const M& get_tensor() const
84 {
85 return m_tensor;
86 }
87
88protected:
89
91 {
92 return m_tensor;
93 }
94 int64_t m_start_time;
95 int64_t m_max_time;
96
98};
99
102
103} // namespace eigen_wrp
104} // namespace deeplima
105
106#endif
void set(uint64_t time, uint64_t feat, value_t value)
value_t get(uint64_t time, uint64_t feat)
EigenMatrix(int64_t max_time, int64_t max_feat)
void init(int64_t max_time, int64_t max_feat)
void set(uint64_t time, EigenMatrix< M > &src, uint64_t src_time)
EigenMatrix< Eigen::MatrixXi > EigenMatrixXi
EigenMatrix< Eigen::MatrixXf > EigenMatrixXf