STK++ 0.9.13
STK_IArray2DSlicers.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: Define the Interface for the Array classes.
28 * Author: Serge Iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 *
30 **/
31
36#ifndef STK_IARRAY2DSLICERS_H
37#define STK_IARRAY2DSLICERS_H
38
39namespace STK
40{
41
42/*access to a part of a column.
43 * @param j index of the column
44 * @return a reference in the range I of the column j of this
45 **/
46template < class Derived >
48{
49#ifdef STK_BOUNDS_CHECK
50 if (beginCols() > j) { STKOUT_OF_RANGE_1ARG(IArray::elt, j, beginCols() > j);}
51 if (endCols() <= j) { STKOUT_OF_RANGE_1ARG(IArray::elt, j, endCols() <= j);}
52#endif
53 return Col( this->asDerived(), this->rangeRowsInCol(j), j);
54}
55/*access to a part of a column.
56 * @param I range of the rows
57 * @param j index of the col
58 * @return a reference in the range I of the column j of this
59 **/
60template < class Derived >
62{
63#ifdef STK_BOUNDS_CHECK
64 if (beginRows() > I.begin()) { STKOUT_OF_RANGE_2ARG(IArray::col, I, j, beginRows() > I.begin());}
65 if (endRows() < I.end()) { STKOUT_OF_RANGE_2ARG(IArray::col, I, j, endRows() <= I.end());}
66 if (beginCols() > j) { STKOUT_OF_RANGE_2ARG(IArray::col, I, j, beginCols() > j);}
67 if (endCols() <= j) { STKOUT_OF_RANGE_2ARG(IArray::col, I, j, endCols() <= j);}
68#endif
69 return SubCol( this->asDerived(), inf(I, this->rangeRowsInCol(j)), j);
70}
71/*access to many columns.
72 * @param J range of the index of the cols
73 * @return a 2D array containing the Container in the Horizontal range @c J
74 **/
75template < class Derived >
77{ return SubArray( this->asDerived(), this->rows(), J);}
78
79/*access to a part of a row.
80 * @param i index of the row
81 * @return a reference of the row i.
82 **/
83template < class Derived >
85{ return Row( this->asDerived(), this->rangeColsInRow(i), i);}
86/*access to a part of a row.
87 * @param i index of the row
88 * @param J range of the columns
89 * @return a reference of the row i.
90 **/
91template < class Derived >
93{ return SubRow( this->asDerived(), inf(J, this->rangeColsInRow(i)), i);}
94/*access to many rows.
95 * @param I range of the index of the rows
96 * @return a 2D array containing the Container in the vertical range @c I
97 **/
98template < class Derived >
100{ return SubArray(this->asDerived(), I, cols());}
101
102/*@return many elements.
103 * @param J Range of the elements
104 **/
105template < class Derived >
107{ return SubVector(this->asDerived(), J);}
108/*access to a sub-array.
109 * @param I,J range of the rows and of the columns
110 **/
111template < class Derived >
113{ return SubArray(this->asDerived(), I, J);}
114
115// overloaded operators for sub-arrays/vectors
116/*@return the sub-vector in given range
117 * @param I range to get
118 **/
119template < class Derived >
121{
123 return sub(I);
124}
125/*@param I range of the index of the rows
126 * @param j index of the column
127 * @return a Vertical container containing the column @c j of this
128 * in the range @c I
129 **/
130template < class Derived >
132{
133#ifdef STK_BOUNDS_CHECK
134 if (beginRows() > I.begin()) { STKOUT_OF_RANGE_2ARG(IArray::operator(), I, j, beginRows() > I.begin());}
135 if (endRows() < I.end()) { STKOUT_OF_RANGE_2ARG(IArray::operator(), I, j, endRows() < I.end());}
136 if (beginCols() > j) { STKOUT_OF_RANGE_2ARG(IArrayBase::operator(), I, j, beginCols() > j);}
137 if (endCols() <= j) { STKOUT_OF_RANGE_2ARG(IArrayBase::operator(), I, j, endCols() < j);}
138#endif
139 return col(I, j);
140}
141/*@param i index of the row
142 * @param J range of the columns
143 * @return an Horizontal container containing the row @c i of this
144 * in the range @c J
145 **/
146template < class Derived >
147inline typename hidden::Traits<Derived>::SubRow IArray2D<Derived>::operator()(int i, Range const& J) const { return this->row(i, J);}
148/*@param I,J range of the rows and of the columns
149 * @return a 2D container containing this in the range @c I, @c J
150 **/
151template < class Derived >
152inline typename hidden::Traits<Derived>:: SubArray IArray2D<Derived>::operator()(Range const& I, Range const& J) const
153{ return sub(I, J);}
154
155/*@return the column j.
156 * @param j index of the column
157 **/
158template < class Derived >
160{
161 if (this->beginCols() > j) { STKOUT_OF_RANGE_1ARG(IArray2D::atCol, j, beginCols() > j);}
162 if (this->endCols() <= j) { STKOUT_OF_RANGE_1ARG(IArray2D::atCol, j, endCols() <= j);}
163 return col(j);
164}
165/*@return the row i.
166 * @param i the index of the row
167 **/
168template < class Derived >
170{
171 if (this->beginRows() > i) { STKOUT_OF_RANGE_1ARG(IArray2D::atRow, i, beginRows() > i);}
172 if (this->endRows() <= i) { STKOUT_OF_RANGE_1ARG(IArray2D::at, i, lastIdxRows() < i);}
173 return row(i);
174}
175
176
177} // namespace STK
178
179#endif
180// STK_IARRAY2DSLICERS_H
#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
#define STK_STATIC_ASSERT_ONE_DIMENSION_ONLY(EXPR)
hidden::Traits< Derived >::SubCol SubCol
TypeConst operator[](int i) const
SubVector sub(Range const &J) const
SubCol atCol(int j) const
Row atRow(int i) const
hidden::Traits< Derived >::Col Col
TypeConst operator()() const
hidden::Traits< Derived >::Row Row
hidden::Traits< Derived >::SubVector SubVector
Col col(int j) const
access to a part of a column.
Row row(int i) const
access to a part of a row.
hidden::Traits< Derived >::SubRow SubRow
hidden::Traits< Derived >::SubArray SubArray
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
Range inf(TRange< SizeI_ > const &I, TRange< SizeJ_ > const &J)
compute inf(I,J).
Definition STK_Range.h:477
The namespace STK is the main domain space of the Statistical ToolKit project.