STK++ 0.9.13
STK_SlicingVisitors.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 * Purpose: Functors applied to the Expression and arrays
28 * Author: Serge Iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
51#ifndef STK_SLICEVISITORS_H
52#define STK_SLICEVISITORS_H
53
54#define STK_SLICEVISITORS(VISITOR, FUNC) \
55template< class Derived> \
56typename hidden::SliceVisitorSelector<Derived, hidden::VISITOR, Arrays::by_col_>::type_result \
57FUNC(Derived const& A) \
58{ return typename hidden::SliceVisitorSelector<Derived, hidden::VISITOR , Arrays::by_col_>::VisitorOp(A);} \
59template< class Derived> \
60typename hidden::SliceVisitorSelector<Derived, hidden::VISITOR, Arrays::by_col_>::type_result \
61FUNC##ByCol(Derived const& A) \
62{ return typename hidden::SliceVisitorSelector<Derived, hidden::VISITOR, Arrays::by_col_>::VisitorOp(A);} \
63template< class Derived> \
64typename hidden::SliceVisitorSelector<Derived, hidden::VISITOR, Arrays::by_row_>::type_result \
65FUNC##ByRow(Derived const& A) \
66{ return typename hidden::SliceVisitorSelector<Derived, hidden::VISITOR, Arrays::by_row_>::VisitorOp(A);}
67
68namespace STK
69{
70
71// forward declaration
72template<typename Derived, template<class> class Visitor>
73class VisitorByCol;
74
75namespace hidden
76{
77
81template<typename Derived, template<class> class Visitor>
82struct Traits< VisitorByCol <Derived, Visitor> >
83{
84 enum
85 {
86 structure_ = Arrays::point_,
87 orient_ = Arrays::by_row_,
88 sizeRows_ = 1,
89 sizeCols_ = Derived::sizeCols_,
90 storage_ = Arrays::dense_
91 };
92 typedef typename Derived::Type Type_;
94 typedef typename VisitorType::Type Type;
95 typedef typename VisitorType::TypeConst TypeConst;
96
98};
99
100} // end namespace hidden
101
102// forward declaration
103template<typename Derived, template<class> class Visitor>
105
106
110template<typename Derived, template<class> class Visitor>
111class VisitorByCol: public ExprBase< VisitorByCol<Derived, Visitor> >, public TRef<1>
112{
113 public:
119 enum
120 {
126 };
131
133 VisitorByCol( Derived const& lhs) : lhs_(lhs), result_(1,lhs_.sizeCols())
134 {
135 result_.shift(lhs_.beginCols());
136 for (int j= lhs_.beginCols(); j < lhs_.endCols(); ++j)
137 {
139 result_.elt(j) = lhs_.col(j).visit(visit);
140 }
141 }
143 inline RowRange const& rowsImpl() const { return result_.rows();}
145 inline ColRange const&colsImpl() const { return result_.cols();}
146
148 inline Derived const& lhs() const { return lhs_; }
150 inline Allocator const& result() const { return result_; }
151
153 inline Type const& elt2Impl(int i, int j) const { return result_.elt(i,j);}
155 inline Type const& elt1Impl(int i) const { return result_.elt(i);}
157 inline Type const& elt0Impl() const { return result_.elt();}
158
159 protected:
160 Derived const& lhs_;
161
162 private:
164};
165
166// forward declaration
167template<typename Derived, template<class> class Visitor>
168class VisitorByRow;
169
170namespace hidden
171{
172
176template<typename Derived, template<class> class Visitor>
177struct Traits< VisitorByRow <Derived, Visitor> >
178{
179 enum
180 {
181 structure_ = Arrays::vector_,
183 sizeRows_ = Derived::sizeRows_,
184 sizeCols_ = 1,
185 storage_ = Arrays::dense_
186 };
187 typedef typename Derived::Type Type_;
189 typedef typename VisitorType::Type Type;
190 typedef typename VisitorType::TypeConst TypeConst;
191
193};
194
195} // end namespace hidden
196
197
201template<typename Derived, template<class> class Visitor>
202class VisitorByRow: public ExprBase< VisitorByRow<Derived, Visitor> >, public TRef<1>
203{
204 public:
205
210
212 enum
213 {
219 };
224
226 VisitorByRow( Derived const& lhs): lhs_(lhs), result_(lhs_.sizeRows(), 1)
227 {
228 result_.shift(lhs_.beginRows());
229 for (int i= lhs_.beginRows(); i < lhs_.endRows(); ++i)
230 {
232 result_.elt(i) = lhs_.row(i).visit(visit);
233 }
234 }
236 inline RowRange const& rowsImpl() const { return result_.rows();}
238 inline ColRange const&colsImpl() const { return result_.cols();}
239
241 inline Derived const& lhs() const { return lhs_; }
243 inline Allocator const& result() const { return result_; }
244
246 inline Type const& elt2Impl(int i, int j) const { return result_.elt(i,j);}
248 inline Type const& elt1Impl(int i) const { return result_.elt(i);}
250 inline Type const& elt0Impl() const { return result_.elt();}
251
252 protected:
253 Derived const& lhs_;
254
255 private:
257};
258
262template<typename Derived, template<class> class Visitor>
264{
265 typedef typename Derived::Type Type_;
266 typedef typename Visitor<Type_>::Type Type;
267 typedef Type Result;
268
270 inline ApplyVisitor( ExprBase<Derived> const& lhs) : lhs_(lhs.asDerived())
271 {
272 Visitor<Type_> visit;
273 lhs_.visit(visit);
274 }
276 inline operator Type () const { return result_;}
277 protected:
278 Derived const& lhs_;
279 private:
281};
282
283// Start utilites function
284namespace hidden
285{
291template<typename Derived, template<class> class Visitor, bool byCol>
293
297template<typename Derived, template<class> class Visitor>
299{
300 typedef typename Derived::Type Type;
301 enum
302 {
303 isVector_ = ( Derived::structure_ == int(Arrays::vector_)
304 || Derived::structure_ == int(Arrays::number_)
305 )
306 };
308 typedef typename VisitorOp::Result type_result;
309};
310
314template<typename Derived, template<class> class Visitor>
316{
317 typedef typename Derived::Type Type;
318 enum
319 {
320 isPoint_ = ( Derived::structure_ == int(Arrays::point_)
321 || Derived::structure_ == int(Arrays::number_)
322 )
323 };
325 typedef typename VisitorOp::Result type_result;
326};
327
328} // hidden
329
386
411
412} // namespace STK
413
414#undef STK_SLICEVISITORS
415
416#endif /*STK_SLICEVISITORS_H*/
#define STK_SLICEVISITORS(VISITOR, FUNC)
base class for template evaluation expressions and visitors.
Visitor::TypeConst visit(Visitor &visitor) const
Visit the container using a constant visitor.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
class allowing to apply a visitor on each columns of an expression.
Allocator const & result() const
hidden::Traits< VisitorByCol< Derived, Visitor > >::VisitorType VisitorType
hidden::Traits< VisitorByCol< Derived, Visitor > >::TypeConst TypeConst
RowRange const & rowsImpl() const
VisitorByCol(Derived const &lhs)
constructor
hidden::Traits< VisitorByCol< Derived, Visitor > >::Allocator Allocator
ColRange const & colsImpl() const
Type const & elt2Impl(int i, int j) const
access to the element (i,j)
Derived const & lhs() const
TRange< sizeCols_ > ColRange
Type of the Range for the columns.
TRange< sizeRows_ > RowRange
Type of the Range for the rows.
hidden::Traits< VisitorByCol< Derived, Visitor > >::Type Type
Type const & elt0Impl() const
access to the element
Type const & elt1Impl(int i) const
access to the element i
class allowing to apply a visitor on each columns of an expression.
hidden::Traits< VisitorByRow< Derived, Visitor > >::TypeConst TypeConst
TRange< sizeCols_ > ColRange
Type of the Range for the columns.
hidden::Traits< VisitorByRow< Derived, Visitor > >::VisitorType VisitorType
hidden::Traits< VisitorByRow< Derived, Visitor > >::Type Type
TRange< sizeRows_ > RowRange
Type of the Range for the rows.
hidden::Traits< VisitorByRow< Derived, Visitor > >::Allocator Allocator
RowRange const & rowsImpl() const
Type const & elt0Impl() const
access to the element
Derived const & lhs() const
Allocator const & result() const
VisitorByRow(Derived const &lhs)
constructor
Type const & elt1Impl(int i) const
access to the element i
Type const & elt2Impl(int i, int j) const
access to the element (i,j)
ColRange const & colsImpl() const
Arrays::SumOp< Lhs, Rhs >::result_type sum(Lhs const &lhs, Rhs const &rhs)
convenience function for summing two arrays
@ dense_
dense matrix/vector/array/expression
@ number_
(1,1) matrix/vector/array/expression (like a number)
@ point_
row oriented vector/array/expression
@ vector_
column oriented vector/array/expression
@ by_row_
storage by row
@ by_col_
storage by column
hidden::SliceVisitorSelector< Derived, hidden::MeanVisitor, Arrays::by_col_ >::type_result mean(Derived const &A)
If A is a row-vector or a column-vector then the function will return the usual mean value of the vec...
hidden::SliceVisitorSelector< Derived, hidden::MinSafeVisitor, Arrays::by_col_ >::type_result minSafe(Derived const &A)
If A is a row-vector or a column-vector then the function will return the usual minimal value of the ...
hidden::SliceVisitorSelector< Derived, hidden::CountVisitor, Arrays::by_col_ >::type_result count(Derived const &A)
If A is a row-vector or a column-vector then the function will return the usual count value of the ve...
hidden::SliceVisitorSelector< Derived, hidden::MeanSafeVisitor, Arrays::by_col_ >::type_result meanSafe(Derived const &A)
If A is a row-vector or a column-vector then the function will return the usual mean value of the vec...
hidden::SliceVisitorSelector< Derived, hidden::MinVisitor, Arrays::by_col_ >::type_result min(Derived const &A)
If A is a row-vector or a column-vector then the function will return the usual minimal value of the ...
hidden::SliceVisitorSelector< Derived, hidden::MaxSafeVisitor, Arrays::by_col_ >::type_result maxSafe(Derived const &A)
If A is a row-vector or a column-vector then the function will return the usual maximal value of the ...
hidden::SliceVisitorSelector< Derived, hidden::AnyVisitor, Arrays::by_col_ >::type_result any(Derived const &A)
If A is a row-vector or a column-vector then the function will return the usual visitor value of the ...
hidden::SliceVisitorSelector< Derived, hidden::MaxVisitor, Arrays::by_col_ >::type_result max(Derived const &A)
If A is a row-vector or a column-vector then the function will return the usual maximal value of the ...
hidden::SliceVisitorSelector< Derived, hidden::AllVisitor, Arrays::by_col_ >::type_result all(Derived const &A)
If A is a row-vector or a column-vector then the function will return the usual all value of the vect...
The namespace STK is the main domain space of the Statistical ToolKit project.
class allowing to apply a visitor on a vector or a point.
Visitor< Type_ >::Type Type
ApplyVisitor(ExprBase< Derived > const &lhs)
constructor
Base class for all referencing containers.
If<(bool) isPoint_, ApplyVisitor< Derived, Visitor >, VisitorByRow< Derived, Visitor > >::Result VisitorOp
If<(bool) isVector_, ApplyVisitor< Derived, Visitor >, VisitorByCol< Derived, Visitor > >::Result VisitorOp
Utility class that will select the type of operator to apply.
CAllocator< Type, sizeRows_, sizeCols_, orient_ > Allocator
CAllocator< Type, sizeRows_, sizeCols_, orient_ > Allocator