Documentation of
CSL
include
librarytensor_hdata.h
Go to the documentation of this file.
1
// This file is part of MARTY.
2
//
3
// MARTY is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, either version 3 of the License, or
6
// (at your option) any later version.
7
//
8
// MARTY is distributed in the hope that it will be useful,
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
// GNU General Public License for more details.
12
//
13
// You should have received a copy of the GNU General Public License
14
// along with MARTY. If not, see <https://www.gnu.org/licenses/>.
15
23
#pragma once
24
25
#include <iostream>
26
27
namespace
csl
{
28
29
void
print_librarytensor_hdata(std::ostream &out) {
30
out <<
"#ifndef CSL_LIBRARYTENSOR_H_INCLUDED\n"
;
31
out <<
"#define CSL_LIBRARYTENSOR_H_INCLUDED\n"
;
32
out <<
"\n"
;
33
out <<
"#include <vector>\n"
;
34
out <<
"#include <iostream>\n"
;
35
out <<
"#include \"csl/default_move_cpy.h\"\n"
;
36
out <<
"\n"
;
37
out <<
"namespace csl {\n"
;
38
out <<
"\n"
;
39
out <<
" template<class Type>\n"
;
40
out <<
" class LibraryTensor {\n"
;
41
out <<
"\n"
;
42
out <<
" public:\n"
;
43
out <<
"\n"
;
44
out <<
" DEFINE_DEFAULT_CPY_MV(LibraryTensor)\n"
;
45
out <<
"\n"
;
46
out <<
" using iterator = typename std::vector<Type>::iterator;\n"
;
47
out <<
" using const_iterator = typename std::vector<Type>::const_iterator;\n"
;
48
out <<
" using reverse_iterator \n"
;
49
out <<
" = typename std::vector<Type>::reverse_iterator;\n"
;
50
out <<
" using const_reverse_iterator \n"
;
51
out <<
" = typename std::vector<Type>::const_reverse_iterator;\n"
;
52
out <<
"\n"
;
53
out <<
" static size_t getTotalDimension(std::vector<size_t> const& dimensions)\n"
;
54
out <<
" {\n"
;
55
out <<
" size_t tot = 1;\n"
;
56
out <<
" for (size_t d : dimensions)\n"
;
57
out <<
" tot *= d;\n"
;
58
out <<
" return tot;\n"
;
59
out <<
" }\n"
;
60
out <<
"\n"
;
61
out <<
" LibraryTensor(std::vector<size_t> const& t_dimensions)\n"
;
62
out <<
" :dimensions(t_dimensions),\n"
;
63
out <<
" data(getTotalDimension(dimensions))\n"
;
64
out <<
" {\n"
;
65
out <<
"\n"
;
66
out <<
" }\n"
;
67
out <<
"\n"
;
68
out <<
" LibraryTensor(std::vector<size_t> const& t_dimensions,\n"
;
69
out <<
" Type const& filler)\n"
;
70
out <<
" :dimensions(t_dimensions),\n"
;
71
out <<
" data(getTotalDimension(dimensions), filler)\n"
;
72
out <<
" {\n"
;
73
out <<
"\n"
;
74
out <<
" }\n"
;
75
out <<
"\n"
;
76
out <<
" LibraryTensor(std::vector<size_t> const& t_dimensions,\n"
;
77
out <<
" std::vector<Type> const& t_data)\n"
;
78
out <<
" :dimensions(t_dimensions),\n"
;
79
out <<
" data(t_data)\n"
;
80
out <<
" {\n"
;
81
out <<
" if (getTotalDimension(dimensions) != data.size()) {\n"
;
82
out <<
" std::cerr << \"Bad initialization of LibraryTensor in file \"\n"
;
83
out <<
" << __FILE__ << \" (l. \" << __LINE__ << \"): expected \"\n"
;
84
out <<
" << getTotalDimension(dimensions) << \" elements, \"\n"
;
85
out <<
" << data.size() << \" given.\\n\";\n"
;
86
out <<
" exit(123);\n"
;
87
out <<
" }\n"
;
88
out <<
" }\n"
;
89
out <<
" \n"
;
90
out <<
" std::vector<size_t> const& getDimensions() const {\n"
;
91
out <<
" return dimensions;\n"
;
92
out <<
" }\n"
;
93
out <<
" std::vector<Type> const& toStdVector() const {\n"
;
94
out <<
" return data;\n"
;
95
out <<
" }\n"
;
96
out <<
"\n"
;
97
out <<
" size_t getIndex(std::vector<size_t> const& indices) const {\n"
;
98
out <<
" if (dimensions.size() == 1)\n"
;
99
out <<
" return indices[0];\n"
;
100
out <<
" size_t index = 0;\n"
;
101
out <<
" auto iter_index = indices.begin();\n"
;
102
out <<
" auto iter_dim = dimensions.begin();\n"
;
103
out <<
" for (; iter_dim != dimensions.end(); ++iter_index, ++iter_dim) {\n"
;
104
out <<
" index *= *iter_dim;\n"
;
105
out <<
" index += *iter_index;\n"
;
106
out <<
" }\n"
;
107
out <<
"\n"
;
108
out <<
" return index;\n"
;
109
out <<
" }\n"
;
110
out <<
"\n"
;
111
out <<
" bool empty() const {\n"
;
112
out <<
" return data.empty();\n"
;
113
out <<
" }\n"
;
114
out <<
" size_t size() const {\n"
;
115
out <<
" return data.size();\n"
;
116
out <<
" }\n"
;
117
out <<
"\n"
;
118
out <<
"#ifndef CSL_LT_DISABLE_ITERATOR\n"
;
119
out <<
" iterator begin() {\n"
;
120
out <<
" return data.begin();\n"
;
121
out <<
" }\n"
;
122
out <<
" iterator end() {\n"
;
123
out <<
" return data.end();\n"
;
124
out <<
" }\n"
;
125
out <<
" const_iterator begin() const {\n"
;
126
out <<
" return data.begin();\n"
;
127
out <<
" }\n"
;
128
out <<
" const_iterator end() const {\n"
;
129
out <<
" return data.end();\n"
;
130
out <<
" }\n"
;
131
out <<
"\n"
;
132
out <<
" reverse_iterator rbegin() {\n"
;
133
out <<
" return data.rbegin();\n"
;
134
out <<
" }\n"
;
135
out <<
" reverse_iterator rend() {\n"
;
136
out <<
" return data.rend();\n"
;
137
out <<
" }\n"
;
138
out <<
" const_reverse_iterator rbegin() const {\n"
;
139
out <<
" return data.rbegin();\n"
;
140
out <<
" }\n"
;
141
out <<
" const_reverse_iterator rend() const {\n"
;
142
out <<
" return data.rend();\n"
;
143
out <<
" }\n"
;
144
out <<
"#endif\n"
;
145
out <<
"\n"
;
146
out <<
" Type& operator[](size_t pos) {\n"
;
147
out <<
" return data[pos];\n"
;
148
out <<
" }\n"
;
149
out <<
" Type const& operator[](size_t pos) const {\n"
;
150
out <<
" return data[pos];\n"
;
151
out <<
" }\n"
;
152
out <<
"\n"
;
153
out <<
" Type& operator[](std::vector<size_t> const& indices) {\n"
;
154
out <<
" return data[getIndex(indices)];\n"
;
155
out <<
" }\n"
;
156
out <<
" Type const& operator[](std::vector<size_t> const& indices) const {\n"
;
157
out <<
" return data[getIndex(indices)];\n"
;
158
out <<
" }\n"
;
159
out <<
"\n"
;
160
out <<
" public:\n"
;
161
out <<
"\n"
;
162
out <<
" std::vector<size_t> dimensions;\n"
;
163
out <<
"\n"
;
164
out <<
" std::vector<Type> data;\n"
;
165
out <<
" };\n"
;
166
out <<
"\n"
;
167
out <<
"} // End of namespace csl\n"
;
168
out <<
"\n"
;
169
out <<
"#endif // ifndef CSL_LIBRARYTENSOR_H_INCLUDED\n"
;
170
}
171
172
}
// End of namespace csl
csl
Namespace for csl library.
Definition:
abreviation.h:34
Generated by
1.8.13