annotate armadillo-2.4.4/include/armadillo_bits/Proxy.hpp @ 18:8d046a9d36aa slimline

Back out rev 13:ac07c60aa798. Like an idiot, I committed a whole pile of unrelated changes in the guise of a single typo fix. Will re-commit in stages
author Chris Cannam
date Thu, 10 May 2012 10:45:44 +0100
parents 8b6102e2a9b0
children
rev   line source
max@0 1 // Copyright (C) 2010-2012 NICTA (www.nicta.com.au)
max@0 2 // Copyright (C) 2010-2012 Conrad Sanderson
max@0 3 //
max@0 4 // This file is part of the Armadillo C++ library.
max@0 5 // It is provided without any warranty of fitness
max@0 6 // for any purpose. You can redistribute this file
max@0 7 // and/or modify it under the terms of the GNU
max@0 8 // Lesser General Public License (LGPL) as published
max@0 9 // by the Free Software Foundation, either version 3
max@0 10 // of the License or (at your option) any later version.
max@0 11 // (see http://www.opensource.org/licenses for more info)
max@0 12
max@0 13
max@0 14 //! \addtogroup Proxy
max@0 15 //! @{
max@0 16
max@0 17
max@0 18
max@0 19 template<typename T1>
max@0 20 class Proxy
max@0 21 {
max@0 22 public:
max@0 23 inline Proxy(const T1& A)
max@0 24 {
max@0 25 arma_type_check(( is_arma_type<T1>::value == false ));
max@0 26 }
max@0 27 };
max@0 28
max@0 29
max@0 30
max@0 31 // ea_type is the "element accessor" type,
max@0 32 // which can provide access to elements via operator[]
max@0 33
max@0 34 template<typename eT>
max@0 35 class Proxy< Mat<eT> >
max@0 36 {
max@0 37 public:
max@0 38
max@0 39 typedef eT elem_type;
max@0 40 typedef typename get_pod_type<elem_type>::result pod_type;
max@0 41 typedef Mat<eT> stored_type;
max@0 42 typedef const eT* ea_type;
max@0 43
max@0 44 static const bool prefer_at_accessor = false;
max@0 45 static const bool has_subview = false;
max@0 46
max@0 47 arma_aligned const Mat<eT>& Q;
max@0 48
max@0 49 inline explicit Proxy(const Mat<eT>& A)
max@0 50 : Q(A)
max@0 51 {
max@0 52 arma_extra_debug_sigprint();
max@0 53 }
max@0 54
max@0 55 arma_inline uword get_n_rows() const { return Q.n_rows; }
max@0 56 arma_inline uword get_n_cols() const { return Q.n_cols; }
max@0 57 arma_inline uword get_n_elem() const { return Q.n_elem; }
max@0 58
max@0 59 arma_inline elem_type operator[] (const uword i) const { return Q[i]; }
max@0 60 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
max@0 61
max@0 62 arma_inline ea_type get_ea() const { return Q.memptr(); }
max@0 63
max@0 64 template<typename eT2>
max@0 65 arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&Q) == void_ptr(&X)); }
max@0 66 };
max@0 67
max@0 68
max@0 69
max@0 70 template<typename eT>
max@0 71 class Proxy< Col<eT> >
max@0 72 {
max@0 73 public:
max@0 74
max@0 75 typedef eT elem_type;
max@0 76 typedef typename get_pod_type<elem_type>::result pod_type;
max@0 77 typedef Col<eT> stored_type;
max@0 78 typedef const eT* ea_type;
max@0 79
max@0 80 static const bool prefer_at_accessor = false;
max@0 81 static const bool has_subview = false;
max@0 82
max@0 83 arma_aligned const Col<eT>& Q;
max@0 84
max@0 85 inline explicit Proxy(const Col<eT>& A)
max@0 86 : Q(A)
max@0 87 {
max@0 88 arma_extra_debug_sigprint();
max@0 89 }
max@0 90
max@0 91 arma_inline uword get_n_rows() const { return Q.n_rows; }
max@0 92 arma_inline uword get_n_cols() const { return 1; }
max@0 93 arma_inline uword get_n_elem() const { return Q.n_elem; }
max@0 94
max@0 95 arma_inline elem_type operator[] (const uword i) const { return Q[i]; }
max@0 96 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
max@0 97
max@0 98 arma_inline ea_type get_ea() const { return Q.memptr(); }
max@0 99
max@0 100 template<typename eT2>
max@0 101 arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&Q) == void_ptr(&X)); }
max@0 102 };
max@0 103
max@0 104
max@0 105
max@0 106 template<typename eT>
max@0 107 class Proxy< Row<eT> >
max@0 108 {
max@0 109 public:
max@0 110
max@0 111 typedef eT elem_type;
max@0 112 typedef typename get_pod_type<elem_type>::result pod_type;
max@0 113 typedef Row<eT> stored_type;
max@0 114 typedef const eT* ea_type;
max@0 115
max@0 116 static const bool prefer_at_accessor = false;
max@0 117 static const bool has_subview = false;
max@0 118
max@0 119 arma_aligned const Row<eT>& Q;
max@0 120
max@0 121 inline explicit Proxy(const Row<eT>& A)
max@0 122 : Q(A)
max@0 123 {
max@0 124 arma_extra_debug_sigprint();
max@0 125 }
max@0 126
max@0 127 arma_inline uword get_n_rows() const { return 1; }
max@0 128 arma_inline uword get_n_cols() const { return Q.n_cols; }
max@0 129 arma_inline uword get_n_elem() const { return Q.n_elem; }
max@0 130
max@0 131 arma_inline elem_type operator[] (const uword i) const { return Q[i]; }
max@0 132 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
max@0 133
max@0 134 arma_inline ea_type get_ea() const { return Q.memptr(); }
max@0 135
max@0 136 template<typename eT2>
max@0 137 arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&Q) == void_ptr(&X)); }
max@0 138 };
max@0 139
max@0 140
max@0 141
max@0 142 template<typename eT, typename gen_type>
max@0 143 class Proxy< Gen<eT, gen_type > >
max@0 144 {
max@0 145 public:
max@0 146
max@0 147 typedef eT elem_type;
max@0 148 typedef typename get_pod_type<elem_type>::result pod_type;
max@0 149 typedef Gen<eT, gen_type> stored_type;
max@0 150 typedef const Gen<eT, gen_type>& ea_type;
max@0 151
max@0 152 static const bool prefer_at_accessor = Gen<eT, gen_type>::prefer_at_accessor;
max@0 153 static const bool has_subview = false;
max@0 154
max@0 155 arma_aligned const Gen<eT, gen_type>& Q;
max@0 156
max@0 157 inline explicit Proxy(const Gen<eT, gen_type>& A)
max@0 158 : Q(A)
max@0 159 {
max@0 160 arma_extra_debug_sigprint();
max@0 161 }
max@0 162
max@0 163 arma_inline uword get_n_rows() const { return Q.n_rows; }
max@0 164 arma_inline uword get_n_cols() const { return Q.n_cols; }
max@0 165 arma_inline uword get_n_elem() const { return Q.n_rows*Q.n_cols; }
max@0 166
max@0 167 arma_inline elem_type operator[] (const uword i) const { return Q[i]; }
max@0 168 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
max@0 169
max@0 170 arma_inline ea_type get_ea() const { return Q; }
max@0 171
max@0 172 template<typename eT2>
max@0 173 arma_inline bool is_alias(const Mat<eT2>&) const { return false; }
max@0 174 };
max@0 175
max@0 176
max@0 177
max@0 178 template<typename T1, typename op_type>
max@0 179 class Proxy< Op<T1, op_type> >
max@0 180 {
max@0 181 public:
max@0 182
max@0 183 typedef typename T1::elem_type elem_type;
max@0 184 typedef typename get_pod_type<elem_type>::result pod_type;
max@0 185 typedef Mat<elem_type> stored_type;
max@0 186 typedef const elem_type* ea_type;
max@0 187
max@0 188 static const bool prefer_at_accessor = false;
max@0 189 static const bool has_subview = false;
max@0 190
max@0 191 arma_aligned const Mat<elem_type> Q;
max@0 192
max@0 193 inline explicit Proxy(const Op<T1, op_type>& A)
max@0 194 : Q(A)
max@0 195 {
max@0 196 arma_extra_debug_sigprint();
max@0 197 }
max@0 198
max@0 199 arma_inline uword get_n_rows() const { return Q.n_rows; }
max@0 200 arma_inline uword get_n_cols() const { return Q.n_cols; }
max@0 201 arma_inline uword get_n_elem() const { return Q.n_elem; }
max@0 202
max@0 203 arma_inline elem_type operator[] (const uword i) const { return Q[i]; }
max@0 204 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
max@0 205
max@0 206 arma_inline ea_type get_ea() const { return Q.memptr(); }
max@0 207
max@0 208 template<typename eT2>
max@0 209 arma_inline bool is_alias(const Mat<eT2>&) const { return false; }
max@0 210 };
max@0 211
max@0 212
max@0 213
max@0 214 template<typename T1, typename T2, typename glue_type>
max@0 215 class Proxy< Glue<T1, T2, glue_type> >
max@0 216 {
max@0 217 public:
max@0 218
max@0 219 typedef typename T1::elem_type elem_type;
max@0 220 typedef typename get_pod_type<elem_type>::result pod_type;
max@0 221 typedef Mat<elem_type> stored_type;
max@0 222 typedef const elem_type* ea_type;
max@0 223
max@0 224 static const bool prefer_at_accessor = false;
max@0 225 static const bool has_subview = false;
max@0 226
max@0 227 arma_aligned const Mat<elem_type> Q;
max@0 228
max@0 229 inline explicit Proxy(const Glue<T1, T2, glue_type>& A)
max@0 230 : Q(A)
max@0 231 {
max@0 232 arma_extra_debug_sigprint();
max@0 233 }
max@0 234
max@0 235 arma_inline uword get_n_rows() const { return Q.n_rows; }
max@0 236 arma_inline uword get_n_cols() const { return Q.n_cols; }
max@0 237 arma_inline uword get_n_elem() const { return Q.n_elem; }
max@0 238
max@0 239 arma_inline elem_type operator[] (const uword i) const { return Q[i]; }
max@0 240 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
max@0 241
max@0 242 arma_inline ea_type get_ea() const { return Q.memptr(); }
max@0 243
max@0 244 template<typename eT2>
max@0 245 arma_inline bool is_alias(const Mat<eT2>&) const { return false; }
max@0 246 };
max@0 247
max@0 248
max@0 249
max@0 250 template<typename eT>
max@0 251 class Proxy< subview<eT> >
max@0 252 {
max@0 253 public:
max@0 254
max@0 255 typedef eT elem_type;
max@0 256 typedef typename get_pod_type<elem_type>::result pod_type;
max@0 257 typedef subview<eT> stored_type;
max@0 258 typedef const subview<eT>& ea_type;
max@0 259
max@0 260 static const bool prefer_at_accessor = true;
max@0 261 static const bool has_subview = true;
max@0 262
max@0 263 arma_aligned const subview<eT>& Q;
max@0 264
max@0 265 inline explicit Proxy(const subview<eT>& A)
max@0 266 : Q(A)
max@0 267 {
max@0 268 arma_extra_debug_sigprint();
max@0 269 }
max@0 270
max@0 271 arma_inline uword get_n_rows() const { return Q.n_rows; }
max@0 272 arma_inline uword get_n_cols() const { return Q.n_cols; }
max@0 273 arma_inline uword get_n_elem() const { return Q.n_elem; }
max@0 274
max@0 275 arma_inline elem_type operator[] (const uword i) const { return Q[i]; }
max@0 276 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
max@0 277
max@0 278 arma_inline ea_type get_ea() const { return Q; }
max@0 279
max@0 280 template<typename eT2>
max@0 281 arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&(Q.m)) == void_ptr(&X)); }
max@0 282 };
max@0 283
max@0 284
max@0 285
max@0 286 template<typename eT, typename T1>
max@0 287 class Proxy< subview_elem1<eT,T1> >
max@0 288 {
max@0 289 public:
max@0 290
max@0 291 typedef eT elem_type;
max@0 292 typedef typename get_pod_type<elem_type>::result pod_type;
max@0 293 typedef Mat<eT> stored_type;
max@0 294 typedef const eT* ea_type;
max@0 295
max@0 296 static const bool prefer_at_accessor = false;
max@0 297 static const bool has_subview = false;
max@0 298
max@0 299 arma_aligned const Mat<eT> Q;
max@0 300
max@0 301 inline explicit Proxy(const subview_elem1<eT,T1>& A)
max@0 302 : Q(A)
max@0 303 {
max@0 304 arma_extra_debug_sigprint();
max@0 305 }
max@0 306
max@0 307 arma_inline uword get_n_rows() const { return Q.n_rows; }
max@0 308 arma_inline uword get_n_cols() const { return 1; }
max@0 309 arma_inline uword get_n_elem() const { return Q.n_elem; }
max@0 310
max@0 311 arma_inline elem_type operator[] (const uword i) const { return Q[i]; }
max@0 312 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
max@0 313
max@0 314 arma_inline ea_type get_ea() const { return Q.memptr(); }
max@0 315
max@0 316 template<typename eT2>
max@0 317 arma_inline bool is_alias(const Mat<eT2>&) const { return false; }
max@0 318 };
max@0 319
max@0 320
max@0 321
max@0 322 template<typename eT>
max@0 323 class Proxy< diagview<eT> >
max@0 324 {
max@0 325 public:
max@0 326
max@0 327 typedef eT elem_type;
max@0 328 typedef typename get_pod_type<elem_type>::result pod_type;
max@0 329 typedef diagview<eT> stored_type;
max@0 330 typedef const diagview<eT>& ea_type;
max@0 331
max@0 332 static const bool prefer_at_accessor = false;
max@0 333 static const bool has_subview = true;
max@0 334
max@0 335 arma_aligned const diagview<eT>& Q;
max@0 336
max@0 337 inline explicit Proxy(const diagview<eT>& A)
max@0 338 : Q(A)
max@0 339 {
max@0 340 arma_extra_debug_sigprint();
max@0 341 }
max@0 342
max@0 343 arma_inline uword get_n_rows() const { return Q.n_rows; }
max@0 344 arma_inline uword get_n_cols() const { return 1; }
max@0 345 arma_inline uword get_n_elem() const { return Q.n_elem; }
max@0 346
max@0 347 arma_inline elem_type operator[] (const uword i) const { return Q[i]; }
max@0 348 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
max@0 349
max@0 350 arma_inline ea_type get_ea() const { return Q; }
max@0 351
max@0 352 template<typename eT2>
max@0 353 arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&(Q.m)) == void_ptr(&X)); }
max@0 354 };
max@0 355
max@0 356
max@0 357
max@0 358
max@0 359 template<typename T1, typename eop_type>
max@0 360 class Proxy< eOp<T1, eop_type > >
max@0 361 {
max@0 362 public:
max@0 363
max@0 364 typedef typename T1::elem_type elem_type;
max@0 365 typedef typename get_pod_type<elem_type>::result pod_type;
max@0 366 typedef eOp<T1, eop_type> stored_type;
max@0 367 typedef const eOp<T1, eop_type>& ea_type;
max@0 368
max@0 369 static const bool prefer_at_accessor = eOp<T1, eop_type>::prefer_at_accessor;
max@0 370 static const bool has_subview = eOp<T1, eop_type>::has_subview;
max@0 371
max@0 372 arma_aligned const eOp<T1, eop_type>& Q;
max@0 373
max@0 374 inline explicit Proxy(const eOp<T1, eop_type>& A)
max@0 375 : Q(A)
max@0 376 {
max@0 377 arma_extra_debug_sigprint();
max@0 378 }
max@0 379
max@0 380 arma_inline uword get_n_rows() const { return Q.get_n_rows(); }
max@0 381 arma_inline uword get_n_cols() const { return Q.get_n_cols(); }
max@0 382 arma_inline uword get_n_elem() const { return Q.get_n_elem(); }
max@0 383
max@0 384 arma_inline elem_type operator[] (const uword i) const { return Q[i]; }
max@0 385 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
max@0 386
max@0 387 arma_inline ea_type get_ea() const { return Q; }
max@0 388
max@0 389 template<typename eT2>
max@0 390 arma_inline bool is_alias(const Mat<eT2>& X) const { return Q.P.is_alias(X); }
max@0 391 };
max@0 392
max@0 393
max@0 394
max@0 395 template<typename T1, typename T2, typename eglue_type>
max@0 396 class Proxy< eGlue<T1, T2, eglue_type > >
max@0 397 {
max@0 398 public:
max@0 399
max@0 400 typedef typename T1::elem_type elem_type;
max@0 401 typedef typename get_pod_type<elem_type>::result pod_type;
max@0 402 typedef eGlue<T1, T2, eglue_type> stored_type;
max@0 403 typedef const eGlue<T1, T2, eglue_type>& ea_type;
max@0 404
max@0 405 static const bool prefer_at_accessor = eGlue<T1, T2, eglue_type>::prefer_at_accessor;
max@0 406 static const bool has_subview = eGlue<T1, T2, eglue_type>::has_subview;
max@0 407
max@0 408 arma_aligned const eGlue<T1, T2, eglue_type>& Q;
max@0 409
max@0 410 inline explicit Proxy(const eGlue<T1, T2, eglue_type>& A)
max@0 411 : Q(A)
max@0 412 {
max@0 413 arma_extra_debug_sigprint();
max@0 414 }
max@0 415
max@0 416 arma_inline uword get_n_rows() const { return Q.get_n_rows(); }
max@0 417 arma_inline uword get_n_cols() const { return Q.get_n_cols(); }
max@0 418 arma_inline uword get_n_elem() const { return Q.get_n_elem(); }
max@0 419
max@0 420 arma_inline elem_type operator[] (const uword i) const { return Q[i]; }
max@0 421 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); }
max@0 422
max@0 423 arma_inline ea_type get_ea() const { return Q; }
max@0 424
max@0 425 template<typename eT2>
max@0 426 arma_inline bool is_alias(const Mat<eT2>& X) const { return (Q.P1.is_alias(X) || Q.P2.is_alias(X)); }
max@0 427 };
max@0 428
max@0 429
max@0 430
max@0 431 template<typename out_eT, typename T1, typename op_type>
max@0 432 class Proxy< mtOp<out_eT, T1, op_type> >
max@0 433 {
max@0 434 public:
max@0 435
max@0 436 typedef out_eT elem_type;
max@0 437 typedef typename get_pod_type<out_eT>::result pod_type;
max@0 438 typedef Mat<out_eT> stored_type;
max@0 439 typedef const elem_type* ea_type;
max@0 440
max@0 441 static const bool prefer_at_accessor = false;
max@0 442 static const bool has_subview = false;
max@0 443
max@0 444 arma_aligned const Mat<out_eT> Q;
max@0 445
max@0 446 inline explicit Proxy(const mtOp<out_eT, T1, op_type>& A)
max@0 447 : Q(A)
max@0 448 {
max@0 449 arma_extra_debug_sigprint();
max@0 450 }
max@0 451
max@0 452 arma_inline uword get_n_rows() const { return Q.n_rows; }
max@0 453 arma_inline uword get_n_cols() const { return Q.n_cols; }
max@0 454 arma_inline uword get_n_elem() const { return Q.n_elem; }
max@0 455
max@0 456 arma_inline elem_type operator[] (const uword i) const { return Q[i]; }
max@0 457 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row,col); }
max@0 458
max@0 459 arma_inline ea_type get_ea() const { return Q.memptr(); }
max@0 460
max@0 461 template<typename eT2>
max@0 462 arma_inline bool is_alias(const Mat<eT2>&) const { return false; }
max@0 463 };
max@0 464
max@0 465
max@0 466
max@0 467 template<typename out_eT, typename T1, typename T2, typename glue_type>
max@0 468 class Proxy< mtGlue<out_eT, T1, T2, glue_type > >
max@0 469 {
max@0 470 public:
max@0 471
max@0 472 typedef out_eT elem_type;
max@0 473 typedef typename get_pod_type<out_eT>::result pod_type;
max@0 474 typedef Mat<out_eT> stored_type;
max@0 475 typedef const elem_type* ea_type;
max@0 476
max@0 477 static const bool prefer_at_accessor = false;
max@0 478 static const bool has_subview = false;
max@0 479
max@0 480 arma_aligned const Mat<out_eT> Q;
max@0 481
max@0 482 inline explicit Proxy(const mtGlue<out_eT, T1, T2, glue_type>& A)
max@0 483 : Q(A)
max@0 484 {
max@0 485 arma_extra_debug_sigprint();
max@0 486 }
max@0 487
max@0 488 arma_inline uword get_n_rows() const { return Q.n_rows; }
max@0 489 arma_inline uword get_n_cols() const { return Q.n_cols; }
max@0 490 arma_inline uword get_n_elem() const { return Q.n_elem; }
max@0 491
max@0 492 arma_inline elem_type operator[] (const uword i) const { return Q[i]; }
max@0 493 arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row,col); }
max@0 494
max@0 495 arma_inline ea_type get_ea() const { return Q.memptr(); }
max@0 496
max@0 497 template<typename eT2>
max@0 498 arma_inline bool is_alias(const Mat<eT2>&) const { return false; }
max@0 499 };
max@0 500
max@0 501
max@0 502
max@0 503 //! @}