STK++ 0.9.13
STK_AssignSelector.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------*/
2/* Copyright (C) 2004-2016 Serge Iovleff, Université Lille 1, Inria
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this program; if not, write to the
16 Free Software Foundation, Inc.,
17 59 Temple Place,
18 Suite 330,
19 Boston, MA 02111-1307
20 USA
21
22 Contact : S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
23*/
24
25/*
26 * Project: stkpp::Arrays
27 * created on: 16 oct. 2012
28 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
37#ifndef STK_ASSIGNSELECTOR_H
38#define STK_ASSIGNSELECTOR_H
39
40
41namespace STK
42{
43
44
45namespace hidden
46{
47
52template<class Derived, int Structure_>
54
58template<class Derived>
59struct CheckShift<Derived, Arrays::array2D_>
60{
61 // all range are authorized for array2D_
62 static bool isAllowed(Derived const& array, Range const& I, Range const& J) { return true;}
63 // check if resize is necessary
64 static bool resize(Derived const& array, Range const& I, Range const& J)
65 { return (array.rows() != I || array.cols() != J);}
66 // check if shift is necessary
67 static bool shift(Derived const& array, int beginRow, int beginCol)
68 { return (array.beginRows() != beginRow || array.beginCols() != beginCol);}
69 // check if resize is necessary
70 static bool resize(Derived const& array, Range const& I)
71 { return (array.rows() != I || array.cols() != I);}
72 // check if shift is necessary
73 static bool shift(Derived const& array, int begin)
74 { return (array.beginRows() != begin || array.beginCols() != begin);}
75};
79template<class Derived>
80struct CheckShift<Derived, Arrays::upper_triangular_>
81{
82 // all range are authorized for upper_triangular_
83 static bool isAllowed(Derived const& array, Range const& I, Range const& J)
84 { return true;}
85 static bool resize(Derived const& array, Range const& I, Range const& J)
86 { return (array.rows() != I || array.cols() != J);}
87 static bool shift(Derived const& array, int beginRow, int beginCol)
88 { return (array.beginRows() != beginRow || array.beginCols() != beginCol);}
89 static bool resize(Derived const& array, Range const& I)
90 { return (array.rows() != I || array.cols() != I);}
91 static bool shift(Derived const& array, int begin)
92 { return (array.beginRows() != begin || array.beginCols() != begin);}
93};
97template<class Derived>
98struct CheckShift<Derived, Arrays::lower_triangular_>
99{
100 // all range are authorized for lower_triangular_
101 static bool isAllowed(Derived const& array, Range const& I, Range const& J)
102 { return true;}
103 static bool resize(Derived const& array, Range const& I, Range const& J)
104 { return (array.rows() != I || array.cols() != J);}
105 static bool shift(Derived const& array, int beginRow, int beginCol)
106 { return (array.beginRows() != beginRow || array.beginCols() != beginCol);}
107 static bool resize(Derived const& array, Range const& I)
108 { return (array.rows() != I || array.cols() != I);}
109 static bool shift(Derived const& array, int begin)
110 { return (array.beginRows() != begin || array.beginCols() != begin);}
111};
115template<class Derived>
116struct CheckShift<Derived, Arrays::square_>
117{
118 // same range only for square_ arrays
119 static bool isAllowed(Derived const& array, Range const& I, Range const& J)
120 { return I==J;}
121 static bool resize(Derived const& array, Range const& I, Range const& J)
122 { return (array.rows() != I || array.cols() != J);}
123 static bool shift(Derived const& array, int beginRow, int beginCol)
124 { return (array.beginRows() != beginRow || array.beginCols() != beginCol);}
125 static bool resize(Derived const& array, Range const& I)
126 { return (array.range() != I);}
127 static bool shift(Derived const& array, int begin)
128 { return (array.beginRows() != begin || array.beginCols() != begin);}
129};
130
134template<class Derived>
135struct CheckShift<Derived, Arrays::diagonal_>
136{
137 // same range only for diagonal_ arrays
138 static bool isAllowed(Derived const& array, Range const& I, Range const& J)
139 { return I==J;}
140 static bool resize(Derived const& array, Range const& I, Range const& J)
141 { return (array.rows() != I || array.cols() != J);}
142 static bool shift(Derived const& array, int beginRow, int beginCol)
143 { return (array.beginRows() != beginRow || array.beginCols() != beginCol);}
144 static bool resize(Derived const& array, Range const& I)
145 { return (array.range() != I);}
146 static bool shift(Derived const& array, int begin)
147 { return (array.beginRows() != begin || array.beginCols() != begin);}
148};
149
150// for vectors
151template<class Derived>
152struct CheckShift<Derived, Arrays::vector_>
153{
154 // same range only for vector_ arrays
155 static bool isAllowed(Derived const& array, Range const& I, Range const& J)
156 { return J.size() == 1;}
157 static bool resize(Derived const& array, Range const& I)
158 { return (array.range() != I);}
159 static bool shift(Derived const& array, int begin)
160 { return (array.begin() != begin);}
161};
162
163// for point
164template<class Derived>
165struct CheckShift<Derived, Arrays::point_>
166{
167 // same range only for diagonal_ arrays
168 static bool isAllowed(Derived const& array, Range const& I, Range const& J)
169 { return (I.size() == 1);}
170 static bool resize(Derived const& array, Range const& I)
171 { return (array.range() != I);}
172 static bool shift(Derived const& array, int begin)
173 { return (array.begin() != begin);}
174};
175// for point
176template<class Derived>
177struct CheckShift<Derived, Arrays::number_>
178{
179 // same range only for diagonal_ arrays
180 static bool isAllowed(Derived const& array, Range const& I, Range const& J)
181 { return (I.size() == 1 && J.size() == 1);}
182 static bool resize(Derived const& array, Range const& I)
183 { return (array.range() == I) ? false : true;}
184 static bool shift(Derived const& array, int begin)
185 { return (array.begin() != begin);}
186};
187
191template< typename Lhs, typename Rhs, int TStructure_>
192struct resizeSelector;
193
195template< typename Lhs, typename Rhs, int TStructure_>
197{
198 inline static void run(Lhs& lhs, ExprBase<Rhs> const& rhs )
199 { lhs.resize(rhs.rows(), rhs.cols());}
200};
202template< typename Lhs, typename Rhs>
203struct resizeSelector<Lhs, Rhs, Arrays::square_>
204{
205 inline static void run(Lhs& lhs, ExprBase<Rhs> const& rhs )
206 { lhs.resize(rhs.range());}
207};
209template< typename Lhs, typename Rhs>
210struct resizeSelector<Lhs, Rhs, Arrays::diagonal_>
211{
212 inline static void run(Lhs& lhs, ExprBase<Rhs> const& rhs )
213 { lhs.resize(rhs.range());}
214};
216template< typename Lhs, typename Rhs>
217struct resizeSelector<Lhs, Rhs, Arrays::vector_>
218{
219 inline static void run(Lhs& lhs, ExprBase<Rhs> const& rhs )
220 { lhs.resize(rhs.range());}
221};
223template< typename Lhs, typename Rhs>
224struct resizeSelector<Lhs, Rhs, Arrays::point_>
225{
226 inline static void run(Lhs& lhs, ExprBase<Rhs> const& rhs )
227 { lhs.resize(rhs.range());}
228};
229
231template< typename Lhs, typename Rhs>
232struct resizeSelector<Lhs, Rhs, Arrays::number_>
233{
234 inline static void run(Lhs& lhs, ExprBase<Rhs> const& rhs )
235 { /* nothing to do */;}
236};
237
238
244template < typename Derived, typename Rhs, int TStructure_, int RhsStructure_>
245struct Copycat;
246
247//---------------------GENERAL----------------------------------
248// general <- general
249template < typename Lhs, typename Rhs>
250struct Copycat< Lhs, Rhs, Arrays::array2D_, Arrays::array2D_>
251{
252 static void runByCol(Lhs& lhs, Rhs const& rhs )
253 {
254 for (int j = rhs.beginCols(); j < rhs.endCols(); ++j)
255 for (int i = rhs.beginRows(); i < rhs.endRows(); ++i)
256 { lhs.setValue(i, j, rhs.elt(i, j));}
257 }
258 static void runByRow(Lhs& lhs, Rhs const& rhs )
259 {
260 for (int i = rhs.beginRows(); i < rhs.endRows(); ++i)
261 for (int j = rhs.beginCols(); j < rhs.endCols(); ++j)
262 { lhs.setValue(i, j, rhs.elt(i, j));}
263 }
264};
265
266// general <- square
267template < typename Lhs, typename Rhs>
268struct Copycat< Lhs, Rhs, Arrays::array2D_, Arrays::square_>
269{
270 static void runByCol(Lhs& lhs, Rhs const& rhs )
271 {
272 for (int i = rhs.begin(); i< rhs.end(); ++i)
273 for (int j = rhs.begin(); j < rhs.end(); ++j)
274 { lhs.setValue(i, j, rhs.elt(i, j));}
275 }
276 static void runByRow(Lhs& lhs, Rhs const& rhs )
277 {
278 for (int j = rhs.begin(); j < rhs.lend(); ++j)
279 for (int i = rhs.begin(); i< rhs.end(); ++i)
280 { lhs.setValue(i, j, rhs.elt(i, j));}
281 }
282};
283
284// general <- diagonal
285template < typename Lhs, typename Rhs>
286struct Copycat< Lhs, Rhs, Arrays::array2D_, Arrays::diagonal_>
287{
289 static void runByCol(Lhs& lhs, Rhs const& rhs )
290 {
291 lhs.setValue(Type(0));
292 for (int i = rhs.begin(); i< rhs.end(); ++i)
293 { lhs.setValue(i, i, rhs.elt(i));}
294 }
295 static void runByRow(Lhs& lhs, Rhs const& rhs )
296 {
297 lhs.setValue(Type(0));
298 for (int i = rhs.begin(); i< rhs.end(); ++i)
299 { lhs.setValue(i, i, rhs.elt(i));}
300 }
301};
302
303// general <- lower_triangular
304template < typename Lhs, typename Rhs>
305struct Copycat< Lhs, Rhs, Arrays::array2D_, Arrays::lower_triangular_>
306{
308 static void runByCol(Lhs& lhs, Rhs const& rhs )
309 {
310 const int end = std::min(rhs.endRows(), rhs.endCols());
311 for (int j = rhs.beginCols(); j < end; ++j)
312 { int i = rhs.beginRows();
313 for (; i < j; ++i) { lhs.setValue(i, j, Type(0));}
314 for (; i < rhs.endRows(); ++i) { lhs.setValue(i, j, rhs.elt(i, j));}
315 }
316 for (int j= end; j < rhs.endCols(); ++j)
317 for (int i = rhs.beginRows(); i < rhs.endRows(); ++i)
318 { lhs.setValue(i, j, Type(0));}
319 }
320 static void runByRow(Lhs& lhs, Rhs const& rhs )
321 {
322 const int end = std::min(rhs.endRows(), rhs.endCols());
323 for (int i = rhs.beginRows(); i < end; ++i)
324 { int j = rhs.beginCols();
325 for (; j <=i; ++j) { lhs.setValue(i, j, rhs.elt(i, j));}
326 for (; j < rhs.endCols(); ++j) { lhs.setValue(i, j, Type(0));}
327 }
328 for (int i= end; i < rhs.endRows(); ++i)
329 for (int j=rhs.beginCols(); j < rhs.endCols(); ++j)
330 { lhs.setValue(i, j, rhs.elt(i, j));}
331 }
332};
333
334// general <- upper_triangular
335template < typename Lhs, typename Rhs>
336struct Copycat< Lhs, Rhs, Arrays::array2D_, Arrays::upper_triangular_>
337{
339 static void runByCol(Lhs& lhs, Rhs const& rhs )
340 {
341 const int end = std::min(rhs.endRows(), rhs.endCols());
342 for (int j = rhs.beginCols(); j < end; ++j)
343 { int i = rhs.beginRows();
344 for (; i <= j; ++i) { lhs.setValue(i, j, rhs.elt(i, j));}
345 for (; i < rhs.endRows(); ++i) { lhs.setValue(i, j, Type(0));}
346 }
347 for (int j= end; j < rhs.endCols(); ++j)
348 for (int i = rhs.beginRows(); i < rhs.endRows(); ++i)
349 { lhs.setValue(i, j, rhs.elt(i, j));}
350 }
351 static void runByRow(Lhs& lhs, Rhs const& rhs )
352 {
353 const int end = std::min(lhs.endRows(), lhs.endCols());
354 for (int i = rhs.beginRows(); i < end; ++i)
355 { int j = rhs.beginCols();
356 for (; j <i; ++j) { lhs.setValue(i, j, Type(0));}
357 for (; j < rhs.endCols(); ++j) { lhs.setValue(i, j, rhs.elt(i, j));}
358 }
359 for (int i= end; i < rhs.endRows(); ++i)
360 for (int j=rhs.beginCols(); j < rhs.endCols(); ++j)
361 { lhs.setValue(i, j, Type(0));}
362 }
363};
364
365// general <- symmetric
366template < typename Lhs, typename Rhs>
367struct Copycat< Lhs, Rhs, Arrays::array2D_, Arrays::symmetric_>
368{
369 static void runByCol(Lhs& lhs, Rhs const& rhs )
370 {
371 for (int j = rhs.beginCols(); j < rhs.endCols(); ++j)
372 for (int i = rhs.beginRows(); i < rhs.endRows(); ++i)
373 { lhs.setValue(i, j, rhs.elt(i, j));}
374 }
375 static void runByRow(Lhs& lhs, Rhs const& rhs )
376 {
377 for (int i = rhs.beginRows(); i < rhs.endRows(); ++i)
378 for (int j = rhs.beginCols(); j < rhs.endCols(); ++j)
379 { lhs.setValue(i, j, rhs.elt(i, j));}
380 }
381};
382
383// general <- upper_symmetric
384template < typename Lhs, typename Rhs>
385struct Copycat< Lhs, Rhs, Arrays::array2D_, Arrays::upper_symmetric_>
386{
387 static void runByCol(Lhs& lhs, Rhs const& rhs )
388 {
389 for (int j = rhs.beginCols(); j < rhs.endCols(); ++j)
390 for (int i = rhs.beginRows(); i <=j; ++i)
391 { lhs.elt(i, j) = ( lhs.elt(j, i) = rhs.elt(i, j) );}
392 }
393 static void runByRow(Lhs& lhs, Rhs const& rhs )
394 {
395 for (int i = rhs.beginRows(); i < rhs.endRows(); ++i)
396 for (int j = i; j < rhs.endCols(); ++j)
397 { lhs.elt(i, j) = (lhs.elt(j, i) = rhs.elt(i, j));}
398 }
399};
400
401// general <- lower_symmetric
402template < typename Lhs, typename Rhs>
403struct Copycat< Lhs, Rhs, Arrays::array2D_, Arrays::lower_symmetric_>
404{
405 static void runByCol(Lhs& lhs, Rhs const& rhs )
406 {
407 for (int j = rhs.beginCols(); j < rhs.endCols(); ++j)
408 for (int i = j; i < rhs.endRows(); ++i)
409 { lhs.elt(i, j) = ( lhs.elt(j, i) = rhs.elt(i, j) );}
410 }
411 static void runByRow(Lhs& lhs, Rhs const& rhs )
412 {
413 for (int i = rhs.beginRows(); i < rhs.endRows(); ++i)
414 for (int j = rhs.beginCols(); j <= i; ++j)
415 { lhs.elt(i, j) = (lhs.elt(j, i) = rhs.elt(i, j));}
416 }
417};
418
419
420// general <- vector
421template < typename Lhs, typename Rhs>
422struct Copycat< Lhs, Rhs, Arrays::array2D_, Arrays::vector_>
423{
424 static void runByCol(Lhs& lhs, Rhs const& rhs )
425 {
426 int j = lhs.beginCols();
427 for (int i = rhs.beginRows(); i < rhs.endRows(); ++i)
428 { lhs.setValue(i, j, rhs.elt(i));}
429 }
430 static void runByRow(Lhs& lhs, Rhs const& rhs )
431 {
432 int j = rhs.beginCols();
433 for (int i = rhs.beginRows(); i < rhs.endRows(); ++i)
434 { lhs.setValue(i, j, rhs.elt(i));}
435 }
436};
437
438// general <- point
439template < typename Lhs, typename Rhs>
440struct Copycat< Lhs, Rhs, Arrays::array2D_, Arrays::point_>
441{
442 static void runByCol(Lhs& lhs, Rhs const& rhs )
443 {
444 int i = lhs.beginRows();
445 for (int j = rhs.beginCols(); j < rhs.endCols(); ++j)
446 { lhs.setValue(i, j, rhs.elt(j));}
447 }
448 static void runByRow(Lhs& lhs, Rhs const& rhs )
449 {
450 int i = lhs.beginRows();
451 for (int j = rhs.beginCols(); j < rhs.endCols(); ++j)
452 { lhs.setValue(i, j, rhs.elt(j));}
453 }
454};
455
456
457
458//---------------------SQUARE----------------------------------
459// square <- general
460template < typename Lhs, typename Rhs>
461struct Copycat< Lhs, Rhs, Arrays::square_, Arrays::array2D_>
462{
463 static void runByCol(Lhs& lhs, Rhs const& rhs )
464 {
465 for (int i = rhs.beginRows(); i < rhs.endRows(); ++i)
466 for (int j = rhs.beginCols(); j < rhs.endCols(); ++j)
467 { lhs.setValue(i, j, rhs.elt(i, j));}
468 }
469 static void runByRow(Lhs& lhs, Rhs const& rhs )
470 {
471 for (int j = rhs.beginCols(); j < rhs.endCols(); ++j)
472 for (int i = rhs.beginRows(); i < rhs.endRows(); ++i)
473 { lhs.setValue(i, j, rhs.elt(i, j));}
474 }
475};
476
477// square <- square
478template < typename Lhs, typename Rhs>
479struct Copycat< Lhs, Rhs, Arrays::square_, Arrays::square_>
480{
481 static void runByCol(Lhs& lhs, Rhs const& rhs )
482 {
483 for (int j = rhs.begin(); j < rhs.end(); ++j)
484 for (int i = rhs.begin(); i< rhs.end(); ++i)
485 { lhs.setValue(i, j, rhs.elt(i, j));}
486 }
487 static void runByRow(Lhs& lhs, Rhs const& rhs )
488 {
489 for (int i = rhs.begin(); i< rhs.end(); ++i)
490 for (int j = rhs.begin(); j < rhs.end(); ++j)
491 { lhs.setValue(i, j, rhs.elt(i, j));}
492 }
493};
494
495// square <- diagonal
496template < typename Lhs, typename Rhs>
497struct Copycat< Lhs, Rhs, Arrays::square_, Arrays::diagonal_>
498{
500 static void runByCol(Lhs& lhs, Rhs const& rhs )
501 {
502 lhs.setValue(Type(0));
503 const int end = std::min(lhs.endRows(), lhs.endCols());
504 for (int i = rhs.beginRows(); i < end; ++i)
505 { lhs.setValue(i, i, rhs.elt(i));}
506 }
507 static void runByRow(Lhs& lhs, Rhs const& rhs )
508 {
509 lhs.setValue(Type(0));
510 const int end = std::min(lhs.endRows(), lhs.endCols());
511 for (int i = rhs.beginRows(); i < end; ++i)
512 { lhs.setValue(i, i, rhs.elt(i));}
513 }
514};
515
516// square_ <- lower_triangular
517template < typename Lhs, typename Rhs>
518struct Copycat< Lhs, Rhs, Arrays::square_, Arrays::lower_triangular_>
519{
521 static void runByCol(Lhs& lhs, Rhs const& rhs )
522 {
523 const int end = std::min(rhs.endRows(), rhs.endCols());
524 for (int j = rhs.beginCols(); j < end; ++j)
525 { int i = rhs.beginRows();
526 for (; i < j; ++i) { lhs.setValue(i, j, Type(0));}
527 for (; i < rhs.endRows(); ++i) { lhs.setValue(i, j, rhs.elt(i, j));}
528 }
529 for (int j= end; j < rhs.endCols(); ++j)
530 for (int i = rhs.beginRows(); i < rhs.endRows(); ++i)
531 { lhs.setValue(i, j, Type(0));}
532 }
533 static void runByRow(Lhs& lhs, Rhs const& rhs )
534 {
535 const int end = std::min(rhs.endRows(), rhs.endCols());
536 for (int i = rhs.beginRows(); i < end; ++i)
537 { int j = rhs.beginCols();
538 for (; j <=i; ++j) { lhs.setValue(i, j, rhs.elt(i, j));}
539 for (; j < rhs.endCols(); ++j) { lhs.setValue(i, j, Type(0));}
540 }
541 for (int i= end; i < rhs.endRows(); ++i)
542 for (int j=rhs.beginCols(); j < rhs.endCols(); ++j)
543 { lhs.setValue(i, j, rhs.elt(i, j));}
544 }
545};
546
547// square_ <- upper triangular
548template < typename Lhs, typename Rhs>
549struct Copycat< Lhs, Rhs, Arrays::square_, Arrays::upper_triangular_>
550{
552 static void runByCol(Lhs& lhs, Rhs const& rhs )
553 {
554 const int end = std::min(rhs.endRows(), rhs.endCols());
555 for (int j = rhs.beginCols(); j < end; ++j)
556 { int i = rhs.beginRows();
557 for (; i <= j; ++i) { lhs.setValue(i, j, rhs.elt(i, j));}
558 for (; i < rhs.endRows(); ++i) { lhs.setValue(i, j, Type(0));}
559 }
560 for (int j= end; j < rhs.endCols(); ++j)
561 for (int i = rhs.beginRows(); i < rhs.endRows(); ++i)
562 { lhs.setValue(i, j, rhs.elt(i, j));}
563 }
564 static void runByRow(Lhs& lhs, Rhs const& rhs )
565 {
566 const int end = std::min(lhs.endRows(), lhs.endCols());
567 for (int i = rhs.beginRows(); i < end; ++i)
568 { int j = rhs.beginCols();
569 for (; j <i; ++j) { lhs.setValue(i, j, Type(0));}
570 for (; j < rhs.endCols(); ++j) { lhs.setValue(i, j, rhs.elt(i, j));}
571 }
572 for (int i= end; i < rhs.endRows(); ++i)
573 for (int j=rhs.beginCols(); j < rhs.endCols(); ++j)
574 { lhs.setValue(i, j, Type(0));}
575 }
576};
577
578// general <- symmetric
579template < typename Lhs, typename Rhs>
580struct Copycat< Lhs, Rhs, Arrays::square_, Arrays::symmetric_>
581{
582 static void runByCol(Lhs& lhs, Rhs const& rhs )
583 {
584 for (int j = rhs.beginCols(); j < rhs.endCols(); ++j)
585 for (int i = rhs.beginRows(); i < rhs.endRows(); ++i)
586 { lhs.setValue(i, j, rhs.elt(i, j));}
587 }
588 static void runByRow(Lhs& lhs, Rhs const& rhs )
589 {
590 for (int i = rhs.beginRows(); i < rhs.endRows(); ++i)
591 for (int j = rhs.beginCols(); j < rhs.endCols(); ++j)
592 { lhs.setValue(i, j, rhs.elt(i, j));}
593 }
594};
595
596// general <- upper_symmetric
597template < typename Lhs, typename Rhs>
598struct Copycat< Lhs, Rhs, Arrays::square_, Arrays::upper_symmetric_>
599{
600 static void runByCol(Lhs& lhs, Rhs const& rhs )
601 {
602 for (int j = rhs.beginCols(); j < rhs.endCols(); ++j)
603 for (int i = rhs.beginRows(); i <=j; ++i)
604 { lhs.elt(i, j) = ( lhs.elt(j, i) = rhs.elt(i, j) );}
605 }
606 static void runByRow(Lhs& lhs, Rhs const& rhs )
607 {
608 for (int i = rhs.beginRows(); i < rhs.endRows(); ++i)
609 for (int j = i; j < rhs.endCols(); ++j)
610 { lhs.elt(i, j) = (lhs.elt(j, i) = rhs.elt(i, j));}
611 }
612};
613
614// general <- lower_symmetric
615template < typename Lhs, typename Rhs>
616struct Copycat< Lhs, Rhs, Arrays::square_, Arrays::lower_symmetric_>
617{
618 static void runByCol(Lhs& lhs, Rhs const& rhs )
619 {
620 for (int j = rhs.beginCols(); j < rhs.endCols(); ++j)
621 for (int i = j; i < rhs.endRows(); ++i)
622 { lhs.elt(i, j) = ( lhs.elt(j, i) = rhs.elt(i, j) );}
623 }
624 static void runByRow(Lhs& lhs, Rhs const& rhs )
625 {
626 for (int i = rhs.beginRows(); i < rhs.endRows(); ++i)
627 for (int j = rhs.beginCols(); j <= i; ++j)
628 { lhs.elt(i, j) = (lhs.elt(j, i) = rhs.elt(i, j));}
629 }
630};
631
632
633//---------------------LDO----------------------------------
634// lower_triangular <- lower_triangular
635template < typename Lhs, typename Rhs>
636struct Copycat< Lhs, Rhs, Arrays::lower_triangular_, Arrays::lower_triangular_>
637{
639 static void runByCol(Lhs& lhs, Rhs const& rhs )
640 {
641 const int end = std::min(rhs.endRows(), rhs.endCols());
642 for (int j = rhs.beginCols(); j < end; ++j)
643 for (int i=j; i < rhs.endRows(); ++i)
644 { lhs.setValue(i, j, rhs.elt(i, j));}
645 }
646 static void runByRow(Lhs& lhs, Rhs const& rhs )
647 {
648 const int end = std::min(rhs.endRows(), rhs.endCols());
649 for (int i = rhs.beginRows(); i < end; ++i)
650 for (int j = rhs.beginCols(); j <=i; ++j)
651 { lhs.setValue(i, j, rhs.elt(i, j));}
652 for (int i= end; i < rhs.endRows(); ++i)
653 for (int j=rhs.beginCols(); j < rhs.endCols(); ++j)
654 { lhs.setValue(i, j, rhs.elt(i, j));}
655 }
656};
657
658//---------------------LUP----------------------------------
659// upper_triangular <- upper_triangular
660template < typename Lhs, typename Rhs>
661struct Copycat< Lhs, Rhs, Arrays::upper_triangular_, Arrays::upper_triangular_>
662{
664 static void runByCol(Lhs& lhs, Rhs const& rhs )
665 {
666 const int end = std::min(rhs.endRows(), rhs.endCols());
667 for (int j = rhs.beginCols(); j < end; ++j)
668 for (int i = rhs.beginRows(); i <= j; ++i)
669 { lhs.setValue(i, j, rhs.elt(i, j));}
670 for (int j= end; j < rhs.endCols(); ++j)
671 for (int i = rhs.beginRows(); i < rhs.endRows(); ++i)
672 { lhs.setValue(i, j, rhs.elt(i, j));}
673 }
674 static void runByRow(Lhs& lhs, Rhs const& rhs )
675 {
676 const int last = std::min(lhs.lastIdxRows(), lhs.lastIdxCols());
677 for (int i = rhs.beginRows(); i <= last; ++i)
678 for (int j=i; j < rhs.endCols(); ++j)
679 { lhs.setValue(i, j, rhs.elt(i, j));}
680 }
681};
682
683
684//---------------------DIAGONAL----------------------------------
685// diagonal <- diagonal
686template < typename Lhs, typename Rhs>
687struct Copycat< Lhs, Rhs, Arrays::diagonal_, Arrays::diagonal_>
688{
689 static void runByCol(Lhs& lhs, Rhs const& rhs )
690 { for (int i = rhs.begin(); i< rhs.end(); ++i) { lhs.setValue(i, rhs.elt(i));}}
691 static void runByRow(Lhs& lhs, Rhs const& rhs )
692 { for (int i = rhs.begin(); i< rhs.end(); ++i) { lhs.setValue(i, rhs.elt(i));}}
693};
694
695// diagonal <- vector
696template < typename Lhs, typename Rhs>
697struct Copycat< Lhs, Rhs, Arrays::diagonal_, Arrays::vector_>
698{
699 static void runByCol(Lhs& lhs, Rhs const& rhs )
700 { for (int i = rhs.begin(); i< rhs.end(); ++i) { lhs.setValue(i, rhs.elt(i));}}
701 static void runByRow(Lhs& lhs, Rhs const& rhs )
702 { for (int i = rhs.begin(); i< rhs.end(); ++i) { lhs.setValue(i, rhs.elt(i));}}
703};
704
705// diagonal <- point
706template < typename Lhs, typename Rhs>
707struct Copycat< Lhs, Rhs, Arrays::diagonal_, Arrays::point_>
708{
709 static void runByCol(Lhs& lhs, Rhs const& rhs )
710 { for (int i = rhs.begin(); i< rhs.end(); ++i) { lhs.setValue(i, rhs.elt(i));}}
711 static void runByRow(Lhs& lhs, Rhs const& rhs )
712 { for (int i = rhs.begin(); i< rhs.end(); ++i) { lhs.setValue(i, rhs.elt(i));}}
713};
714
715//---------------------VECTOR----------------------------------
716// vector <- diagonal
717template < typename Lhs, typename Rhs>
718struct Copycat< Lhs, Rhs, Arrays::vector_, Arrays::diagonal_>
719{
720 static void runByCol(Lhs& lhs, Rhs const& rhs )
721 { for (int i = rhs.begin(); i< rhs.end(); ++i) { lhs.setValue(i, rhs.elt(i));}}
722 static void runByRow(Lhs& lhs, Rhs const& rhs )
723 { for (int i = rhs.begin(); i< rhs.end(); ++i) { lhs.setValue(i, rhs.elt(i));}}
724};
725
726// vector <- vector
727template < typename Lhs, typename Rhs>
728struct Copycat< Lhs, Rhs, Arrays::vector_, Arrays::vector_>
729{
730 static void runByCol(Lhs& lhs, Rhs const& rhs )
731 { for (int i = rhs.begin(); i< rhs.end(); ++i) { lhs.setValue(i, rhs.elt(i));}}
732 static void runByRow(Lhs& lhs, Rhs const& rhs )
733 { for (int i = rhs.begin(); i< rhs.end(); ++i) { lhs.setValue(i, rhs.elt(i));}}
734};
735// vector <- point
736template < typename Lhs, typename Rhs>
737struct Copycat< Lhs, Rhs, Arrays::vector_, Arrays::point_>
738{
739 static void runByCol(Lhs& lhs, Rhs const& rhs )
740 { for (int i = rhs.begin(); i< rhs.end(); ++i) { lhs.setValue(i, rhs.elt(i));}}
741 static void runByRow(Lhs& lhs, Rhs const& rhs )
742 { for (int i = rhs.begin(); i< rhs.end(); ++i) { lhs.setValue(i, rhs.elt(i));}}
743};
744
745//---------------------POINT----------------------------------
746// point_ <- diagonal
747template < typename Lhs, typename Rhs>
748struct Copycat< Lhs, Rhs, Arrays::point_, Arrays::diagonal_>
749{
750 static void runByCol(Lhs& lhs, Rhs const& rhs )
751 { for (int i = rhs.begin(); i< rhs.end(); ++i) { lhs.setValue(i, rhs.elt(i));}}
752 static void runByRow(Lhs& lhs, Rhs const& rhs )
753 { for (int i = rhs.begin(); i< rhs.end(); ++i) { lhs.setValue(i, rhs.elt(i));}}
754};
755
756// vector <- vector
757template < typename Lhs, typename Rhs>
758struct Copycat< Lhs, Rhs, Arrays::point_, Arrays::vector_>
759{
760 static void runByCol(Lhs& lhs, Rhs const& rhs )
761 { for (int i = rhs.begin(); i< rhs.end(); ++i) { lhs.setValue(i, rhs.elt(i));}}
762 static void runByRow(Lhs& lhs, Rhs const& rhs )
763 { for (int i = rhs.begin(); i< rhs.end(); ++i) { lhs.setValue(i, rhs.elt(i));}}
764};
765// vector <- point
766template < typename Lhs, typename Rhs>
767struct Copycat< Lhs, Rhs, Arrays::point_, Arrays::point_>
768{
769 static void runByCol(Lhs& lhs, Rhs const& rhs )
770 { for (int i = rhs.begin(); i< rhs.end(); ++i) { lhs.setValue(i, rhs.elt(i));}}
771 static void runByRow(Lhs& lhs, Rhs const& rhs )
772 { for (int i = rhs.begin(); i< rhs.end(); ++i) { lhs.setValue(i, rhs.elt(i));}}
773};
774
775
776//---------------------NUMBER----------------------------------
777// point_ <- diagonal
778template < typename Lhs, typename Rhs>
779struct Copycat< Lhs, Rhs, Arrays::number_, Arrays::number_>
780{
781 inline static void runByCol(Lhs& lhs, Rhs const& rhs )
782 { lhs.setValue(rhs.elt());}
783 inline static void runByRow(Lhs& lhs, Rhs const& rhs )
784 { lhs.setValue(rhs.elt());}
785};
786
790template < typename Lhs, typename Rhs, int TOrient_>
792
794template< typename Lhs, typename Rhs>
795struct CopycatSelector< Lhs, Rhs, Arrays::by_col_>
796{
797 enum
798 { lhs_structure_ = hidden::Traits<Lhs>::structure_
800 };
801 inline static void run(Lhs& lhs, Rhs const& rhs )
803};
804
806template< typename Lhs, typename Rhs>
807struct CopycatSelector< Lhs, Rhs, Arrays::by_row_>
808{
809 enum
810 { lhs_structure_ = hidden::Traits<Lhs>::structure_
812 };
813 inline static void run(Lhs& lhs, Rhs const& rhs )
815};
816
817} // namespace hidden
818
819
820} // namespace STK
821
822#endif /* STK_ASSIGNSELECTOR_H */
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
Index sub-vector region: Specialization when the size is unknown.
Definition STK_Range.h:265
@ array2D_
general matrix/array/expression
@ number_
(1,1) matrix/vector/array/expression (like a number)
@ point_
row oriented vector/array/expression
@ lower_symmetric_
lower symmetric matrix/array/expression
@ lower_triangular_
lower triangular matrix/array/expression
@ symmetric_
symmetric matrix/array/expression
@ upper_triangular_
upper triangular matrix/array/expression
@ diagonal_
diagonal matrix/array/expression
@ upper_symmetric_
upper symmetric matrix/array/expression
@ vector_
column oriented vector/array/expression
@ square_
square matrix/array/expression
The namespace STK is the main domain space of the Statistical ToolKit project.
static bool resize(Derived const &array, Range const &I)
static bool isAllowed(Derived const &array, Range const &I, Range const &J)
static bool shift(Derived const &array, int beginRow, int beginCol)
static bool shift(Derived const &array, int begin)
static bool resize(Derived const &array, Range const &I, Range const &J)
static bool shift(Derived const &array, int beginRow, int beginCol)
static bool resize(Derived const &array, Range const &I, Range const &J)
static bool shift(Derived const &array, int begin)
static bool resize(Derived const &array, Range const &I)
static bool isAllowed(Derived const &array, Range const &I, Range const &J)
static bool resize(Derived const &array, Range const &I)
static bool isAllowed(Derived const &array, Range const &I, Range const &J)
static bool resize(Derived const &array, Range const &I, Range const &J)
static bool shift(Derived const &array, int beginRow, int beginCol)
static bool isAllowed(Derived const &array, Range const &I, Range const &J)
static bool shift(Derived const &array, int begin)
static bool resize(Derived const &array, Range const &I)
static bool shift(Derived const &array, int begin)
static bool resize(Derived const &array, Range const &I)
static bool isAllowed(Derived const &array, Range const &I, Range const &J)
static bool resize(Derived const &array, Range const &I, Range const &J)
static bool resize(Derived const &array, Range const &I)
static bool shift(Derived const &array, int begin)
static bool shift(Derived const &array, int beginRow, int beginCol)
static bool isAllowed(Derived const &array, Range const &I, Range const &J)
static bool resize(Derived const &array, Range const &I, Range const &J)
static bool shift(Derived const &array, int beginRow, int beginCol)
static bool isAllowed(Derived const &array, Range const &I, Range const &J)
static bool resize(Derived const &array, Range const &I)
static bool shift(Derived const &array, int begin)
static bool resize(Derived const &array, Range const &I)
static bool shift(Derived const &array, int begin)
static bool isAllowed(Derived const &array, Range const &I, Range const &J)
Utility class allowing to know if in an assignment the destination must be resized or shifted.
utility class that select if the copy will be by row or by column
Copycat to use at compile time.
static void run(Lhs &lhs, ExprBase< Rhs > const &rhs)
static void run(Lhs &lhs, ExprBase< Rhs > const &rhs)
static void run(Lhs &lhs, ExprBase< Rhs > const &rhs)
static void run(Lhs &lhs, ExprBase< Rhs > const &rhs)
static void run(Lhs &lhs, ExprBase< Rhs > const &rhs)
utility class that select the resize method to call
static void run(Lhs &lhs, ExprBase< Rhs > const &rhs)