36#ifndef STK_IARRAY2DMODIFIERS_H
37#define STK_IARRAY2DMODIFIERS_H
45template <
class Derived >
48 reserveCols(sizeCols);
49 reserveRows(sizeRows);
54template <
class Derived >
56{ reserveRowsCols(cols(), size);}
60template<
class Derived>
63 if (availableCols() >= sizeCols)
return;
70 Range J(this->beginCols(), sizeCols);
71 allocator_.realloc(
J);
72 rangeCols_.reserve(
J.size());
84template <
class Derived >
87 for (
int j=
J.begin();
j<
J.end();
j++)
88 { reserveRowCol(
j, size);}
94template <
class Derived >
97 if (this->capacityCol(col) >= size)
return;
98 allocator_.elt(col)->reserve(size);
106template <
class Derived >
115template <
class Derived >
117{ this->asDerived().shift1D(
beg);}
121template <
class Derived >
125 int inc =
beg - beginRows();
126 if (inc == 0)
return;
131 Base2D::shiftRows(
beg);
133 for (
int j=beginCols();
j<endCols();
j++)
134 { shiftRowCol(
j, rangeCols_[
j].begin()+inc);}
139template <
class Derived >
143 if (
cbeg == this->beginCols())
return;
148 allocator_.shift(
cbeg);
149 rangeCols_.shift(
cbeg);
150 Base2D::shiftCols(
cbeg);
158template <
class Derived >
161 if (allocator_.elt(col)) { allocator_.elt(col)->shift(
beg);}
162 rangeCols_[col].shift(
beg);
171template <
class Derived >
175 if ((this->rows() ==
I) && (this->cols() ==
J))
return this->asDerived();
179 shift(
I.begin(),
J.begin());
180 if ((this->rows() ==
I) && (this->cols() ==
J))
return this->asDerived();
182 if (
I.size()<=0 ||
J.size() <= 0)
183 { clear();
return this->asDerived();}
186 int rinc =
I.end() - endRows();
187 int cinc =
J.end() - endCols();
192 if (
rinc < 0) { popBackRows(-
rinc);}
193 else { pushBackRows(
rinc);}
199 if (
rinc < 0) { popBackRows(-
rinc);}
200 else { pushBackRows(
rinc);}
202 return this->asDerived();
207template <
class Derived >
209{
return this->asDerived().resize1D(
I);}
215template <
class Derived >
222 insertRows(beginRows(), n);
227template <
class Derived >
234 insertRows(endRows(), n);
239template <
class Derived >
245#ifdef STK_BOUNDS_CHECK
249 eraseRows(endRows()-n, n);
254template <
class Derived >
260#ifdef STK_BOUNDS_CHECK
264 eraseRows(endRows()-n, n);
271template <
class Derived >
278 this->asDerived() =
other.asDerived();
279 return this->asDerived();
286 pushFrontRows(
nbRow);
287 for (
int j=beginCols();
j< endCols(); ++
j)
293 return this->asDerived();
300template <
class Derived >
307 this->asDerived() =
other.asDerived();
308 return this->asDerived();
316 for (
int j=beginCols();
j< endCols(); ++
j)
323 return this->asDerived();
330template <
class Derived >
337 insertCols(beginCols(), n );
342template <
class Derived >
349 insertCols(endCols(), n );
354template <
class Derived >
360#ifdef STK_BOUNDS_CHECK
365 eraseCols(beginCols(), n);
370template <
class Derived >
376#ifdef STK_BOUNDS_CHECK
381 eraseCols(endCols()-n, n);
386template <
class Derived >
393 this->asDerived() =
other.asDerived();
394 return this->asDerived();
400 this->asDerived().insertCols(beginCols(), other.sizeCols());
401 for (
int j= beginCols(), j1= other.beginCols(); j < endCols(); ++j, ++j1)
403 *allocator_.elt(j) = other.col(j1);
406 return this->asDerived();
411template <
class Derived >
418 resize(
other.rows(),1);
420 (*
this)(
i, lastIdxCols()) =
other[
i];
421 return this->asDerived();
431 return this->asDerived();
439template <
class Derived >
446#ifdef STK_BOUNDS_CHECK
447 if (beginCols() > pos)
457 for (
int k=
OldRange.lastIdx(); k>=pos; k--)
458 { transferCol(k+n, k);}
460 nullCols(
Range(pos, n) );
461 initializeCols(
Range(pos, n) );
467template <
class Derived >
473#ifdef STK_BOUNDS_CHECK
474 if (beginCols() > pos)
476 if (endCols() <= pos)
478 if (endCols() < pos+n)
482 freeCols(
Range(pos, n));
484 this->decLastIdxCols(n);
485 rangeCols_.erase(pos, n);
486 allocator_.memmove(pos,
Range(pos+n, endCols()-pos));
488 if (sizeCols() == 0) { freeMem();}
498template <
class Derived >
504#ifdef STK_BOUNDS_CHECK
505 if (beginRows() > pos)
511 this->incLastIdxRows(n);
512 for (
int j=beginCols();
j<endCols();
j++)
514 if (!allocator_.elt(
j))
515 { initializeCol(
j, this->rangeRowsInCol(
j));}
518 if ( (pos >= rangeCols_[j].begin()) && (pos <= rangeCols_[j].end()))
519 { insertRowsCol(j, pos, n);}
527template <
class Derived >
534#ifdef STK_BOUNDS_CHECK
535 if (beginRows() > pos)
537 if (endRows() <= pos)
539 if (endRows() < pos+n)
543 for (
int j=beginCols();
j<endCols();
j++) { eraseRowsCol(
j, pos, n);}
544 this->decLastIdxRows(n);
551template <
class Derived >
555 insert(
Range(this->begin(), 1),
v);
560template <
class Derived >
564 this->asDerived().pushBack();
570template <
class Derived >
574 this->asDerived().insertElt(
I.begin(),
I.size());
575 for (
int i=
I.begin();
i<
I.end();
i++) { elt(
i) =
v;}
582template <
class Derived >
587 else { eraseCols(pos, n); }
600template <
class Derived >
603 if (rangeCols_[col] ==
I)
return;
604 shiftRowCol(col,
I.begin());
605 int inc = rangeCols_[col].size() -
I.size();
606 if (inc == 0)
return;
609 allocator_.elt(col)->pushBack(-inc);
610 rangeCols_[col].incLast(-inc);
614 rangeCols_[col].decLast(inc);
615 if (rangeCols_[col].size()==0) freeCol(col);
624template <
class Derived >
627 allocator_.elt(col)->insertElt(pos, n);
628 rangeCols_[col].incLast(n);
642template <
class Derived >
646 if (rangeCols_[col].lastIdx() < pos)
return;
647 if (rangeCols_[col].begin()> pos+n-1)
648 { shiftRowCol( col, rangeCols_[col].begin() - n);
return;}
653 if (
newRange == rangeCols_[col]) { freeCol(col);
return;}
657 rangeCols_[col].decLast(
newRange.size());
661 { shiftRowCol( col, rangeCols_[col].begin() - (n-
newRange.size()));}
#define STKOUT_OF_RANGE_1ARG(Where, Arg, Error)
#define STKRUNTIME_ERROR_1ARG(Where, Arg, Error)
#define STKOUT_OF_RANGE_2ARG(Where, Arg1, Arg2, Error)
#define STKRUNTIME_ERROR_NO_ARG(Where, Error)
#define STKRUNTIME_ERROR_2ARG(Where, Arg1, Arg2, Error)
#define STK_STATIC_ASSERT_ONE_DIMENSION_ONLY(EXPR)
Sdk class for all library Exceptions.
void shiftRowCol(int col, int beg)
internal method for translating a column.
void reserveRowsCols(Range const &J, int size)
Internal method for reserving memory in a range of columns.
void insertRowsCol(int col, int pos, int n)
Internal method for inserting rows to a specified column.
void reserveRows(int size)
Reserve a certain amount of rows in all columns.
void erase(int pos, int n=1)
STL compatibility:Delete n elements at the pos index from the container.
void pushFrontCols(int n=1)
Insert n columns at the beginning of the array.
void insertCols(int pos, int n=1)
Insert n columns at the index pos to the array.
Derived & resize(Range const &I, Range const &J)
resize the array.
void pushBackCols(int n=1)
Add n columns at the end of the array.
void resizeRowCol(int col, Range const &I)
Internal method for resizing a column with a specified range.
void reserve(int sizeRows, int sizeCols)
function for reserving memory in all the columns
void popBackCols(int n=1)
Delete last columns of the array.
void insert(Range const &I, Type const &v)
STL compatibility: insert element v in the range I of the Array.
void popFrontCols(int n=1)
Delete first columns of the array.
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.
void shiftCols(int cbeg)
New first index for the columns of the object.
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.
void pushFrontRows(int n=1)
Insert n rows in front of the array.
void reserveCols(int sizeCols)
Reserve a certain amount of columns.
void shift(int rbeg, int cbeg)
Set new beginning indexes to the array.
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 insertRows(int pos, int n=1)
Insert n rows at position pos in the array If pos is outside the range of a column,...
hidden::Traits< Derived >::Type Type
void eraseCols(int pos, int n=1)
Delete n columns at the specified position of the array.
String const & error() const
get the last error message.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
Index sub-vector region: Specialization when the size is unknown.
@ vector_
column oriented vector/array/expression
The namespace STK is the main domain space of the Statistical ToolKit project.
TRange< UnknownSize > Range