LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
std_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_APPS_STD_MATRIX_H
7#define DEEPLIMA_APPS_STD_MATRIX_H
8
9#include <cassert>
10#include <iostream>
11#include <limits>
12#include <memory>
13#include <vector>
14
15template <class T>
17{
18public:
19 StdVector(const std::vector<T>& input)
20 : m_vector(input) { }
21
22 inline T get(size_t idx) const
23 {
24 assert(idx < m_vector.size());
25 return m_vector[idx];
26 }
27
28protected:
29 const std::vector<T>& m_vector;
30};
31
32template <class T>
34{
35public:
36
38 {
39 }
40
41 // A copy of the vectors input points to (none if it is null). It used to
42 // initialize m_tensor with the pointer itself, which does not compile: no
43 // code had ever instantiated it
44 explicit StdMatrix(std::shared_ptr< std::vector< std::vector<T> > > input)
45 : m_tensor(input ? *input : std::vector< std::vector<T> >())
46 {
47 }
48
50 }
51
54 return *this;
55 }
56
58 // std::cerr << "Matrix Destroyed!\n";
59 }
60
61 inline size_t get(size_t time, size_t feat) const
62 {
63 assert(feat < std::numeric_limits<size_t>::max());
64 assert(time < std::numeric_limits<size_t>::max());
65
66 return m_tensor[feat][time];
67 }
68
69 void copy(const StdMatrix<T>& m){
71 }
72
74 inline size_t size() const
75 {
76 return m_tensor.size();
77 }
78
83 inline size_t dim() const
84 {
85 assert(m_tensor.size() > 0);
86 return m_tensor[0].size();
87 }
88
89 inline void resize(size_t new_size)
90 {
91 m_tensor.resize(new_size);
92 }
93
94 inline std::vector<T>& operator[](size_t index)
95 {
96 return m_tensor[index];
97 }
98
99 std::vector<std::vector<T>> m_tensor;
100protected:
101
102};
103
104#endif
size_t size() const
Return the number of elements in this matrix.
Definition std_matrix.h:74
size_t dim() const
Return the dimension of this matrix's vectors (their size).
Definition std_matrix.h:83
StdMatrix(const StdMatrix &m)
Definition std_matrix.h:49
StdMatrix & operator=(const StdMatrix &m)
Definition std_matrix.h:52
size_t get(size_t time, size_t feat) const
Definition std_matrix.h:61
void copy(const StdMatrix< T > &m)
Definition std_matrix.h:69
std::vector< T > & operator[](size_t index)
Definition std_matrix.h:94
void resize(size_t new_size)
Definition std_matrix.h:89
std::vector< std::vector< T > > m_tensor
Definition std_matrix.h:99
StdMatrix(std::shared_ptr< std::vector< std::vector< T > > > input)
Definition std_matrix.h:44
StdVector(const std::vector< T > &input)
Definition std_matrix.h:19
const std::vector< T > & m_vector
Definition std_matrix.h:29
T get(size_t idx) const
Definition std_matrix.h:22
STL namespace.