STK++ 0.9.13
STK_SlicingOperators.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: 21 nov. 2013
28 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
35#ifndef STK_SLICINGOPERATORS_H
36#define STK_SLICINGOPERATORS_H
37
38namespace STK
39{
40// forward declaration
41template< typename Array> class RowOperator;
42template< typename Array> class ColOperator;
43// only for vectors/points/diagonal expressions
44template< typename Array, int Size_> class SubVectorOperator;
45// only for array expressions
46template< typename Array, int SizeRows_, int SizeCols_> class SubOperator;
47
48namespace hidden
49{
50
54template<typename Lhs>
56{
57 enum
58 {
59 structure_ = ( Lhs::structure_ != int(Arrays::vector_) && Lhs::structure_ != int(Arrays::number_) )
60 ? Arrays::point_ : Arrays::number_,
61 orient_ = Lhs::orient_,
62 sizeRows_ = 1,
63 sizeCols_ = Lhs::sizeCols_,
64 storage_ = Lhs::storage_
65 };
68 typedef typename Lhs::Type Type;
69 typedef typename Lhs::TypeConst TypeConst;
70};
71
72} // namespace hidden
87template< typename Lhs>
88class RowOperator: public ExprBase< RowOperator< Lhs> >, public TRef<1>
89{
90 public:
92 typedef typename hidden::Traits< RowOperator< Lhs> >::Type Type;
93 typedef typename hidden::Traits< RowOperator< Lhs> >::TypeConst TypeConst;
94 enum
95 {
96 structure_ = hidden::Traits< RowOperator<Lhs> >::structure_,
98 sizeRows_ = hidden::Traits< RowOperator<Lhs> >::sizeRows_,
99 sizeCols_ = hidden::Traits< RowOperator<Lhs> >::sizeCols_,
100 storage_ = hidden::Traits< RowOperator<Lhs> >::storage_
101 };
105 typedef TRange<sizeCols_> ColRange; // will not be used
106
108 inline RowOperator( Lhs const& lhs, int i): Base(), lhs_(lhs), i_(i), rows_(i_, 1), cols_(lhs_.rangeColsInRow(i_)) {}
109// /** Copy constructor */
110// inline RowOperator( RowOperator const& row, bool ref = true)
111// : Base(), lhs_(row.lhs_), i_(row.i_), rows_(row.rows_), cols_(row.cols_) {}
113 inline RowRange const& rowsImpl() const { return rows_;}
115 inline ColRange const& colsImpl() const { return cols_;}
117 inline Lhs const& lhs() const { return lhs_;}
121 inline TypeConst elt2Impl(int i, int j) const
122 {
123#ifdef STK_BOUNDS_CHECK
124 if (i != i_) { STKRUNTIME_ERROR_2ARG(RowOperatorBase::elt2Impl,i,j,row index is not valid);}
125#endif
126 return (lhs().elt(i_, j));
127 }
131 inline TypeConst elt1Impl(int j) const { return (lhs().elt(i_, j));}
133 inline TypeConst elt0Impl() const { return (lhs().elt());}
134
135 protected:
136 Lhs const& lhs_;
137 int i_;
140};
141
142
143namespace hidden
144{
148template<typename Lhs>
150{
151 enum
152 {
153 structure_ = ( Lhs::structure_ != int(Arrays::point_) && Lhs::structure_ != int(Arrays::number_) )
154 ? Arrays::vector_ : Arrays::number_,
155 orient_ = Lhs::orient_,
156 sizeRows_ = Lhs::sizeRows_,
157 sizeCols_ = 1,
158 storage_ = Lhs::storage_
159 };
162 typedef typename Lhs::Type Type;
163 typedef typename Lhs::TypeConst TypeConst;
164};
165
166} // namespace hidden
167
182template< typename Lhs>
183class ColOperator: public ExprBase< ColOperator< Lhs> >, public TRef<1>
184{
185 public:
187 typedef typename hidden::Traits< ColOperator<Lhs> >::Type Type;
188 typedef typename hidden::Traits< ColOperator<Lhs> >::TypeConst TypeConst;
189 enum
190 {
191 structure_ = hidden::Traits< ColOperator<Lhs> >::structure_,
193 sizeRows_ = hidden::Traits< ColOperator<Lhs> >::sizeRows_,
194 sizeCols_ = hidden::Traits< ColOperator<Lhs> >::sizeCols_,
195 storage_ = hidden::Traits< ColOperator<Lhs> >::storage_
196 };
201
203 inline ColOperator( Lhs const& lhs, int j)
204 : Base(), lhs_(lhs), j_(j), rows_(lhs_.rangeRowsInCol(j_)), cols_(j_,1) {}
205// /** Copy constructor */
206// inline ColOperator( ColOperator const& col, bool ref = true)
207// : Base(), lhs_(col.lhs_), j_(col.j_), rows_(col.rows_), cols_(col.cols_) {}
209 inline RowRange const& rowsImpl() const { return rows_;}
211 inline ColRange const& colsImpl() const { return cols_;}
212
214 inline Lhs const& lhs() const { return lhs_; }
218 inline TypeConst elt2Impl(int i, int j) const
219 {
220#ifdef STK_BOUNDS_CHECK
221 if (j != j_) { STKRUNTIME_ERROR_2ARG(ColOperatorBase::elt2Impl,i,j,column index is not valid);}
222#endif
223 return (lhs_.elt(i, j_));
224 }
228 inline TypeConst elt1Impl(int i) const { return (lhs_.elt(i, j_));}
230 inline TypeConst elt0Impl() const { return (lhs_.elt(j_));}
231
232 protected:
233 Lhs const& lhs_;
234 const int j_;
237};
238
239
240namespace hidden
241{
245template<typename Lhs, int Size_>
247{
248 enum
249 {
250 structure_ = Lhs::structure_,
251 orient_ = Lhs::orient_,
252 sizeRows_ = (structure_ == int(Arrays::point_)) ? 1 : Size_,
253 sizeCols_ = (structure_ == int(Arrays::vector_)) ? 1 : Size_,
254 storage_ = Lhs::storage_
255 };
258 typedef typename Lhs::Type Type;
259 typedef typename Lhs::TypeConst TypeConst;
260};
261
262} // namespace hidden
263
264// forward declaration
265template< typename Lhs, int Size_, int Structure_>
267
283template< typename Lhs, int Size_>
285 , hidden::Traits< SubVectorOperator<Lhs, Size_> >::structure_
286 >
287 , public TRef<1>
288{
289 public:
292 enum
293 {
299 };
301
306
308 inline SubVectorOperator( Lhs const& lhs, TRange<Size_> const& I): Base(I), lhs_(lhs) {}
310 inline Lhs const& lhs() const { return lhs_;}
314 inline TypeConst elt2Impl(int i, int j) const { return (lhs_.elt2Impl(i, j));}
318 inline TypeConst elt1Impl(int i) const { return (lhs_.elt1Impl(i));}
320 inline TypeConst elt0Impl() const { return (lhs_.elt());}
321
322 protected:
326 inline Type& elt2Impl(int i, int j) { return (lhs_.elt2Impl(i, j));}
330 inline Type& elt1Impl(int i) { return (lhs_.elt1Impl(i));}
332 inline Type& elt0Impl() { return (lhs_.elt());}
333
334 protected:
335 Lhs const& lhs_;
336};
337
338
343template< typename Lhs, int Size_>
344class SubVectorOperatorBase<Lhs, Size_, Arrays::point_ >: public ExprBase< SubVectorOperator<Lhs, Size_> >
345{
346 public:
349 enum
350 {
353 };
359 inline SubVectorOperatorBase( ColRange const& J): Base(), cols_(J) {}
361 inline RowRange const& rowsImpl() const { return this->asDerived().lhs().rows();}
363 inline ColRange const& colsImpl() const { return cols_;}
364
365 protected:
367};
368
373template< typename Lhs, int Size_>
374class SubVectorOperatorBase<Lhs, Size_, Arrays::vector_ >: public ExprBase< SubVectorOperator<Lhs, Size_> >
375{
376 public:
379 enum
380 {
383 };
389 inline SubVectorOperatorBase( RowRange const& I): Base(), rows_(I) {}
391 inline RowRange const& rowsImpl() const { return rows_;}
393 inline ColRange const& colsImpl() const { return this->asDerived().lhs().cols();}
394
395 protected:
397};
398
403template< typename Lhs, int Size_>
404class SubVectorOperatorBase<Lhs, Size_, Arrays::diagonal_ >: public ExprBase< SubVectorOperator<Lhs, Size_> >
405{
406 public:
409 enum
410 {
413 };
419 inline SubVectorOperatorBase( RowRange const& I): Base(), range_(I) {}
421 inline RowRange const& rowsImpl() const { return range_;}
423 inline ColRange const& colsImpl() const { return range_;}
424
425 protected:
427};
428
429
430namespace hidden
431{
435template<typename Lhs, int SizeRows_, int SizeCols_>
437{
438 enum
439 {
440 structure_ = Lhs::structure_,
441 orient_ = Lhs::orient_,
442 sizeRows_ = SizeRows_,
443 sizeCols_ = SizeCols_,
444 storage_ = Lhs::storage_
445 };
446 typedef typename Lhs::Type Type;
447 typedef typename Lhs::TypeConst TypeConst;
448};
449
450} // namespace hidden
451
466template< typename Lhs, int SizeRows_, int SizeCols_>
467class SubOperator: public ExprBase< SubOperator<Lhs, SizeRows_, SizeCols_> >
468 , public TRef<1>
469{
470 public:
473 enum
474 {
480 };
482
487
489 inline SubOperator( Lhs const& lhs, RowRange const& I, ColRange const& J)
490 : Base(), lhs_(lhs), rows_(I), cols_(J) {}
492 inline RowRange const& rowsImpl() const { return rows_;}
494 inline ColRange const& colsImpl() const { return cols_;}
496 inline Lhs const& lhs() const { return lhs_;}
497
501 inline TypeConst elt2Impl(int i, int j) const { return (lhs_.elt2Impl(i, j));}
505 inline TypeConst elt1Impl(int i) const { return (lhs_.elt1Impl(i));}
507 inline TypeConst elt0Impl() const { return (lhs_.elt());}
508
509 protected:
510 Lhs const& lhs_;
513};
514
515
516} // namespace STK
517
518#endif /* STK_SLICINGOPERATORS_H */
#define STKRUNTIME_ERROR_2ARG(Where, Arg1, Arg2, Error)
Definition STK_Macros.h:120
Generic expression when the column of an expression is accessed.
TypeConst elt0Impl() const
access to the element
TRange< sizeRows_ > RowRange
Type of the Range for the rows.
ColOperator(Lhs const &lhs, int j)
constructor
hidden::Traits< ColOperator< Lhs > >::TypeConst TypeConst
hidden::Traits< ColOperator< Lhs > >::Type Type
TRange< sizeCols_ > ColRange
Type of the Range for the columns.
TypeConst elt1Impl(int i) const
ExprBase< ColOperator< Lhs > > Base
RowRange const & rowsImpl() const
Lhs const & lhs() const
TypeConst elt2Impl(int i, int j) const
ColRange const & colsImpl() const
base class for template evaluation expressions and visitors.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
Generic expression when the row of an expression is accessed.
Lhs const & lhs() const
TRange< sizeRows_ > RowRange
Type of the Range for the rows.
TypeConst elt1Impl(int j) const
ExprBase< RowOperator< Lhs > > Base
hidden::Traits< RowOperator< Lhs > >::TypeConst TypeConst
TypeConst elt2Impl(int i, int j) const
RowOperator(Lhs const &lhs, int i)
constructor
TypeConst elt0Impl() const
accesses to the element
ColRange const & colsImpl() const
hidden::Traits< RowOperator< Lhs > >::Type Type
TRange< sizeCols_ > ColRange
Type of the Range for the columns.
RowRange const & rowsImpl() const
Generic expression when the sub-part of an expression is accessed.
TypeConst elt1Impl(int i) const
TypeConst elt2Impl(int i, int j) const
hidden::Traits< SubOperator< Lhs, SizeRows_, SizeCols_ > >::Type Type
TRange< sizeRows_ > RowRange
Type of the Range for the rows.
TypeConst elt0Impl() const
accesses to the element
SubOperator(Lhs const &lhs, RowRange const &I, ColRange const &J)
constructor
hidden::Traits< SubOperator< Lhs, SizeRows_, SizeCols_ > >::TypeConst TypeConst
ExprBase< SubOperator< Lhs, SizeRows_, SizeCols_ > > Base
TRange< sizeCols_ > ColRange
Type of the Range for the columns.
ColRange const & colsImpl() const
Lhs const & lhs() const
RowRange const & rowsImpl() const
TRange< sizeRows_ > RowRange
Type of the Range for the rows.
TRange< sizeCols_ > ColRange
Type of the Range for the columns.
TRange< sizeCols_ > ColRange
Type of the Range for the columns.
TRange< sizeRows_ > RowRange
Type of the Range for the rows.
TRange< sizeCols_ > ColRange
Type of the Range for the columns.
TRange< sizeRows_ > RowRange
Type of the Range for the rows.
Specialization for point_.
Generic expression when the sub-part of an expression is accessed (specialization for vectors)
hidden::Traits< SubVectorOperator< Lhs, Size_ > >::TypeConst TypeConst
SubVectorOperatorBase< Lhs, Size_, structure_ > Base
TRange< sizeRows_ > RowRange
Type of the Range for the rows.
TypeConst elt2Impl(int i, int j) const
Type & elt0Impl()
accesses to the element
Type & elt2Impl(int i, int j)
SubVectorOperator(Lhs const &lhs, TRange< Size_ > const &I)
constructor
TypeConst elt0Impl() const
accesses to the element
TRange< sizeCols_ > ColRange
Type of the Range for the columns.
TypeConst elt1Impl(int i) const
hidden::Traits< SubVectorOperator< Lhs, Size_ > >::Type Type
@ number_
(1,1) matrix/vector/array/expression (like a number)
@ point_
row oriented vector/array/expression
@ vector_
column oriented vector/array/expression
The namespace STK is the main domain space of the Statistical ToolKit project.
Base class for all referencing containers.
RowOperator< ColOperator< Lhs > > Row
ColOperator< ColOperator< Lhs > > Col
RowOperator< RowOperator< Lhs > > Row
ColOperator< RowOperator< Lhs > > Col
RowOperator< SubVectorOperator< Lhs, Size_ > > Row
ColOperator< SubVectorOperator< Lhs, Size_ > > Col