-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMat.hpp
More file actions
261 lines (230 loc) · 6.49 KB
/
Mat.hpp
File metadata and controls
261 lines (230 loc) · 6.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#ifndef ISL_CXX_Mat_IMPL_H
#define ISL_CXX_Mat_IMPL_H
#include "isl/Mat.h"
#include "isl/Val.hpp"
#include "isl/Vec.hpp"
#include "isl/Ctx.hpp"
#include "isl/IslBase.h"
#include "isl/IslException.h"
#include <string>
#include <cassert>
namespace isl {
inline isl_mat *Mat::GetCopy() const {
return isl_mat_copy((isl_mat *)This);
}
inline Mat &Mat::operator=(const Mat &Other) {
isl_mat *New = Other.GetCopy();
ctx = Other.Context();
isl_mat_free((isl_mat *)This);
This = New;
return *this;
}
inline Mat Mat::alloc(const Ctx &ctx, unsigned int n_row, unsigned int n_col) {
const Ctx &_ctx = ctx.Context();
_ctx.lock();
isl_mat *That = isl_mat_alloc((ctx.Get()), n_row, n_col);
_ctx.unlock();
if (_ctx.hasError()) {
handleError("isl_mat_alloc returned a NULL pointer.");
}
return Mat(_ctx, That);
}
inline Mat Mat::fromRowVec(const Vec &vec) {
const Ctx &_ctx = vec.Context();
_ctx.lock();
isl_mat *That = isl_mat_from_row_vec((vec).GetCopy());
_ctx.unlock();
if (_ctx.hasError()) {
handleError("isl_mat_from_row_vec returned a NULL pointer.");
}
return Mat(_ctx, That);
}
inline Mat::~Mat() {
isl_mat_free((isl_mat *)This);
This = nullptr;
}
/// rief Release ownership of the wrapped object.
///
/// You are on your own now buddy.
/// The wrapper cannot be used anymore after calling Give()
///
///@return the wrapped isl object.
inline isl_mat *Mat::Give() {
isl_mat *res = (isl_mat *)This;
This = nullptr;
return res;
}
/// \brief Unwrap the stored isl object.
/// \returns A the wrapped isl object.
inline isl_mat *Mat::Get() const { return (isl_mat *)This;
}
inline Mat Mat::addRows(unsigned int n) const {
ctx.lock();
isl_mat * res = isl_mat_add_rows((*this).GetCopy(), n);
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_mat_add_rows returned a NULL pointer.");
}
return Mat(ctx, res);
}
inline Mat Mat::addZeroCols(unsigned int n) const {
ctx.lock();
isl_mat * res = isl_mat_add_zero_cols((*this).GetCopy(), n);
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_mat_add_zero_cols returned a NULL pointer.");
}
return Mat(ctx, res);
}
inline Mat Mat::addZeroRows(unsigned int n) const {
ctx.lock();
isl_mat * res = isl_mat_add_zero_rows((*this).GetCopy(), n);
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_mat_add_zero_rows returned a NULL pointer.");
}
return Mat(ctx, res);
}
inline int Mat::cols() const {
ctx.lock();
int res = isl_mat_cols((*this).Get());
ctx.unlock();
return res;
}
inline Mat Mat::concat(const Mat &bot) const {
ctx.lock();
isl_mat * res = isl_mat_concat((*this).GetCopy(), (bot).GetCopy());
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_mat_concat returned a NULL pointer.");
}
return Mat(ctx, res);
}
inline Val Mat::getElementVal(int row, int col) const {
ctx.lock();
isl_val * res = isl_mat_get_element_val((*this).Get(), row, col);
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_mat_get_element_val returned a NULL pointer.");
}
return Val(ctx, res);
}
inline int Mat::initialNonZeroCols() const {
ctx.lock();
int res = isl_mat_initial_non_zero_cols((*this).Get());
ctx.unlock();
return res;
}
inline Mat Mat::insertCols(unsigned int col, unsigned int n) const {
ctx.lock();
isl_mat * res = isl_mat_insert_cols((*this).GetCopy(), col, n);
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_mat_insert_cols returned a NULL pointer.");
}
return Mat(ctx, res);
}
inline Mat Mat::insertRows(unsigned int row, unsigned int n) const {
ctx.lock();
isl_mat * res = isl_mat_insert_rows((*this).GetCopy(), row, n);
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_mat_insert_rows returned a NULL pointer.");
}
return Mat(ctx, res);
}
inline Mat Mat::insertZeroCols(unsigned int first, unsigned int n) const {
ctx.lock();
isl_mat * res = isl_mat_insert_zero_cols((*this).GetCopy(), first, n);
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_mat_insert_zero_cols returned a NULL pointer.");
}
return Mat(ctx, res);
}
inline Mat Mat::insertZeroRows(unsigned int row, unsigned int n) const {
ctx.lock();
isl_mat * res = isl_mat_insert_zero_rows((*this).GetCopy(), row, n);
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_mat_insert_zero_rows returned a NULL pointer.");
}
return Mat(ctx, res);
}
inline int Mat::isEqual(const Mat &mat2) const {
ctx.lock();
int res = isl_mat_is_equal((*this).Get(), (mat2).Get());
ctx.unlock();
return res;
}
inline Mat Mat::moveCols(unsigned int dst_col, unsigned int src_col, unsigned int n) const {
ctx.lock();
isl_mat * res = isl_mat_move_cols((*this).GetCopy(), dst_col, src_col, n);
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_mat_move_cols returned a NULL pointer.");
}
return Mat(ctx, res);
}
inline Mat Mat::normalize() const {
ctx.lock();
isl_mat * res = isl_mat_normalize((*this).GetCopy());
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_mat_normalize returned a NULL pointer.");
}
return Mat(ctx, res);
}
inline Mat Mat::normalizeRow(int row) const {
ctx.lock();
isl_mat * res = isl_mat_normalize_row((*this).GetCopy(), row);
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_mat_normalize_row returned a NULL pointer.");
}
return Mat(ctx, res);
}
inline Mat Mat::rightInverse() const {
ctx.lock();
isl_mat * res = isl_mat_right_inverse((*this).GetCopy());
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_mat_right_inverse returned a NULL pointer.");
}
return Mat(ctx, res);
}
inline Mat Mat::rightKernel() const {
ctx.lock();
isl_mat * res = isl_mat_right_kernel((*this).GetCopy());
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_mat_right_kernel returned a NULL pointer.");
}
return Mat(ctx, res);
}
inline int Mat::rows() const {
ctx.lock();
int res = isl_mat_rows((*this).Get());
ctx.unlock();
return res;
}
inline Mat Mat::setElementVal(int row, int col, const Val &v) const {
ctx.lock();
isl_mat * res = isl_mat_set_element_val((*this).GetCopy(), row, col, (v).GetCopy());
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_mat_set_element_val returned a NULL pointer.");
}
return Mat(ctx, res);
}
inline Mat Mat::vecConcat(const Vec &bot) const {
ctx.lock();
isl_mat * res = isl_mat_vec_concat((*this).GetCopy(), (bot).GetCopy());
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_mat_vec_concat returned a NULL pointer.");
}
return Mat(ctx, res);
}
} // namespace isl
#endif //ISL_CXX_Mat_IMPL_H