STK++ 0.9.13
STK_Array2D.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: 07 jul. 2007
28 * Author: Serge Iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
34#ifndef STK_ARRAY2D_H
35#define STK_ARRAY2D_H
36
37#include "STK_IArray2D.h"
38#include "STK_IArray2DSlicers.h"
40
41namespace STK
42{
43// forward declaration
44template< typename Type> class Array2D;
45template< typename Type> class Array2DNumber;
46template< typename Type> class Array2DPoint;
47template< typename Type> class Array2DVector;
48
56
57
58namespace hidden
59{
63template<class Type_>
64struct Traits< Array2D<Type_> >
65{
66 private:
67 class Void {};
68 public:
75 typedef Void SubVector;
76
77 typedef Type_ Type;
78 typedef typename RemoveConst<Type>::Type const& TypeConst;
79
80 enum
81 {
82 structure_ = Arrays::array2D_,
83 orient_ = Arrays::by_col_,
84 sizeRows_ = UnknownSize,
85 sizeCols_ = UnknownSize,
86 storage_ = Arrays::dense_ // always dense
87 };
89};
90
91} // namespace hidden
92
115template<class Type_ >
116class Array2D: public IArray2D< Array2D<Type_> >
117{
118 public:
122
129
132
133 enum
134 {
139 storage_ = Arrays::dense_ // always dense
140 };
142 Array2D(): Base() {}
146 Array2D( Range const& I, Range const& J): Base(I, J) {}
152 Array2D( Range const& I, Range const& J, Type const& v): Base(I, J)
158 Array2D( Array2D const& T, bool ref=false): Base(T, ref) {}
163 template<class OtherArray>
164 Array2D( IArray2D<OtherArray> const& T, Range const& I, Range const& J)
165 : Base(T, I, J) {}
169 template<class OtherDerived>
176 Array2D( Type** q, Range const& I, Range const& J): Base(q, I, J) {}
182 template<class Rhs>
187 Array2D& operator=( Array2D const& T) { return LowBase::assign(T);}
195 void shift1D(int beg)
196 { Base::shift(beg, beg);}
201 { Base::resize(I, I); return *this;}
205 void swapRows( int const& pos1, int const& pos2)
206 {
207#ifdef STK_BOUNDS_CHECK
208 // check conditions
209 if (this->beginRows() > pos1)
211 if (this->endRows() <= pos1)
213 if (this->beginRows() > pos2)
215 if (this->endRows() <= pos2)
217#endif
218 for (int j=this->beginCols(); j<this->endCols(); j++)
219 { std::swap(this->elt(pos1, j), this->elt(pos2, j));}
220 }
221};
222
223} // namespace STK
224
225#endif
226// STK_ARRAY2D_H
In this file we implement the modifiers of the IArray2D.
In this file we implement the slicing methods for IArray2D class.
Interface base class for the Array2D classes, this is an internal header file, included by other cont...
#define STKOUT_OF_RANGE_2ARG(Where, Arg1, Arg2, Error)
Definition STK_Macros.h:102
template two dimensional column (vertically) oriented Array.
IArray2D< Array2D< Type_ > > Base
Type for the Interface base Class.
Array2D & operator=(Type const &v)
set the container to a constant value.
Array2D(Array2D const &T, bool ref=false)
Copy constructor.
hidden::Traits< Array2D< Type_ > >::TypeConst TypeConst
hidden::Traits< Array2D< Type_ > >::Type Type
hidden::Traits< Array2D< Type_ > >::Col Col
Array2D & operator=(ExprBase< Rhs > const &T)
operator = : overwrite the Array2D with the right hand side T.
~Array2D()
destructor.
Array2D(Range const &I, Range const &J, Type const &v)
constructor with rows and columns ranges specified and initialization with a constant.
void swapRows(int const &pos1, int const &pos2)
Swapping the pos1 row and the pos2 row.
Array2D(Range const &I, Range const &J)
constructor
hidden::Traits< Array2D< Type_ > >::SubArray SubArray
hidden::Traits< Array2D< Type_ > >::SubVector SubVector
void shift1D(int beg)
New beginning index for the object.
Array2D(Type **q, Range const &I, Range const &J)
Wrapper constructor Contruct a reference container.
Array2D(ExprBase< OtherDerived > const &T)
Copy constructor using an expression.
ArrayBase< Array2D< Type_ > > LowBase
hidden::Traits< Array2D< Type_ > >::Row Row
Array2D & resize1D(Range const &I)
New size for the container.
Array2D()
Default constructor.
hidden::Traits< Array2D< Type_ > >::SubCol SubCol
hidden::Traits< Array2D< Type_ > >::SubRow SubRow
Array2D & operator=(Array2D const &T)
overwrite the Array2D with T.
Array2D(IArray2D< OtherArray > const &T, Range const &I, Range const &J)
Copy constructor by reference, ref_=1.
Array2D< Type_ > & operator=(Type const &value)
Array2D< Type_ > & setValue(TypeConst value)
set a value to this container.
Array2D< Type_ > & assign(ExprBase< Rhs > const &rhs)
template interface base class for two-dimensional arrays.
Array2D< Type_ > & resize(Range const &I, Range const &J)
resize the array.
void shift(int rbeg, int cbeg)
Set new beginning indexes to the array.
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< Real > ArrayXX
Specialization of the Array2D class for Real values.
Definition STK_Array2D.h:53
@ dense_
dense matrix/vector/array/expression
@ array2D_
general matrix/array/expression
@ by_col_
storage by column
const int UnknownSize
This value means that an integer is not known at compile-time, and that instead the value is stored i...
The namespace STK is the main domain space of the Statistical ToolKit project.
Array2D< int > ArrayXXi
Definition STK_Array2D.h:55
Array2D< double > ArrayXXd
Definition STK_Array2D.h:54
RemoveConst< Type >::Type const & TypeConst
Definition STK_Array2D.h:78
Array1D< Type, UnknownSize > ColVector
Definition STK_Array2D.h:88