STK++ 0.9.13
STK_Visitors.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: 27 sept. 2012
28 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
35#ifndef STK_VISITORS_H
36#define STK_VISITORS_H
37
38
39namespace STK
40{
41
42namespace hidden
43{
44
49template <class Visitor, int Structure_> struct GetIdx;
50template <class Visitor> struct GetIdx<Visitor, Arrays::vector_>
51{ inline static int idx(Visitor const& visitor) { return visitor.row_;};};
52
53template <class Visitor> struct GetIdx<Visitor, Arrays::point_>
54{ inline static int idx(Visitor const& visitor) { return visitor.col_;};};
55
56template <class Visitor> struct GetIdx<Visitor, Arrays::diagonal_>
57{ inline static int idx(Visitor const& visitor) { return visitor.col_;};};
58
59
63template <typename Type_>
65{
66 typedef Type_ Type;
67 typedef typename RemoveConst<Type>::Type const& TypeConst;
69 int row_, col_;
71 inline TypeConst result() const { return res_;}
72};
73
79template <typename Type>
81{
84 inline void operator()( Type const& value, int i, int j)
85 {
87 { this->res_ = value; this->row_ = i; this->col_ = j;}
88 }
89};
90
97template <typename Type>
99{
102 inline void operator()( Type const& value, int i, int j)
103 {
105 { this->res_ = value; this->row_ = i; this->col_ = j;}
106 }
107};
113template <typename Type>
115{
118 inline void operator()( Type const& value, int i, int j)
119 {
120 if (value > this->res_)
121 { this->res_ = value; this->row_ = i; this->col_ = j;}
122 }
123};
129template <typename Type>
131{
134 inline void operator()( Type const& value, int i, int j)
135 {
137 if(value > this->res_)
138 { this->res_ = value; this->row_ = i; this->col_ = j;}
139 }
140};
146template <typename Type_>
148{
149 typedef Type_ Type;
150 typedef typename RemoveConst<Type>::Type const& TypeConst;
151
154 inline void operator() ( Type const& value, int i, int j)
155 { res_ = std::min(res_,value);}
156 inline void operator() ( Type const& value, int i)
157 { res_ = std::min(res_,value);}
158 inline TypeConst result() const { return res_;}
159};
165template <typename Type_>
167{
168 typedef Type_ Type;
169 typedef typename RemoveConst<Type>::Type const& TypeConst;
170
173 inline void operator() ( Type const& value, int i, int j)
174 { if (Arithmetic<Type>::isFinite(value)) { res_ = std::min(res_,value);} }
175 inline void operator() ( Type const& value, int i)
176 { if (Arithmetic<Type>::isFinite(value)) { res_ = std::min(res_,value);}}
177 inline TypeConst result() const { return res_;}
178};
184template <typename Type_>
186{
187 typedef Type_ Type;
188 typedef typename RemoveConst<Type>::Type const& TypeConst;
189
191 inline MaxVisitor(): res_(-Arithmetic<Type>::max()) {}
192 inline void operator() ( Type const& value, int i, int j)
193 { res_ = std::max(res_,value);}
194 inline void operator() ( Type const& value, int i)
195 { res_ = std::max(res_,value);}
196 inline TypeConst result() const { return res_;}
197};
203template <typename Type_>
205{
206 typedef Type_ Type;
207 typedef typename RemoveConst<Type>::Type const& TypeConst;
208
211 inline void operator() ( Type const& value, int i, int j)
212 { if (Arithmetic<Type>::isFinite(value)) { res_ = std::max(res_,value);}}
213 inline void operator() ( Type const& value, int i)
214 { if (Arithmetic<Type>::isFinite(value)) { res_ = std::max(res_,value);}}
215 inline TypeConst result() const { return res_;}
216};
222template <typename Type_>
224{
225 typedef Type_ Type;
226 typedef typename RemoveConst<Type>::Type const& TypeConst;
227
229 inline SumVisitor(): res_(Type(0)) {}
230 inline void operator() ( Type const& value, int i, int j)
231 { res_ += value;}
232 inline void operator() ( Type const& value, int i)
233 { res_ += value;}
234 inline TypeConst result() const { return res_;}
235};
241template <typename Type_>
243{
244 typedef Type_ Type;
247 int nb_;
248 inline MeanVisitor(): res_(Type(0)), nb_(0) {}
249 inline void operator() ( Type const& value, int i, int j)
250 { res_ += value; nb_++;}
251 inline void operator() ( Type const& value, int i)
252 { res_ += value; nb_++;}
253 inline TypeConst result() const { return nb_ == 0 ? Arithmetic<Type>::NA() : res_/nb_;}
254};
260template <typename Type_>
262{
263 typedef Type_ Type;
266 int nb_;
267 inline MeanSafeVisitor(): res_(Type(0)), nb_(0) {}
268 inline void operator() ( Type const& value, int i, int j)
269 {
271 { res_ += value; nb_++;}
272 }
273 inline void operator() ( Type const& value, int i)
274 {
276 { res_ += value; nb_++;}
277 }
278 inline TypeConst result() const { return nb_ == 0 ? Arithmetic<Type>::NA() : res_/nb_;}
279};
291template <typename Type_>
293{
294 int res_;
295 typedef int Type;
296 typedef int const& TypeConst;
298 inline void operator() ( Type_ const& value, int i, int j)
299 { if (value) ++res_;}
300 inline void operator() ( Type_ const& value, int i)
301 { if (value) ++res_;}
302 inline TypeConst result() const { return res_;}
303};
304
315template <typename Type_>
317{
318 bool res_;
319 typedef bool Type;
320 typedef bool const& TypeConst;
321 inline AllVisitor(): res_(true) {}
322 inline void operator() ( Type_ const& value, int i, int j)
323 { res_ &= (value);}
324 inline void operator() ( Type_ const& value, int i)
325 { res_ &= (value);}
326 inline TypeConst result() const { return res_;}
327};
338template <typename Type_>
340{
341 bool res_;
342 typedef bool Type;
343 typedef bool const& TypeConst;
344 inline AnyVisitor(): res_(false) {}
345 inline void operator() ( Type_ const& value, int i, int j) { res_ |= (value);}
346 inline void operator() ( Type_ const& value, int i) { res_ |= (value);}
347 inline TypeConst result() const { return res_;}
348};
349
350} //namespace hidden
351
352} // namespace STK
353
354#endif /* STK_VISITORS_H */
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
const int baseIdx
base index of the containers created in STK++.
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 ...
The namespace STK is the main domain space of the Statistical ToolKit project.
Arithmetic properties of STK fundamental types.
static Type NA()
Adding a Non Available (NA) special number.
Visitor checking if all the elements of an array are different from zero.
void operator()(Type_ const &value, int i, int j)
TypeConst result() const
Visitor checking if at least, one element of an array is different from zero.
void operator()(Type_ const &value, int i, int j)
TypeConst result() const
Visitor counting the number of not-zero element in an array This visitor can be used in conjunction w...
void operator()(Type_ const &value, int i, int j)
TypeConst result() const
Base class to implement min, max, sum,... visitors for 2D containers.
RemoveConst< Type >::Type const & TypeConst
static int idx(Visitor const &visitor)
static int idx(Visitor const &visitor)
static int idx(Visitor const &visitor)
utility class for getting the result from a visitor acting on a vector or a point.
Visitor computing safely the maximal coefficient of the Array.
void operator()(Type const &value, int i, int j)
Visitor computing the maximal coefficient of the Array.
void operator()(Type const &value, int i, int j)
Visitor computing safely the max of all the coefficients of the Array.
RemoveConst< Type >::Type const & TypeConst
void operator()(Type const &value, int i, int j)
Visitor computing the max of all the coefficients of the Array.
void operator()(Type const &value, int i, int j)
TypeConst result() const
RemoveConst< Type >::Type const & TypeConst
Visitor computing safely the mean of all the coefficients of the Array.
RemoveConst< Type >::Type TypeConst
void operator()(Type const &value, int i, int j)
Visitor computing the mean of all the coefficients of the Array.
RemoveConst< Type >::Type TypeConst
TypeConst result() const
void operator()(Type const &value, int i, int j)
Visitor computing safely the minimal coefficient with its value and indexes.
void operator()(Type const &value, int i, int j)
Visitor computing the min coefficient with its value and coordinates.
void operator()(Type const &value, int i, int j)
Visitor computing safely the min of all the coefficients of the Array.
RemoveConst< Type >::Type const & TypeConst
void operator()(Type const &value, int i, int j)
Visitor computing the min of all the coefficients of the Array.
void operator()(Type const &value, int i, int j)
TypeConst result() const
RemoveConst< Type >::Type const & TypeConst
Visitor computing the sum of all the coefficients of the Array.
RemoveConst< Type >::Type const & TypeConst
TypeConst result() const
void operator()(Type const &value, int i, int j)