STK++ 0.9.13
STK_ArrayBase.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: 13 oct. 2012
28 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
36#ifndef STK_ARRAYBASE_H
37#define STK_ARRAYBASE_H
38
39#include "STK_ExprBase.h"
43
45#define MAKE_RESHAPE_OPERATOR(OPERATOR, SHAPE) \
46 inline OPERATOR##Operator< Derived> const SHAPE() const \
47 { return OPERATOR##Operator< Derived>(this->asDerived()); } \
48 inline OPERATOR##Accessor< Derived> SHAPE() \
49 { return OPERATOR##Accessor< Derived>(this->asDerived()); }
50
51namespace STK
52{
53
66template< class Derived>
67class ArrayBase: public ExprBase<Derived>
68{
69 public:
73
74 enum
75 {
81 };
82
83 protected:
88
89 public:
90 // start appliers
105 template<typename Visitor>
106 void apply(Visitor& visitor);
108 Derived& randUnif();
112 Derived& randGauss();
115 Derived& rand( Law::IUnivLaw<Type> const& law);
117 Derived& setOnes();
119 Derived& setZeros();
121 Derived& ones();
123 Derived& zeros();
124
128 Derived& setValue(TypeConst value);
132 inline void setValue(int i, TypeConst value)
133 { this->asDerived().setValueImpl(i, value);}
137 inline void setValue(int i, int j, TypeConst value)
138 { this->asDerived().setValueImpl(i, j, value);}
139
147 template<class Rhs> Derived& assign(ExprBase<Rhs> const& rhs);
148
150 Derived& operator=( Type const& value);
152 Derived& operator=( Derived const& rhs);
154 template<typename Rhs>
155 Derived& operator=( ExprBase<Rhs> const& rhs);
156
158 template<typename Rhs>
159 Derived& operator+=( ExprBase<Rhs> const& other);
161 template<typename Rhs>
162 Derived& operator-=( ExprBase<Rhs> const& other);
164 template<typename Rhs>
165 Derived& operator/=( ExprBase<Rhs> const& other);
167 template<typename Rhs>
168 Derived& operator%=( ExprBase<Rhs> const& other);
170 template<typename Rhs>
171 Derived& operator*=( ExprBase<Rhs> const& other);
172
174 Derived& operator+=( Type const& other);
176 Derived& operator-=( Type const& other);
178 Derived& operator*=( Type const& other);
180 Derived& operator/=( Type const& other);
182 Derived& operator%=( Type const& other);
183
188 template<class Rhs>
189 Derived& copy( ExprBase<Rhs> const& rhs);
190
207
208 // slice operators and accessors
210 inline ColOperator<Derived> const col(int j) const
211 { return ColOperator<Derived> (this->asDerived(), j);}
213 inline RowOperator<Derived> const row(int i) const
214 { return RowOperator<Derived> (this->asDerived(), i);}
216 template<int Size_>
218 {
220 return SubVectorOperator<Derived, Size_>(this->asDerived(), I);
221 }
223 template<int SizeRows_, int SizeCols_>
231 { return ColAccessor<Derived> (this->asDerived(), j);}
234 { return RowAccessor<Derived> (this->asDerived(), i);}
236 template<int Size_>
243 template<int SizeRows_, int SizeCols_>
249
250 // overloaded operators
254 inline TypeConst operator()(int i, int j) const
255 {
256#ifdef STK_BOUNDS_CHECK
257 if (this->beginRows() > i) { STKOUT_OF_RANGE_2ARG(IArrayBase::elt, i, j, beginRows() > i);}
258 if (this->endRows() <= i) { STKOUT_OF_RANGE_2ARG(IArrayBase::elt, i, j, endRows() <= i);}
259 if (this->beginCols() > j) { STKOUT_OF_RANGE_2ARG(IArrayBase::elt, i, j, beginCols() > j);}
260 if (this->endCols() <= j) { STKOUT_OF_RANGE_2ARG(IArrayBase::elt, i, j, endCols() <= j);}
261#endif
262 return this->elt(i,j);}
266 inline Type& operator()(int i, int j)
267 {
268#ifdef STK_BOUNDS_CHECK
269 if (this->beginRows() > i) { STKOUT_OF_RANGE_2ARG(IArrayBase::elt, i, j, beginRows() > i);}
270 if (this->endRows() <= i) { STKOUT_OF_RANGE_2ARG(IArrayBase::elt, i, j, endRows() <= i);}
271 if (this->beginCols() > j) { STKOUT_OF_RANGE_2ARG(IArrayBase::elt, i, j, beginCols() > j);}
272 if (this->endCols() <= j) { STKOUT_OF_RANGE_2ARG(IArrayBase::elt, i, j, endCols() <= j);}
273#endif
274 return this->elt(i,j);
275 }
279 inline TypeConst operator[](int i) const
280 {
282#ifdef STK_BOUNDS_CHECK
283 if (this->begin() > i) { STKOUT_OF_RANGE_1ARG(IArrayBase::elt, i, begin() > i);}
284 if (this->end() <= i) { STKOUT_OF_RANGE_1ARG(IArrayBase::elt, i, end() <= i);}
285#endif
286 return this->elt(i);
287 }
291 inline Type& operator[](int i)
292 {
294#ifdef STK_BOUNDS_CHECK
295 if (this->begin() > i) { STKOUT_OF_RANGE_1ARG(IArrayBase::elt, i, begin() > i);}
296 if (this->end() <= i) { STKOUT_OF_RANGE_1ARG(IArrayBase::elt, i, end() <= i);}
297#endif
298 return this->elt(i);
299 }
301 inline TypeConst operator()() const { return this->elt();}
303 inline Type& operator()() { return this->elt();}
310
312 template<typename Rhs>
314};
315
316} // namespace STK
317
318#undef MAKE_RESHAPE_OPERATOR
319
320#include "STK_ArrayBaseApplier.h"
321#include "STK_ArrayBaseAssign.h"
323
324#endif /* STK_ARRAYBASE_H_ */
In this file we define the appliers on writable arrays.
In this file we implement the copy and assign methods.
In this file we implement the ArrayInitializer class.
#define MAKE_RESHAPE_OPERATOR(OPERATOR, SHAPE)
utility macro allowing to construct unary operators
In this file we define the base class for Arrays and Expressions.
#define STKOUT_OF_RANGE_1ARG(Where, Arg, Error)
Definition STK_Macros.h:93
#define STKOUT_OF_RANGE_2ARG(Where, Arg1, Arg2, Error)
Definition STK_Macros.h:102
In this file we implement the DiagonalAccessor, DiagonalGetterAccessor, UpperTriangularizeAccessor,...
In this file we implement the RowAccessor, ColAccessor, SubVectorAccessor and SubAccessor classes.
#define STK_STATIC_ASSERT_ONE_DIMENSION_ONLY(EXPR)
#define STK_STATIC_ASSERT_TWO_DIMENSIONS_ONLY(EXPR)
In this file we implement the TransposeAccessor class.
base class for template arrays.
SubVectorAccessor< Derived, Size_ > sub(TRange< Size_ > const &I)
ArrayInitializer< Derived > operator<<(Type const &s)
Convenient operator to set the coefficients of a matrix.
TransposeOperator< Derived > const transpose() const
Derived & operator+=(ExprBase< Rhs > const &other)
Add Rhs to this.
Derived & zeros()
set zero to this using a Visitor.
Derived & operator=(Type const &value)
void setValue(int i, int j, TypeConst value)
set a value to this container at position (i,j).
DiagonalGetterOperator< Derived > const getDiagonal() const
Derived & copy(ExprBase< Rhs > const &rhs)
overwrite this with src.
UpperTriangularizeOperator< Derived > const upperTriangularize() const
SubAccessor< Derived, SizeRows_, SizeCols_ > sub(TRange< SizeRows_ > const &I, TRange< SizeCols_ > const &J)
Derived & setValue(TypeConst value)
set a value to this container.
ArrayBase()
Default constructor.
~ArrayBase()
destructor
Derived & ones()
set one to this using a Visitor.
ColOperator< Derived > const col(int j) const
SubOperator< Derived, SizeRows_, SizeCols_ > const sub(TRange< SizeRows_ > const &I, TRange< SizeCols_ > const &J) const
Type & operator[](int i)
hidden::Traits< Derived >::Type Type
LowerSymmetrizeOperator< Derived > const lowerSymmetrize() const
Derived & assign(ExprBase< Rhs > const &rhs)
Derived & operator/=(ExprBase< Rhs > const &other)
divide this by Rhs.
Type & operator()(int i, int j)
RowOperator< Derived > const row(int i) const
Derived & operator*=(ExprBase< Rhs > const &other)
multiply this by Rhs.
Derived & randUnif()
set random values to this using a uniform law.
Type & operator()()
ColAccessor< Derived > col(int j)
void apply(Visitor &visitor)
Apply the Visitor visitor to the whole coefficients of the array.
Derived & setZeros()
set zero to this using a Visitor.
void setValue(int i, TypeConst value)
set a value to this container at index i.
TypeConst operator()() const
hidden::Traits< Derived >::TypeConst TypeConst
Derived & randGauss()
set random values to this using a standard gaussian law.
Derived & operator-=(ExprBase< Rhs > const &other)
subtract a Rhs to this.
TypeConst operator()(int i, int j) const
Derived & rand(Law::IUnivLaw< Type > const &law)
set random values to this using a distribution law given by the user.
SymmetrizeOperator< Derived > const symmetrize() const
RowAccessor< Derived > row(int i)
SubVectorOperator< Derived, Size_ > const sub(TRange< Size_ > const &I) const
DiagonalizeOperator< Derived > const diagonalize() const
TypeConst operator[](int i) const
ExprBase< Derived > Base
Derived & operator%=(ExprBase< Rhs > const &other)
Take modulo of this by Rhs.
UpperSymmetrizeOperator< Derived > const upperSymmetrize() const
Derived & setOnes()
set one to this using a Visitor.
LowerTriangularizeOperator< Derived > const lowerTriangularize() const
Generic expression when the column of an expression is accessed.
base class for template evaluation expressions and visitors.
Interface base class for all the univariate distributions.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
The namespace STK is the main domain space of the Statistical ToolKit project.