| 1 |
/* |
| 2 |
* Advanced Simulation Library <http://asl.org.il> |
| 3 |
* |
| 4 |
* Copyright 2015 Avtech Scientific <http://avtechscientific.com> |
| 5 |
* |
| 6 |
* |
| 7 |
* This file is part of Advanced Simulation Library (ASL). |
| 8 |
* |
| 9 |
* ASL is free software: you can redistribute it and/or modify it |
| 10 |
* under the terms of the GNU Affero General Public License as |
| 11 |
* published by the Free Software Foundation, version 3 of the License. |
| 12 |
* |
| 13 |
* ASL is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU Affero General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Affero General Public License |
| 19 |
* along with ASL. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
* |
| 21 |
*/ |
| 22 |
|
| 23 |
|
| 24 |
#include "aclGenerators.h" |
| 25 |
#include "aclMath/aclVectorOfElements.h" |
| 26 |
#include "acl.h" |
| 27 |
#include "DataTypes/aclConstant.h" |
| 28 |
#include "DataTypes/aclArray.h" |
| 29 |
#include "DataTypes/aclSubvector.h" |
| 30 |
#include "DataTypes/aclVariableReference.h" |
| 31 |
#include "DataTypes/aclVariableSP.h" |
| 32 |
#include "DataTypes/aclPrivateVariable.h" |
| 33 |
#include "DataTypes/aclPrivateArray.h" |
| 34 |
#include "DataTypes/aclIndex.h" |
| 35 |
#include "DataTypes/aclIndexExt.h" |
| 36 |
#include "DataTypes/aclGroupID.h" |
| 37 |
|
| 38 |
#include "aclTypesList.h" |
| 39 |
|
| 40 |
|
| 41 |
namespace acl |
| 42 |
{ |
| 43 |
|
| 44 |
template <typename T> VectorOfElements generateVEConstant(T a) |
| 45 |
{ |
| 46 |
VectorOfElements v(1); |
| 47 |
v[0] = Element(new Constant<T>(a)); |
| 48 |
return v; |
| 49 |
} |
| 50 |
|
| 51 |
#define BOOST_TT_rep_expression(r, data, t) \ |
| 52 |
template VectorOfElements generateVEConstant(t a); |
| 53 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 54 |
#undef BOOST_TT_rep_expression |
| 55 |
|
| 56 |
template <typename T> VectorOfElements generateVEConstant(T a, T b) |
| 57 |
{ |
| 58 |
VectorOfElements v(2); |
| 59 |
v[0] = Element(new Constant<T>(a)); |
| 60 |
v[1] = Element(new Constant<T>(b)); |
| 61 |
return v; |
| 62 |
} |
| 63 |
|
| 64 |
#define BOOST_TT_rep_expression(r, data, t) \ |
| 65 |
template VectorOfElements generateVEConstant(t a, t b); |
| 66 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 67 |
#undef BOOST_TT_rep_expression |
| 68 |
|
| 69 |
template <typename T> VectorOfElements generateVEConstant(T a, T b, T c) |
| 70 |
{ |
| 71 |
VectorOfElements v(3); |
| 72 |
v[0] = Element(new Constant<T>(a)); |
| 73 |
v[1] = Element(new Constant<T>(b)); |
| 74 |
v[2] = Element(new Constant<T>(c)); |
| 75 |
return v; |
| 76 |
} |
| 77 |
|
| 78 |
#define BOOST_TT_rep_expression(r, data, t) \ |
| 79 |
template VectorOfElements generateVEConstant(t a, t b, t c); |
| 80 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 81 |
#undef BOOST_TT_rep_expression |
| 82 |
|
| 83 |
|
| 84 |
template <typename T> VectorOfElements generateVEConstantN(unsigned int n, T a) |
| 85 |
{ |
| 86 |
VectorOfElements v(n); |
| 87 |
v[0] = Element(new Constant<T>(a)); |
| 88 |
for (unsigned int i(1); i < n; ++i) |
| 89 |
v[i] = v[0]; |
| 90 |
return v; |
| 91 |
} |
| 92 |
|
| 93 |
#define BOOST_TT_rep_expression(r, data, t) \ |
| 94 |
template VectorOfElements generateVEConstantN(unsigned int n, t a); |
| 95 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 96 |
#undef BOOST_TT_rep_expression |
| 97 |
|
| 98 |
template <typename T> VectorOfElements generateVEConstant(unsigned int n, |
| 99 |
const T* const a) |
| 100 |
{ |
| 101 |
VectorOfElements v(n); |
| 102 |
for (unsigned int i(0); i < n; ++i) |
| 103 |
v[i] = Element(new Constant<T>(a[i])); |
| 104 |
return v; |
| 105 |
} |
| 106 |
|
| 107 |
#define BOOST_TT_rep_expression(r, data, t) \ |
| 108 |
template VectorOfElements generateVEConstant(unsigned int n, const t* const a); |
| 109 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 110 |
#undef BOOST_TT_rep_expression |
| 111 |
|
| 112 |
template <typename T> VectorOfElements generateVEConstant(const vector<T> & a) |
| 113 |
{ |
| 114 |
return generateVEConstant(a.size(), &a[0]); |
| 115 |
} |
| 116 |
|
| 117 |
#define BOOST_TT_rep_expression(r, data, t) \ |
| 118 |
template VectorOfElements generateVEConstant(const vector<t> & a); |
| 119 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 120 |
#undef BOOST_TT_rep_expression |
| 121 |
|
| 122 |
template <typename T> VectorOfElements generateVEConstant(const asl::AVec<T> &a) |
| 123 |
{ |
| 124 |
VectorOfElements v(a.getSize()); |
| 125 |
for (unsigned int i(0); i < a.getSize(); ++i) |
| 126 |
v[i] = Element(new Constant<T>(a[i])); |
| 127 |
return v; |
| 128 |
} |
| 129 |
|
| 130 |
#define BOOST_TT_rep_expression(r, data, t) \ |
| 131 |
template VectorOfElements generateVEConstant(const asl::AVec<t> &a); |
| 132 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 133 |
#undef BOOST_TT_rep_expression |
| 134 |
|
| 135 |
template <typename T> MatrixOfElements generateMEConstant(const asl::AMatr<T> &a) |
| 136 |
{ |
| 137 |
MatrixOfElements m(a.getNRow(), a.getNCol()); |
| 138 |
copy(generateVEConstant(a.getInternalVec()), |
| 139 |
m.getInternalVector()); |
| 140 |
return m; |
| 141 |
} |
| 142 |
|
| 143 |
template MatrixOfElements generateMEConstant(const asl::AMatr<double> &a); |
| 144 |
template MatrixOfElements generateMEConstant(const asl::AMatr<float> &a); |
| 145 |
|
| 146 |
template <typename T> |
| 147 |
VectorOfElementsData generateVEData(unsigned int length, |
| 148 |
unsigned int nComponents, |
| 149 |
CommandQueue queue) |
| 150 |
{ |
| 151 |
VectorOfElementsData v(nComponents); |
| 152 |
for (unsigned int i(0); i < nComponents; ++i) |
| 153 |
v[i] = ElementData(new Array<T>(length, queue)); |
| 154 |
return v; |
| 155 |
} |
| 156 |
|
| 157 |
#define BOOST_TT_rep_expression(r, data, t) \ |
| 158 |
template VectorOfElementsData generateVEData<t>(unsigned int length, \ |
| 159 |
unsigned int nComponents, \ |
| 160 |
CommandQueue queue); |
| 161 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 162 |
#undef BOOST_TT_rep_expression |
| 163 |
|
| 164 |
template <typename T> |
| 165 |
VectorOfElementsData generateVEData(unsigned int length, |
| 166 |
unsigned int nComponents) |
| 167 |
{ |
| 168 |
return generateVEData<T>(length,nComponents,hardware.defaultQueue); |
| 169 |
} |
| 170 |
|
| 171 |
#define BOOST_TT_rep_expression(r, data, t) \ |
| 172 |
template VectorOfElementsData generateVEData<t>(unsigned int length, \ |
| 173 |
unsigned int nComponents); |
| 174 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 175 |
#undef BOOST_TT_rep_expression |
| 176 |
|
| 177 |
VectorOfElementsData generateVEData(unsigned int length, |
| 178 |
TypeID typeID, |
| 179 |
unsigned int nComponents, |
| 180 |
CommandQueue queue) |
| 181 |
{ |
| 182 |
VectorOfElementsData v(nComponents); |
| 183 |
for (unsigned int i(0); i < nComponents; ++i) |
| 184 |
v[i] = generateElementArray(typeID, length, queue); |
| 185 |
return v; |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
VectorOfElements generateVELocalArray(unsigned int componentSize, |
| 190 |
TypeID typeID, |
| 191 |
unsigned int size) |
| 192 |
{ |
| 193 |
VectorOfElements v(size); |
| 194 |
for (unsigned int i(0); i < size; ++i) |
| 195 |
v[i] = generateElementLocalArray(typeID, componentSize); |
| 196 |
return v; |
| 197 |
} |
| 198 |
|
| 199 |
template <typename T> VectorOfElements generateVEPrivateArray(const vector<T> & data) |
| 200 |
{ |
| 201 |
VectorOfElements v(1); |
| 202 |
v[0] = Element(new PrivateArray<T>(data)); |
| 203 |
return v; |
| 204 |
} |
| 205 |
#define BOOST_TT_rep_expression(r, data, T) \ |
| 206 |
template VectorOfElements generateVEPrivateArray(const vector<T> & d); |
| 207 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 208 |
#undef BOOST_TT_rep_expression |
| 209 |
|
| 210 |
template <typename T> VectorOfElements generateVEPrivateArray(const vector<asl::AVec<T>> & data) |
| 211 |
{ |
| 212 |
unsigned int nd(data[0].getSize()); |
| 213 |
VectorOfElements v(nd); |
| 214 |
vector<T> d(data.size()); |
| 215 |
for(unsigned int i(0); i < nd; ++i) |
| 216 |
{ |
| 217 |
for(unsigned int j(0); j < data.size(); ++j) |
| 218 |
d[j] = data[j][i]; |
| 219 |
v[i] = Element(new PrivateArray<T>(d)); |
| 220 |
} |
| 221 |
return v; |
| 222 |
} |
| 223 |
#define BOOST_TT_rep_expression(r, data, T) \ |
| 224 |
template VectorOfElements generateVEPrivateArray(const vector<asl::AVec<T>> & d); |
| 225 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 226 |
#undef BOOST_TT_rep_expression |
| 227 |
|
| 228 |
|
| 229 |
template <typename T> VectorOfElements generateVEPrivateArray(const vector<T> & d, |
| 230 |
TypeID typeID) |
| 231 |
{ |
| 232 |
VectorOfElements v(1); |
| 233 |
switch (typeID) |
| 234 |
{ |
| 235 |
#define BOOST_TT_rep_expression(r, data, tt) \ |
| 236 |
case typeToTypeID<tt>(): \ |
| 237 |
{ \ |
| 238 |
vector<tt> newD(d.size()); \ |
| 239 |
copy(d.begin(),d.end(),newD.begin()); \ |
| 240 |
copy(generateVEPrivateArray(newD), v); \ |
| 241 |
} \ |
| 242 |
break; |
| 243 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 244 |
#undef BOOST_TT_rep_expression |
| 245 |
} |
| 246 |
return v; |
| 247 |
} |
| 248 |
#define BOOST_TT_rep_expression(r, data, T) \ |
| 249 |
template VectorOfElements generateVEPrivateArray(const vector<T> & d, TypeID typeID); |
| 250 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 251 |
#undef BOOST_TT_rep_expression |
| 252 |
|
| 253 |
template <typename T> VectorOfElements generateVEPrivateArray(const vector<asl::AVec<T>> & d, |
| 254 |
TypeID typeID) |
| 255 |
{ |
| 256 |
VectorOfElements v(1); |
| 257 |
switch (typeID) |
| 258 |
{ |
| 259 |
#define BOOST_TT_rep_expression(r, data, tt) \ |
| 260 |
case typeToTypeID<tt>(): \ |
| 261 |
{ \ |
| 262 |
vector<asl::AVec<tt>> newD(d.size()); \ |
| 263 |
copy(d.begin(),d.end(),newD.begin()); \ |
| 264 |
copy(generateVEPrivateArray(newD), v); \ |
| 265 |
} \ |
| 266 |
break; |
| 267 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 268 |
#undef BOOST_TT_rep_expression |
| 269 |
} |
| 270 |
return v; |
| 271 |
} |
| 272 |
#define BOOST_TT_rep_expression(r, data, T) \ |
| 273 |
template VectorOfElements generateVEPrivateArray(const vector<asl::AVec<T>> & d, TypeID typeID); |
| 274 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 275 |
#undef BOOST_TT_rep_expression |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
template <typename T> |
| 280 |
VectorOfElements generateVEDataSub(T, |
| 281 |
unsigned int sublength, |
| 282 |
unsigned int length, |
| 283 |
unsigned int nComponents, |
| 284 |
CommandQueue queue) |
| 285 |
{ |
| 286 |
VectorOfElements v(nComponents); |
| 287 |
for (unsigned int i(0); i < nComponents; ++i) |
| 288 |
{ |
| 289 |
shared_ptr<Array<T> > vec(new Array<T>(length, queue)); |
| 290 |
v[i] = Element(new Subvector<T>(vec, sublength, 0u)); |
| 291 |
} |
| 292 |
return v; |
| 293 |
} |
| 294 |
|
| 295 |
#define BOOST_TT_rep_expression(r, data, t) \ |
| 296 |
template VectorOfElements generateVEDataSub(t, \ |
| 297 |
unsigned int sublength, \ |
| 298 |
unsigned int length, \ |
| 299 |
unsigned int nComponents, \ |
| 300 |
CommandQueue queue); |
| 301 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 302 |
#undef BOOST_TT_rep_expression |
| 303 |
|
| 304 |
template <typename T> VectorOfElements generateVEVariableR(T& a) |
| 305 |
{ |
| 306 |
VectorOfElements v(1); |
| 307 |
v[0] = Element(new VariableReference<T>(a)); |
| 308 |
return v; |
| 309 |
} |
| 310 |
|
| 311 |
#define BOOST_TT_rep_expression(r, data, t) \ |
| 312 |
template VectorOfElements generateVEVariableR(t & a); |
| 313 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 314 |
#undef BOOST_TT_rep_expression |
| 315 |
|
| 316 |
template <typename T> VectorOfElements generateVEVariableR(T& a, T& b) |
| 317 |
{ |
| 318 |
VectorOfElements v(2); |
| 319 |
v[0] = Element(new VariableReference<T>(a)); |
| 320 |
v[1] = Element(new VariableReference<T>(b)); |
| 321 |
return v; |
| 322 |
} |
| 323 |
|
| 324 |
#define BOOST_TT_rep_expression(r, data, t) \ |
| 325 |
template VectorOfElements generateVEVariableR(t & a, t & b); |
| 326 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 327 |
#undef BOOST_TT_rep_expression |
| 328 |
|
| 329 |
template <typename T> VectorOfElements generateVEVariableR(T& a, T& b, T& c) |
| 330 |
{ |
| 331 |
VectorOfElements v(3); |
| 332 |
v[0] = Element(new VariableReference<T>(a)); |
| 333 |
v[1] = Element(new VariableReference<T>(b)); |
| 334 |
v[2] = Element(new VariableReference<T>(c)); |
| 335 |
return v; |
| 336 |
} |
| 337 |
|
| 338 |
#define BOOST_TT_rep_expression(r, data, t) \ |
| 339 |
template VectorOfElements generateVEVariableR(t & a, t & b, t & c); |
| 340 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 341 |
#undef BOOST_TT_rep_expression |
| 342 |
|
| 343 |
template <typename T> VectorOfElements generateVEVariableR(asl::AVec<T>& a) |
| 344 |
{ |
| 345 |
unsigned int n(nD(a)); |
| 346 |
VectorOfElements v(n); |
| 347 |
for (unsigned int i(0); i < n; ++i) |
| 348 |
v[i] = Element(new VariableReference<T>(a[i])); |
| 349 |
return v; |
| 350 |
} |
| 351 |
|
| 352 |
#define BOOST_TT_rep_expression(r, data, t) \ |
| 353 |
template VectorOfElements generateVEVariableR(asl::AVec<t> & a); |
| 354 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 355 |
#undef BOOST_TT_rep_expression |
| 356 |
|
| 357 |
template <typename T> VectorOfElements generateVEVariableSP(std::shared_ptr<T> a) |
| 358 |
{ |
| 359 |
VectorOfElements v(1); |
| 360 |
v[0] = Element(new VariableSP<T>(a)); |
| 361 |
return v; |
| 362 |
} |
| 363 |
|
| 364 |
#define BOOST_TT_rep_expression(r, data, t) \ |
| 365 |
template VectorOfElements generateVEVariableSP(std::shared_ptr<t> a); |
| 366 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 367 |
#undef BOOST_TT_rep_expression |
| 368 |
|
| 369 |
template <typename T> VectorOfElements generateVEVariableSP(std::shared_ptr<T> a, |
| 370 |
std::shared_ptr<T> b) |
| 371 |
{ |
| 372 |
VectorOfElements v(2); |
| 373 |
v[0] = Element(new VariableSP<T>(a)); |
| 374 |
v[1] = Element(new VariableSP<T>(b)); |
| 375 |
return v; |
| 376 |
} |
| 377 |
|
| 378 |
#define BOOST_TT_rep_expression(r, data, t) \ |
| 379 |
template VectorOfElements generateVEVariableSP(std::shared_ptr<t> a, std::shared_ptr<t> b); |
| 380 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 381 |
#undef BOOST_TT_rep_expression |
| 382 |
|
| 383 |
template <typename T> VectorOfElements generateVEVariableSP(std::shared_ptr<T> a,std::shared_ptr<T> b, std::shared_ptr<T> c) |
| 384 |
{ |
| 385 |
VectorOfElements v(3); |
| 386 |
v[0] = Element(new VariableSP<T>(a)); |
| 387 |
v[1] = Element(new VariableSP<T>(b)); |
| 388 |
v[2] = Element(new VariableSP<T>(c)); |
| 389 |
return v; |
| 390 |
} |
| 391 |
|
| 392 |
#define BOOST_TT_rep_expression(r, data, t) \ |
| 393 |
template VectorOfElements generateVEVariableSP(std::shared_ptr<t> a, std::shared_ptr<t> b, std::shared_ptr<t> c); |
| 394 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 395 |
#undef BOOST_TT_rep_expression |
| 396 |
|
| 397 |
template <typename T> VectorOfElements generateVEVariableSP(std::shared_ptr<asl::AVec<T>> a) |
| 398 |
{ |
| 399 |
unsigned int n(nD(*a)); |
| 400 |
VectorOfElements v(n); |
| 401 |
for (unsigned int i(0); i < n; ++i) |
| 402 |
v[i] = Element(new VariableSP<T>(std::shared_ptr<T>(a, & (*a)[i]) )); |
| 403 |
return v; |
| 404 |
} |
| 405 |
|
| 406 |
#define BOOST_TT_rep_expression(r, data, t) \ |
| 407 |
template VectorOfElements generateVEVariableSP(std::shared_ptr<asl::AVec<t>> a); |
| 408 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 409 |
#undef BOOST_TT_rep_expression |
| 410 |
|
| 411 |
|
| 412 |
template <typename T> VectorOfElements generateVEPrivateVariable(unsigned int n) |
| 413 |
{ |
| 414 |
VectorOfElements v(n); |
| 415 |
for (unsigned int i(0); i < n; ++i) |
| 416 |
v[i] = Element(new PrivateVariable<T>()); |
| 417 |
return v; |
| 418 |
} |
| 419 |
|
| 420 |
#define BOOST_TT_rep_expression(r, data, t) \ |
| 421 |
template VectorOfElements generateVEPrivateVariable<t>(unsigned int i); |
| 422 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 423 |
#undef BOOST_TT_rep_expression |
| 424 |
|
| 425 |
VectorOfElements generateVEPrivateVariable(unsigned int n, TypeID t) |
| 426 |
{ |
| 427 |
VectorOfElements v; |
| 428 |
switch (t) |
| 429 |
{ |
| 430 |
#define BOOST_TT_rep_expression(r, data, tt) \ |
| 431 |
case typeToTypeID<tt>(): \ |
| 432 |
copy(generateVEPrivateVariable<tt>(n), v); \ |
| 433 |
break; |
| 434 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 435 |
#undef BOOST_TT_rep_expression |
| 436 |
} |
| 437 |
return v; |
| 438 |
} |
| 439 |
|
| 440 |
MatrixOfElements generateMEPrivateVariable(unsigned int nR, unsigned int nC, TypeID t) |
| 441 |
{ |
| 442 |
MatrixOfElements res(nR,nC); |
| 443 |
copy(generateVEPrivateVariable(nR*nC, t), res.getInternalVector()); |
| 444 |
return res; |
| 445 |
} |
| 446 |
|
| 447 |
|
| 448 |
VectorOfElements generateVESubElements(VectorOfElements a, |
| 449 |
unsigned int length, |
| 450 |
int offset) |
| 451 |
{ |
| 452 |
unsigned int n(a.size()); |
| 453 |
VectorOfElements v(n); |
| 454 |
for (unsigned int i(0); i < n; ++i) |
| 455 |
v[i] = generateSubElement(a[i], length, offset); |
| 456 |
return v; |
| 457 |
} |
| 458 |
|
| 459 |
|
| 460 |
VectorOfElements generateVESubElements(VectorOfElements a, |
| 461 |
unsigned int length, |
| 462 |
VectorOfElements offset) |
| 463 |
{ |
| 464 |
unsigned int n(a.size()); |
| 465 |
if (n != offset.size()) |
| 466 |
errorMessage("generateVESubElements(): two VectorOfElements have different sizes"); |
| 467 |
VectorOfElements v(n); |
| 468 |
for (unsigned int i(0); i < n; ++i) |
| 469 |
v[i] = generateSubElement(a[i], length, offset[i]); |
| 470 |
return v; |
| 471 |
} |
| 472 |
|
| 473 |
|
| 474 |
VectorOfElements generateVEShiftedElements(VectorOfElements a, |
| 475 |
int offset) |
| 476 |
{ |
| 477 |
unsigned int n(a.size()); |
| 478 |
VectorOfElements v(n); |
| 479 |
for (unsigned int i(0); i < n; ++i) |
| 480 |
v[i] = generateShiftedElement(a[i], offset); |
| 481 |
return v; |
| 482 |
} |
| 483 |
|
| 484 |
VectorOfElements generateVEShiftedElements(VectorOfElements a, |
| 485 |
VectorOfElements offset) |
| 486 |
{ |
| 487 |
unsigned int n(a.size()); |
| 488 |
if (n != offset.size()) |
| 489 |
errorMessage("generateVEShiftedElements(): two VectorOfElements have different sizes"); |
| 490 |
VectorOfElements v(n); |
| 491 |
for (unsigned int i(0); i < n; ++i) |
| 492 |
v[i] = generateShiftedElement(a[i], offset[i]); |
| 493 |
return v; |
| 494 |
} |
| 495 |
|
| 496 |
|
| 497 |
VectorOfElements generateVEShiftedElements(VectorOfElements a, |
| 498 |
const vector<int> & offset) |
| 499 |
{ |
| 500 |
unsigned int n(a.size()); |
| 501 |
if (n != offset.size()) |
| 502 |
errorMessage("generateVEShiftedElements(): VectorOfElements and vector<int> have different sizes"); |
| 503 |
VectorOfElements v(n); |
| 504 |
for (unsigned int i(0); i < n; ++i) |
| 505 |
v[i] = generateShiftedElement(a[i], offset[i]); |
| 506 |
return v; |
| 507 |
} |
| 508 |
|
| 509 |
|
| 510 |
VectorOfElements generateParsedVE(const VectorOfElements & fields, |
| 511 |
const vector<string> & names, |
| 512 |
const string & statement) |
| 513 |
{ |
| 514 |
if (fields.size() != names.size()) |
| 515 |
errorMessage("generateParsedVE(): VectorOfElements \"fields\" and vector<string> \"names\" have different sizes"); |
| 516 |
vector<pair<Element, string> > f(names.size()); |
| 517 |
for (unsigned int i(0); i < names.size(); ++i) |
| 518 |
{ |
| 519 |
f[i].first = fields[i]; |
| 520 |
f[i].second = names[i]; |
| 521 |
} |
| 522 |
|
| 523 |
VectorOfElements a(1u); |
| 524 |
a[0] = elementOperators::parse(f, statement); |
| 525 |
return a; |
| 526 |
} |
| 527 |
|
| 528 |
VectorOfElements generateVEPolynom(VectorOfElements x, |
| 529 |
VectorOfElements coefs) |
| 530 |
{ |
| 531 |
if (x.size() > 1) |
| 532 |
errorMessage("generateVEPolynom(): \"x\" has size more than 1"); |
| 533 |
if (coefs.size() < 1) |
| 534 |
errorMessage("generateVEPolynom(): size of \"coefs\" less than 1"); |
| 535 |
auto type(getElementType(x)); |
| 536 |
VectorOfElements p(x.size()); |
| 537 |
copy(subVE(coefs, 0), p); |
| 538 |
for (unsigned int i(1); i < coefs.size(); ++i) |
| 539 |
copy(mad(p, x, subVE(coefs, i), type), p); |
| 540 |
// p[0] = p[0] * x[0] + coefs[i]; |
| 541 |
return p; |
| 542 |
} |
| 543 |
|
| 544 |
template <typename T> MatrixOfElements generateMEUnit(unsigned int n) |
| 545 |
{ |
| 546 |
MatrixOfElements m(n,n); |
| 547 |
Element c0(new Constant<T>(0)); |
| 548 |
Element c1(new Constant<T>(1)); |
| 549 |
|
| 550 |
for(unsigned int i(0); i<n; ++i) |
| 551 |
for(unsigned int j(0); j<n; ++j) |
| 552 |
m.setElement(i,j,c0); |
| 553 |
for(unsigned int i(0); i<n; ++i) |
| 554 |
m.setElement(i,i,c1); |
| 555 |
return m; |
| 556 |
} |
| 557 |
|
| 558 |
#define BOOST_TT_rep_expression(r, data, t) \ |
| 559 |
template MatrixOfElements generateMEUnit<t>(unsigned int n); |
| 560 |
BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types) |
| 561 |
#undef BOOST_TT_rep_expression |
| 562 |
|
| 563 |
MatrixOfElements generateMEDiagonal(const VectorOfElements & d) |
| 564 |
{ |
| 565 |
unsigned int n(d.size()); |
| 566 |
MatrixOfElements m(n,n); |
| 567 |
|
| 568 |
Element c0(new Constant<int>(0)); |
| 569 |
|
| 570 |
for(unsigned int i(0); i<n; ++i) |
| 571 |
for(unsigned int j(0); j<n; ++j) |
| 572 |
m.setElement(i,j,c0); |
| 573 |
for(unsigned int i(0); i<n; ++i) |
| 574 |
m.setElement(i,i,d[i]); |
| 575 |
|
| 576 |
return m; |
| 577 |
} |
| 578 |
|
| 579 |
/* template <typename T> VectorOfElements indexDependedConstant(vector<unsigned int> r, vector<T> values) |
| 580 |
{ |
| 581 |
Index in; |
| 582 |
|
| 583 |
Element e(select()) |
| 584 |
return |
| 585 |
}*/ |
| 586 |
|
| 587 |
|
| 588 |
VectorOfElements generateVEIndex(unsigned int size) |
| 589 |
{ |
| 590 |
VectorOfElements v(1); |
| 591 |
Element ind(new Index(size)); |
| 592 |
v[0] = ind; |
| 593 |
return v; |
| 594 |
} |
| 595 |
|
| 596 |
VectorOfElements generateVEGroupID() |
| 597 |
{ |
| 598 |
VectorOfElements v(1); |
| 599 |
v[0].reset(new GroupID()); |
| 600 |
return v; |
| 601 |
} |
| 602 |
|
| 603 |
VectorOfElements generateVEIndexExt(unsigned int size) |
| 604 |
{ |
| 605 |
VectorOfElements v(1); |
| 606 |
Element ind(new IndexExt(size)); |
| 607 |
v[0] = ind; |
| 608 |
return v; |
| 609 |
} |
| 610 |
|
| 611 |
} // acl |