STK++ 0.9.13
STK_IArray2D.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
41#ifndef STK_IARRAY2D_H
42#define STK_IARRAY2D_H
43
44#include "STK_ArrayBase.h"
45#include "STK_IContainer2D.h"
46#include "STK_Array1D.h"
47
48namespace STK
49{
50
76template < class Derived>
77class IArray2D: protected IContainer2D<hidden::Traits<Derived>::sizeRows_, hidden::Traits<Derived>::sizeCols_>
78 , public ArrayBase<Derived>
79{
80 // needed by merge
81 template < class OtherDerived> friend class IArray2D;
82
83 public:
86
92 // for 1D container
94
96 typedef ColVector* PtrCol;
97 typedef ColVector const* PtrColConst;
98
99 enum
100 {
106 };
117
118 using Base::elt;
119 using Base2D::setCols;
120 using Base2D::setRows;
121
122 protected:
128 IArray2D( Range const& I, Range const& J);
141 IArray2D( IArray2D const& T, bool ref =false);
146 template<class OtherDerived>
147 IArray2D( IArray2D< OtherDerived> const& T, Range const& I, Range const& J);
152
153 public:
158 void clear();
163 Derived& move(Derived const& T);
168
169 // getters
171 inline bool isRef() const { return allocator_.isRef();}
173 inline RowRange const& rowsImpl() const { return Base2D::rows();}
175 inline ColRange const& colsImpl() const { return Base2D::cols();}
176
178 inline RowRange const& rows() const { return Base2D::rows();}
180 inline int beginRows() const { return Base2D::beginRows();}
182 inline int endRows() const { return Base2D::endRows();}
184 inline int sizeRows() const { return Base2D::sizeRows();}
185
187 inline ColRange const& cols() const { return Base2D::cols();}
189 inline int beginCols() const { return Base2D::beginCols();}
191 inline int endCols() const { return Base2D::endCols();}
193 inline int sizeCols() const { return Base2D::sizeCols();}
194
196 inline int lastIdxCols() const { return Base2D::lastIdxCols();}
198 inline int lastIdxRows() const { return Base2D::lastIdxRows();}
199
201 inline bool empty() const { return Base2D::empty();}
202
204 inline Allocator const& allocator() const { return allocator_;}
208 inline PtrColConst ptr(int j) const { return allocator_.elt(j);}
210 inline int availableCols() const { return allocator_.size();}
214 inline int capacityCol(int col) const { return ptr(col) ? ptr(col)->capacity() : 0;}
216 inline Array1D<Range, sizeCols_> const& rangeCols() const { return rangeCols_;}
220 inline Range const& rangeCol(int col) const { return rangeCols_[col];}
221
223 inline void setValueImpl( int j, TypeConst v)
224 {
226 this->asDerived().setValue1D(j, v);
227 }
229 inline void setValueImpl( int i, int j, TypeConst v) { allocator_.elt(j)->setValue(i, v);}
230
235 inline Type& elt2Impl( int i, int j) { return allocator_.elt(j)->elt(i);}
240 inline TypeConst elt2Impl( int i, int j) const { return ptr(j)->elt(i);}
241
242 // overloaded operators
246 inline TypeConst operator()(int i, int j) const
247 {
248#ifdef STK_BOUNDS_CHECK
249 if (beginRows() > i) { STKOUT_OF_RANGE_2ARG(IArray::elt, i, j, beginRows() > i);}
250 if (endRows() <= i) { STKOUT_OF_RANGE_2ARG(IArray::elt, i, j, endRows() <= i);}
251 if (beginCols() > j) { STKOUT_OF_RANGE_2ARG(IArray::elt, i, j, beginCols() > j);}
252 if (endCols() <= j) { STKOUT_OF_RANGE_2ARG(IArray::elt, i, j, endCols() <= j);}
253#endif
254 return elt(i,j);
255 }
259 inline Type& operator()(int i, int j)
260 {
261#ifdef STK_BOUNDS_CHECK
262 if (this->beginRows() > i) { STKOUT_OF_RANGE_2ARG(IArray2D::elt, i, j, beginRows() > i);}
263 if (this->endRows() <= i) { STKOUT_OF_RANGE_2ARG(IArray2D::elt, i, j, endRows() <= i);}
264 if (this->beginCols() > j) { STKOUT_OF_RANGE_2ARG(IArray2D::elt, i, j, beginCols() > j);}
265 if (this->endCols() <= j) { STKOUT_OF_RANGE_2ARG(IArray2D::elt, i, j, endCols() <= j);}
266#endif
267 return elt(i,j);
268 }
272 inline TypeConst operator[](int i) const
273 {
275#ifdef STK_BOUNDS_CHECK
276 if (this->asDerived().begin() > i) { STKOUT_OF_RANGE_1ARG(IArray2D::elt, i, begin() > i);}
277 if (this->asDerived().end() <= i) { STKOUT_OF_RANGE_1ARG(IArray2D::elt, i, end() <= i);}
278#endif
279 return elt(i);
280 }
284 inline Type& operator[](int i)
285 {
287#ifdef STK_BOUNDS_CHECK
288 if (this->asDerived().begin() > i) { STKOUT_OF_RANGE_1ARG(IArray2D::elt, i, begin() > i);}
289 if (this->asDerived().end() <= i) { STKOUT_OF_RANGE_1ARG(IArray2D::elt, i, end() <= i);}
290#endif
291 return elt(i);
292 }
294 inline TypeConst operator()() const { return elt();}
296 inline Type& operator()() { return elt();}
297
298 //slicing
303 Col col( int j) const;
309 SubCol col(Range const& I, int j) const;
314 SubArray col(Range const& J) const;
319 Row row( int i) const;
324 SubRow row(int i, Range const& J) const;
329 SubArray row(Range const& I) const;
333 SubVector sub(Range const& J) const;
337 SubArray sub(Range const& I, Range const& J) const;
338 // overloaded operators for sub-arrays/vectors
342 SubVector operator[](Range const& I) const;
347 SubCol operator()(Range const& I, int j) const;
352 SubRow operator()(int i, Range const& J) const;
356 SubArray operator()(Range const& I, Range const& J) const;
360 SubCol atCol(int j) const;
364 Row atRow(int i) const;
365
366 // modifiers
370 void reserve(int sizeRows, int sizeCols);
374 void reserveRows(int size);
378 void reserveCols(int sizeCols);
379
383 void shift( int rbeg, int cbeg);
387 void shift( int beg);
391 void shiftRows( int beg);
395 void shiftCols(int cbeg);
396
404 Derived& resize( Range const& I, Range const& J);
408 Derived& resize( Range const& I);
409
410 // rows
417 void insertRows(int pos, int n =1);
422 void eraseRows(int pos, int n=1);
426 void pushFrontRows(int n =1);
430 void pushBackRows( int n=1);
434 void popFrontRows( int n = 1);
438 void popBackRows( int n = 1);
444 template<class Other>
445 Derived& pushFrontRows(ExprBase<Other> const& other);
451 template<class Other>
452 Derived& pushBackRows(ExprBase<Other> const& other);
453 // columns modifiers
458 void insertCols(int pos, int n =1);
463 void eraseCols(int pos, int n = 1);
467 void pushFrontCols(int n =1);
471 void pushBackCols(int n = 1);
475 void popFrontCols( int n =1);
479 void popBackCols( int n =1);
483 template<class Other>
484 Derived& pushFrontCols(ExprBase<Other> const& other);
488 template<class Other>
489 Derived& pushBackCols(IArray1D<Other> const& other);
490
491 // modifiers, STL compatibility: for one dimension containers
495 void push_front(Type const& v);
499 void push_back(Type const& v);
503 void insert( Range const& I, Type const& v);
508 void erase(int pos, int n=1);
509
510 // Useful
514 void swapCols(int pos1, int pos2)
515 {
516 #ifdef STK_BOUNDS_CHECK
517 if (this->beginCols() > pos1)
519 if (this->endCols() <= pos1)
521 if (this->beginCols() > pos2)
523 if (this->endCols() <= pos2)
525 #endif
527 rangeCols_.swap(pos1,pos2);
528 }
532 void swap(int i, int j)
533 {
535 std::swap(elt(i), elt(j));
536 }
547 template<class OtherDerived>
549 {
550 //checks
551 if (isRef())
552 { STKRUNTIME_ERROR_NO_ARG(IArray2D::merge(other),*this is a reference.);}
553 if (other.isRef())
555 // if there is no columns, we can safely modify the vertical range
556 if (this->sizeCols() <= 0) setRows(other.rows());
557 if (this->rows() != other.rows())
558 { STKRUNTIME_ERROR_NO_ARG(IArray2D::merge(other),this->rows() != other.rows());}
559
560 // break const reference
562 // compute horizontal range of the container after insertion
563 Range cols(this->cols());
564
565 // save first index of the first column added before modification of cols
566 const int first = cols.end();
567 // reallocate memory for the columns
568 cols.incLast(Tref.sizeCols());
570
571 // copy data from other
572 Tref.shiftCols(first); // easiest like that
573 for (int j=first; j< cols.end(); j++)
574 { transferCol(Tref, j);}
575
576 // delete and set view on the data
577 Tref.allocator().free();
578 Tref.allocator().setPtr(allocator_.p_data(), Tref.cols(), true);
579 }
586 template<class OtherDerived>
588 {
589 // checks
590 if (isRef())
591 { STKRUNTIME_ERROR_NO_ARG(IArray2D::merge(IArray1D),*this is a reference.);}
592 if (other.isRef())
594 // if there is no columns, we can safely modify the vertical range
595 if (this->sizeCols() <= 0) setRows(other.range());
596 if (this->rows() != other.range())
597 { STKRUNTIME_ERROR_NO_ARG(IArray2D::merge(IArray1D),this->rows() != other.range());}
598
599 // compute horizontal range of the container after insertion
600 Range cols(this->cols());
601
602 // reallocate memory for the columns
603 cols.incLast(1);
605
606 // set column
607 allocator_.elt(cols.lastIdx()) = const_cast<OtherDerived*>(other.asPtrDerived());
608 rangeCols_[cols.lastIdx()] = other.range();
609
610 // set other as reference
611 other.setRef(true);
612 }
616 void update(Range const& J)
617 {
618 #ifdef STK_BOUNDS_CHECK
619 if (beginCols() > J.begin())
621 if (endCols() < J.end())
623 #endif
624 for ( int icol = J.begin(); icol < J.end() ; ++icol)
625 { update(icol);}
626 }
630 void update(int col)
631 {
632 #ifdef STK_BOUNDS_CHECK
633 if (beginCols() > col)
635 if (this->lastIdxCols() < col)
637 #endif
638 if (this->rangeRowsInCol(col) != rangeCols_[col])
639 { resizeRowCol(col, this->rangeRowsInCol(col));}
640 }
641
642 protected:
647
649 inline Allocator& allocator() { return allocator_;}
650
654 void transferCol( int pos1, int pos2)
655 {
656 // copy by address pointer on column pos2 of T in pos1 of this
659 }
666 void reallocCols(Range const& J);
667
672 void nullCols(ColRange const& J);
673
674 private:
681 void freeMem();
690 void mallocCols(ColRange const& J);
695 void initializeCols(Range const& J);
699 void freeCols(Range const& J);
704 void reserveRowsCols(Range const& J, int size);
705 // single column methods
710 void copyCol(IArray2D const& src, int j);
719 template<class OtherDerived>
721 {
722 allocator_.elt(pos) = T.allocator_.elt(pos);
723 rangeCols_[pos] = T.rangeCols_[pos];
724 T.nullCol(pos);
725 }
730 void nullCol(int col);
735 void initializeCol(int col, Range const& I);
739 void freeCol(int col);
740 // modifiers
747 void shiftRowCol( int col, int beg);
756 void resizeRowCol( int col, Range const& I);
761 void reserveRowCol( int col, int size);
768 void insertRowsCol( int col, int pos, int n);
781 void eraseRowsCol( int col, int pos, int n);
782};
783
784/* Default constructor */
785template < class Derived >
787 , allocator_()
788 , rangeCols_()
789{ mallocCols(this->cols());}
793template < class Derived >
795 : Base2D(I,J), Base()
796 , allocator_()
797 , rangeCols_()
798{ mallocCols(this->cols()); initializeCols(J);}
799/* Copy constructor
800 * @param T the array to copy
801 * @param ref true if we wrap T
802 **/
803template < class Derived >
805 : Base2D(T), Base()
806 , allocator_(T.allocator_, ref)
807 , rangeCols_(T.rangeCols_, false) // have to be created again, in case T is a temporary
808{
809 if (!ref)
810 {
811 initializeCols(T.cols()); // initialize the Columns
812 for (int j=T.beginCols(); j<T.endCols(); j++)
813 { copyCol(T, j);}
814 }
815}
816/* constructor by reference, ref_=1.
817 * @param T the array to copy
818 * @param I,J ranges of the rows and columns to wrap
819 **/
820template < class Derived >
821template<class OtherDerived>
823 : Base2D(I,J), Base()
824 , allocator_(T.allocator_, J, true) // a reference
825 , rangeCols_(T.rangeCols_, J, false) // have to be created again, in case T is a temporary
826 // T.rangeCols_ is itself a temporary that will be deleted
827 // Tref(T.sub(J), true) for example
828{
829 for (int j=J.begin(); j<J.end(); j++)
830 { rangeCols_[j] = inf(I, T.rangeCols()[j]);}
831}
832/* destructor.
833 * free the vertically allocated memory (the columns). The horizontally
834 * allocated memory is handled by the Allocator class.
835 **/
836template < class Derived >
837IArray2D<Derived>::~IArray2D() { if (!isRef()) freeCols(cols());}
838
839/* clear the object.
840 * This will free all allocated memory and reset all range to Range().
841 * (while freeMem() does not modify rows range (rows_)
842 **/
843template < class Derived >
845{
846 // Nothing to do for reference
847 if (isRef()) return;
848 freeMem();
849 this->setRanges();
850}
851/* move T to this.
852 * @note : T is not modified but just set as a reference of the data it was responsible.
853 * @param T the array to move.
854 **/
855template < class Derived >
856Derived& IArray2D<Derived>::move(Derived const& T)
857{
858 if (this->asPtrDerived() == &T) return this->asDerived();
859 if (!isRef()) { freeCols(cols());}
860 // move Base part
861 allocator_.move(T.allocator_); // T become a reference
862 rangeCols_.move(T.rangeCols_);
863 // Set IContainer2D part
864 setCols(T.cols());
865 setRows(T.rows());
866 return this->asDerived();
867}
868/* exchange this container with T.
869 * @param T the container to exchange with this
870 **/
871template < class Derived >
873{
874 // swap MemAllocator part
875 allocator_.exchange(T.allocator_);
876 Base2D::exchange(T);
877 rangeCols_.exchange(T.rangeCols_);
878}
879
880/* @brief Internal method for memory deallocation.
881 * This method clear all allocated memory and reset ranges to default value.
882 * Do nothing if this is a reference
883 * Range of the columns is set to default.
884 * Range of the rows (rows_) remains unmodified.
885 **/
886template< class Derived>
888{
889 if (isRef()) return;
890 freeCols(cols());
891 // free memory allocated in allocator.
892 // For fixed size arrays, the size remain the same
893 allocator_.free();
894 setCols(allocator_.range());
895 // clear arrays
896 rangeCols_.resize(cols());
897}
898/* Method for memory allocation and initialization of the horizontal
899 * range of the container.
900 * The vertical range is not set in this method. If an
901 * error occur, we set the cols_ of the container to default.
902 * @param J horizontal range
903 **/
904template< class Derived>
906{
907 // try to allocate memory
908 try
909 {
910 if (J.size() > availableCols())
911 {
912 // compute the necessary size
913 int size= Arrays::evalSizeCapacity(J.size());
914 allocator_.malloc(Range(J.begin(), size)); // allocate memory for the columns
915 }
916 else
917 { allocator_.shift(J.begin());}
918 rangeCols_.resize(J);
919 }
920 catch (Exception const& error) // if an error occur
921 {
922 Base2D::setCols(); // set default range
923 rangeCols_.clear(); // clear this->rangeCols_
924 allocator_.free(); // initialize with zero
925 allocator_.setValue(0); // initialize with zero
926 throw error; // throw the error
927 }
928 allocator_.setValue(0); // initialize with zero
929}
930/* @brief Internal method for memory allocation and initialization of a range of columns.
931 * The capacity for the rows have to be set before calling this method.
932 * @param J vertical range of the Columns to initialize
933 **/
934template< class Derived>
936{
937#ifdef STK_BOUNDS_CHECK
938if (beginCols() > J.begin())
939{ STKOUT_OF_RANGE_1ARG(IArray2D::initializeCols, J, beginCols() > J.begin());}
940if (endCols() < J.end())
941{ STKOUT_OF_RANGE_1ARG(IArray2D::initializeCols, J, endCols() < J.end());}
942#endif
943 for (int j=J.begin(); j<J.end(); j++)
944 {
945 try
946 { initializeCol(j, this->rangeRowsInCol(j));}
947 catch (Exception const& error) // if an error occur
948 {
949 // free each column allocated and throw exception
950 for (int k=J.begin(); k<j; k++) freeCol(k);
951 throw error;
952 }
953 }
954}
955/* @brief Internal method for releasing memory in a given range of columns.
956 * @param J range of columns to liberate.
957 **/
958template< class Derived>
960{ for (int j=J.begin(); j<J.end(); j++) { freeCol(j);}}
961/* copy column j of src into column j of this
962 * @param src source to copy
963 * @param j index of the columns to copy
964 **/
965template< class Derived>
967{
968 PtrCol dp =allocator_.elt(j), sp =src.allocator_.elt(j);
969 dp->assign(*sp);
970}
971
972/* Method for memory reallocation and initialization of the horizontal
973 * range of the container.
974 * The vertical range is not set in this method. If an
975 * error occur, we set the cols_ of the container to default.
976 * @param J horizontal range
977 **/
978template< class Derived>
980{
981 Range oldRange(cols());
982 // try to allocate memory
983 if (J.size() > availableCols())
984 {
985 int size= Arrays::evalSizeCapacity(J.size());
986 Range newRange(J.begin(), size);
987 allocator_.realloc( newRange ); // reallocate memory for the columns
988 }
989 rangeCols_.resize(J); // initialize this->rangeCols_
990 setCols(J);
991}
992
993/* Internal method for initializing to default values (null pointer and null range)
994 * to a range of columns.
995 * @param J horizontal range
996 **/
997template< class Derived>
999{
1000#ifdef STK_BOUNDS_CHECK
1001 if (beginCols() > J.begin())
1002 { STKOUT_OF_RANGE_1ARG(IArray2D::nullCols, J, beginCols() > J.begin());}
1003 if (endCols() < J.end())
1004 { STKOUT_OF_RANGE_1ARG(IArray2D::nullCols, J, endCols() < J.end());}
1005#endif
1006 for (int j=J.begin(); j<J.end(); ++j) { nullCol(j);}
1007}
1008/* Internal method setting default parameters and dimension to a column of the container.
1009 * @param col the position of the column to initialize to a default value.
1010 * @note if data is allocated, it will be lost
1011 **/
1012template< class Derived>
1014{
1015 allocator_.elt(col) = 0;
1016 rangeCols_[col] = Range();
1017}
1018
1019/* @brief Internal method for initializing a column.
1020 * Method for the the allocation of memory of the column col with range I.
1021 * @param col,I index and range of the column to initialize
1022 **/
1023template< class Derived>
1025{
1026#ifdef STK_DEBUG_ARRAY2D
1027 stk_cout << _T("Entering initializeCol\n");
1028 stk_cout << _T("Initialize col=") << col <<_T(", I=") << I <<_T("\n");
1029#endif
1030 if (I.size() <=0)
1031 {
1032 allocator_.elt(col) = 0;
1033 rangeCols_[col] = I;
1034 return;
1035 }
1036 // try to allocate memory
1037 try
1038 { allocator_.elt(col) = new ColVector(I);}
1039 catch (std::bad_alloc & error) // if an alloc error occur
1040 {
1041 allocator_.elt(col) = 0;
1042 rangeCols_[col] = Range();
1044 }
1045 rangeCols_[col] = I;
1046}
1047/* @brief Internal method for memory deallocation.
1048 * @param col the number of the column to free
1049 **/
1050template< class Derived>
1052{
1053#ifdef STK_DEBUG_ARRAY2D
1054 stk_cout << _T("Entering freeCol\n");
1055 stk_cout << _T("Deleting col=") << col <<_T(", rangeCols_[col]=") << rangeCols_[col] <<_T("\n");
1056 stk_cout << _T("allocator_.elt(col)=") << allocator_.elt(col) <<_T("\n");
1057#endif
1058 if (allocator_.elt(col)) // if there is a column at this position
1059 {
1060 delete allocator_.elt(col);
1061 allocator_.elt(col) =0;
1062 rangeCols_[col] = Range();
1063 }
1064}
1065
1066} // namespace STK
1067
1068#endif
1069// STK_IARRAY2D_H
In this file we define and implement the final class Array1D.
In this file we define the base class for Arrays.
In this file we define the IContainer2D interface classes.
#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 STKRUNTIME_ERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:138
#define STKRUNTIME_ERROR_2ARG(Where, Arg1, Arg2, Error)
Definition STK_Macros.h:120
#define STK_STATIC_ASSERT_ONE_DIMENSION_ONLY(EXPR)
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
base class for template arrays.
Sdk class for all library Exceptions.
template one dimensional Array.
template interface base class for two-dimensional arrays.
int sizeRows() const
IArray2D(Range const &I, Range const &J)
constructor with specified ranges
void shiftRowCol(int col, int beg)
internal method for translating a column.
ColRange const & colsImpl() const
Array1D< Range, sizeCols_ > rangeCols_
range of the index of the columns of the container.
int beginRows() const
void mallocCols(ColRange const &J)
Internal method for memory allocation and initialization of the horizontal range of the container.
void nullCols(ColRange const &J)
Internal method for initializing to default values (null pointer and null range) to a range of column...
TypeConst operator()(int i, int j) const
void reserveRowsCols(Range const &J, int size)
Internal method for reserving memory in a range of columns.
friend class IArray2D
void reallocCols(Range const &J)
Method for memory reallocation and initialization of the horizontal range of the container.
void setRows(RowRange const &I=RowRange())
Set the range of the number of rows.
hidden::Traits< Derived >::SubCol SubCol
RowRange const & rowsImpl() const
Type & elt2Impl(int i, int j)
access to an element.
TypeConst operator[](int i) const
void insertRowsCol(int col, int pos, int n)
Internal method for inserting rows to a specified column.
int capacityCol(int col) const
void swap(int i, int j)
swap two elements: only for vectors and points
void exchange(IArray2D &T)
exchange this container with T.
void initializeCol(int col, Range const &I)
Internal method for initializing a column.
int lastIdxCols() const
void reserveRows(int size)
Reserve a certain amount of rows in all columns.
SubVector sub(Range const &J) const
void erase(int pos, int n=1)
STL compatibility:Delete n elements at the pos index from the container.
RowRange const & rows() const
SubCol atCol(int j) const
void nullCol(int col)
Internal method setting default parameters and dimension to a column of the container.
void pushFrontCols(int n=1)
Insert n columns at the beginning of the array.
Row atRow(int i) const
hidden::Traits< Derived >::Col Col
int endRows() const
bool isRef() const
void transferCol(int pos1, int pos2)
Transfer the column pos2 to the column pos1 of this.
TypeConst operator()() const
IArray2D(IArray2D< OtherDerived > const &T, Range const &I, Range const &J)
constructor by reference, ref_=1.
~IArray2D()
destructor.
Allocator allocator_
allocator of the column data set
void insertCols(int pos, int n=1)
Insert n columns at the index pos to the array.
IContainer2D< sizeRows_, sizeCols_ > Base2D
Type for the IContainer2D base Class.
hidden::Traits< Derived >::Row Row
void setValueImpl(int j, TypeConst v)
implement setValue for vector/point/diagonal arrays
Derived & resize(Range const &I, Range const &J)
resize the array.
hidden::Traits< Derived >::ColVector ColVector
void pushBackCols(int n=1)
Add n columns at the end of the array.
Allocator & allocator()
void merge(IArray2D< OtherDerived > const &other)
Append the container other to this without copying the data explicitly.
int lastIdxRows() const
Derived & move(Derived const &T)
move T to this.
void resizeRowCol(int col, Range const &I)
Internal method for resizing a column with a specified range.
void swapCols(int pos1, int pos2)
Swapping two columns.
void reserve(int sizeRows, int sizeCols)
function for reserving memory in all the columns
int endCols() const
void transferCol(IArray2D< OtherDerived > &T, int pos)
Internal method transferring column pos of container T to column pos of this.
hidden::Traits< Derived >::TypeConst TypeConst
void initializeCols(Range const &J)
Internal method for memory allocation and initialization of a range of columns.
void popBackCols(int n=1)
Delete last columns of the array.
ColVector const * PtrColConst
void insert(Range const &I, Type const &v)
STL compatibility: insert element v in the range I of the Array.
hidden::Traits< Derived >::SubVector SubVector
Allocator const & allocator() const
void popFrontCols(int n=1)
Delete first columns of the array.
Type & operator()()
int availableCols() const
void update(Range const &J)
Update columns of the array at a specified range.
void freeCol(int col)
Internal method for memory deallocation.
IArray2D()
Default constructor.
void pushBackRows(int n=1)
Add n rows to the array.
void reserveRowCol(int col, int size)
Internal method for reserving rows to a specified column.
void push_back(Type const &v)
STL compatibility: append an element v.
Col col(int j) const
access to a part of a column.
void merge(IArray1D< OtherDerived > const &other)
Append the vector other to this without copying the data explicitly.
Type & operator()(int i, int j)
void shiftCols(int cbeg)
New first index for the columns of the object.
Type & operator[](int i)
void clear()
clear the object.
int sizeCols() const
ColRange const & cols() const
Row row(int i) const
access to a part of a row.
void eraseRows(int pos, int n=1)
Delete n rows at the position pos.
void popBackRows(int n=1)
Delete n latest rows of the array.
int beginCols() const
void freeMem()
Internal method for memory deallocation.
PtrColConst ptr(int j) const
void pushFrontRows(int n=1)
Insert n rows in front of the array.
hidden::Traits< Derived >::SubRow SubRow
Range const & rangeCol(int col) const
ColVector * PtrCol
TRange< sizeCols_ > ColRange
Type of the Range for the columns.
Array1D< Range, sizeCols_ > const & rangeCols() const
void reserveCols(int sizeCols)
Reserve a certain amount of columns.
void shift(int rbeg, int cbeg)
Set new beginning indexes to the array.
MemAllocator< PtrCol, sizeCols_ > Allocator
Type for the Base Class.
void shiftRows(int beg)
New first index for the rows of the array.
void eraseRowsCol(int col, int pos, int n)
Internal method for deleting rows from a specified column.
void push_front(Type const &v)
STL compatibility: push front an element.
void popFrontRows(int n=1)
Delete n first rows of the array.
void setValueImpl(int i, int j, TypeConst v)
implement setValue for vector/point/diagonal arrays
void insertRows(int pos, int n=1)
Insert n rows at position pos in the array If pos is outside the range of a column,...
ArrayBase< Derived > Base
type of the Base Container Class.
hidden::Traits< Derived >::Type Type
void copyCol(IArray2D const &src, int j)
copy column j of src into column j of this
IArray2D(IArray2D const &T, bool ref=false)
Copy constructor If we want to wrap T, the main ptr will be wrapped in MemAllocator class.
void update(int col)
Update column of the array at specified position.
void freeCols(Range const &J)
Internal method for releasing memory in a given range of columns.
TRange< sizeRows_ > RowRange
Type of the Range for the rows.
void eraseCols(int pos, int n=1)
Delete n columns at the specified position of the array.
hidden::Traits< Derived >::SubArray SubArray
bool empty() const
TypeConst elt2Impl(int i, int j) const
constant access to an element.
Interface base class for 2D containers.
int lastIdxCols() const
void setRows(RowRange const &I=RowRange())
Set the range of the number of rows.
int lastIdxRows() const
RowRange const & rows() const
ColRange const & cols() const
void setCols(ColRange const &J=ColRange())
Set the columns range.
String const & error() const
get the last error message.
Definition STK_IRunner.h:82
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
TRange & incLast(int inc=1)
create the TRange [begin_, end_+inc)
Definition STK_Range.h:349
TRange & incLast(int inc=1)
create the TRange [begin_, end_+inc)
Definition STK_Range.h:242
int end() const
get the ending index of the TRange.
Definition STK_Range.h:192
int lastIdx() const
get the last index of the TRange.
Definition STK_Range.h:206
int evalSizeCapacity(int m)
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.
TRange< UnknownSize > Range
Definition STK_Range.h:59
Type *const & p_data() const
Get constant pointer on data.
void swap(int pos1, int pos2)
swap two elements of the Allocator.
TypeConst elt(int pos) const
Get the const element number pos.