STK++ 0.9.13
STK_SArray2D.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_SARRAY2D_H
35#define STK_SARRAY2D_H
36
37#include "STK_SArray1D.h"
38
39#include "STK_IArray2D.h"
40#include "STK_IArray2DSlicers.h"
42
43namespace STK
44{
45// forward declaration
46template< typename Type> class SArray2D;
47template< typename Type> class SArray2DNumber;
48template< typename Type> class SArray2DPoint;
49template< typename Type> class SArray2DVector;
50
58
59
60namespace hidden
61{
65template<class Type_>
66struct Traits< SArray2D<Type_> >
67{
68 private:
69 class Void {};
70 public:
77 typedef Void SubVector;
78
79 typedef Type_ Type;
80 typedef typename RemoveConst<Type>::Type const& TypeConst;
81
82 enum
83 {
84 structure_ = Arrays::array2D_,
85 orient_ = Arrays::by_col_,
86 sizeRows_ = UnknownSize,
87 sizeCols_ = UnknownSize,
88 storage_ = Arrays::sparse_ // always dense
89 };
91};
92
93} // namespace hidden
94
117template<class Type_ >
118class SArray2D: public IArray2D< SArray2D<Type_> >
119{
120 public:
124
131
134
135 enum
136 {
141 storage_ = Arrays::dense_ // always dense
142 };
148 SArray2D( Range const& I, Range const& J): Base(I, J) {}
154 SArray2D( Range const& I, Range const& J, Type const& v): Base(I, J)
160 SArray2D( SArray2D const& T, bool ref=false): Base(T, ref) {}
165 template<class OtherArray>
166 SArray2D( IArray2D<OtherArray> const& T, Range const& I, Range const& J)
167 : Base(T, I, J) {}
171 template<class OtherDerived>
178 SArray2D( Type** q, Range const& I, Range const& J): Base(q, I, J) {}
184 template<class Rhs>
189 SArray2D& operator=( SArray2D const& T) { return LowBase::assign(T);}
197 void shift1D(int beg)
198 { Base::shift(beg, beg);}
203 { Base::resize(I, I); return *this;}
207 void swapRows( int const& pos1, int const& pos2)
208 {
209#ifdef STK_BOUNDS_CHECK
210 // check conditions
211 if (this->beginRows() > pos1)
213 if (this->endRows() <= pos1)
215 if (this->beginRows() > pos2)
217 if (this->endRows() <= pos2)
219#endif
220 for (int j=this->beginCols(); j<this->endCols(); j++)
221 { std::swap(this->elt(pos1, j), this->elt(pos2, j));}
222 }
223};
224
225} // namespace STK
226
227#endif
228// STK_SARRAY2D_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
In this file we define and implement the final class SArray1D.
SArray2D< Type_ > & operator=(Type const &value)
SArray2D< Type_ > & setValue(TypeConst value)
set a value to this container.
SArray2D< Type_ > & assign(ExprBase< Rhs > const &rhs)
template interface base class for two-dimensional arrays.
SArray2D< 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...
template sparse two dimensional column (vertically) oriented Array.
hidden::Traits< SArray2D< Type_ > >::SubCol SubCol
SArray2D & operator=(Type const &v)
set the container to a constant value.
SArray2D(ExprBase< OtherDerived > const &T)
Copy constructor using an expression.
ArrayBase< SArray2D< Type_ > > LowBase
~SArray2D()
destructor.
hidden::Traits< SArray2D< Type_ > >::Row Row
hidden::Traits< SArray2D< Type_ > >::SubArray SubArray
SArray2D & operator=(SArray2D const &T)
overwrite the SArray2D with T.
hidden::Traits< SArray2D< Type_ > >::SubRow SubRow
void shift1D(int beg)
New beginning index for the object.
SArray2D(Range const &I, Range const &J, Type const &v)
constructor with rows and columns ranges specified and initialization with a constant.
SArray2D(SArray2D const &T, bool ref=false)
Copy constructor.
SArray2D(Type **q, Range const &I, Range const &J)
Wrapper constructor Contruct a reference container.
void swapRows(int const &pos1, int const &pos2)
Swapping the pos1 row and the pos2 row.
SArray2D(Range const &I, Range const &J)
constructor
hidden::Traits< SArray2D< Type_ > >::TypeConst TypeConst
IArray2D< SArray2D< Type_ > > Base
Type for the Interface base Class.
SArray2D()
Default constructor.
hidden::Traits< SArray2D< Type_ > >::Type Type
SArray2D(IArray2D< OtherArray > const &T, Range const &I, Range const &J)
Copy constructor by reference, ref_=1.
SArray2D & operator=(ExprBase< Rhs > const &T)
operator = : overwrite the SArray2D with the right hand side T.
hidden::Traits< SArray2D< Type_ > >::Col Col
SArray2D & resize1D(Range const &I)
New size for the container.
hidden::Traits< SArray2D< Type_ > >::SubVector SubVector
Index sub-vector region: Specialization when the size is unknown.
Definition STK_Range.h:265
SArray2D< Real > SArrayXX
Specialization of the SArray2D class for Real values.
@ sparse_
sparse matrix/vector/array/expression
@ 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.
SArray2D< double > SArrayXXd
SArray2D< int > SArrayXXi
SArray1D< Type, UnknownSize, UnknownSize > ColVector
RemoveConst< Type >::Type const & TypeConst