22 struct array:Map< Array<Type,Dynamic,1> >{
24 typedef Array<Type,Dynamic,1> Base;
25 typedef Map< Base > MapBase;
41 mult.resize(dim.size());
43 for(
int k=1;k<dim.size();k++){
44 mult[k]=mult[k-1]*dim[k-1];
48 vectorcopy.resize(dim_.prod());
50 if (vectorcopy.size() > 0) {
51 new (
this) MapBase(&vectorcopy[0],vectorcopy.size());
77 vector<int> c(
int n1,
int n2,
int n3,
int n4,
int n5){
79 ans << n1,n2,n3,n4,n5;
82 vector<int> c(
int n1,
int n2,
int n3,
int n4,
int n5,
int n6){
84 ans << n1,n2,n3,n4,n5,n6;
87 vector<int> c(
int n1,
int n2,
int n3,
int n4,
int n5,
int n6,
int n7){
89 ans << n1,n2,n3,n4,n5,n6,n7;
95 array():MapBase(NULL,0){};
101 array(
int n1):MapBase(NULL,0){initZeroArray(c(n1));}
102 array(
int n1,
int n2):MapBase(NULL,0){initZeroArray(c(n1,n2));}
103 array(
int n1,
int n2,
int n3):MapBase(NULL,0){initZeroArray(c(n1,n2,n3));}
104 array(
int n1,
int n2,
int n3,
int n4):MapBase(NULL,0){initZeroArray(c(n1,n2,n3,n4));}
105 array(
int n1,
int n2,
int n3,
int n4,
int n5):MapBase(NULL,0){initZeroArray(c(n1,n2,n3,n4,n5));}
106 array(
int n1,
int n2,
int n3,
int n4,
int n5,
int n6):MapBase(NULL,0){initZeroArray(c(n1,n2,n3,n4,n5,n6));}
107 array(
int n1,
int n2,
int n3,
int n4,
int n5,
int n6,
int n7):MapBase(NULL,0){initZeroArray(c(n1,n2,n3,n4,n5,n6,n7));}
113 new (
this) MapBase(&vectorcopy[0],x.size());
121 new (
this) MapBase(&vectorcopy[0],x.size());
128 array(
const array &x) : MapBase(NULL,0), vectorcopy(x) {
129 if ( x.size() > 0 ) {
131 new (
this) MapBase(&vectorcopy[0], x.size());
150 if(this->dim.size() == 0){
151 this->initZeroArray(other.dim);
153 this->MapBase::operator=(other);
169 Array<Type, Dynamic, Dynamic> a = y;
170 a.resize(a.size(),1);
171 return array(MapBase::operator=(a), dim);
175 std::cout <<
"Array dim: ";
176 for(
int i=0;i<dim.size();i++)std::cout << dim[i] <<
" ";
178 std::cout <<
"Array val: ";
179 for(
int i=0;i<this->MapBase::size();i++)std::cout << this->MapBase::operator[](i) <<
" ";
188 return dim[dim.size()-1];
202 int nslice=this->MapBase::size()/this->
cols();
203 Type* p=&(this->MapBase::operator()(i*nslice));
206 newdim=dim.segment(0,dim.size()-1);
211 return array(p,newdim);
217 return this->MapBase::operator[](i1);
221 return this->MapBase::operator[](index(c(i1,i2)));
225 return this->MapBase::operator[](index(c(i1,i2,i3)));
229 return this->MapBase::operator[](index(c(i1,i2,i3,i4)));
233 return this->MapBase::operator[](index(c(i1,i2,i3,i4,i5)));
236 Type&
operator()(
int i1,
int i2,
int i3,
int i4,
int i5,
int i6){
237 return this->MapBase::operator[](index(c(i1,i2,i3,i4,i5,i6)));
240 Type&
operator()(
int i1,
int i2,
int i3,
int i4,
int i5,
int i6,
int i7){
241 return this->MapBase::operator[](index(c(i1,i2,i3,i4,i5,i6,i7)));
246 eigen_assert( tup.size() == dim.size() );
247 eigen_assert( ( (dim*0 <= tup) && (tup < dim) ).all() );
248 return (tup*mult).sum();
253 for(
int k=0;k<dim.size();k++){
254 revtup[k]=i/revmult[k];
255 i=i-revtup[k]*revmult[k];
257 return revtup.reverse();
266 for(
int i=0;i<this->size();i++){
267 ans[ans.index(tuple(i)(p))]=this->operator[](i);
278 for(
int i=0;i<p.size();i++)p[i]=i;
279 return this->
perm(p.reverse());
282 int mod(
int i,
int n){
return ((i%n)+n)%n;}
292 for(
int i=0;i<p.size();i++)p[i]=mod(i-n,p.size());
293 return this->
perm(p);
296 #define INHERIT(OP) \ 298 array<Type> OP(T y){return array(MapBase::OP(y),dim);} 312 ans.resize(this->
rows(), ans.size() / this->
rows() );
Vector class used by TMB.
void setdim(vector< int > dim_)
Sets dimension attribute and updates internal stride. Must be used when e.g. collapsing array dimensi...
array< Type > perm(vector< int > p)
Array permutation. Permutes array dimensions corresponding to permutation vector p.
tmbutils::matrix< Type > matrix()
Convert TMB array to matrix by keeping the first dimension and collapsing remaining dimensions...
int cols()
Number of outer-most dimensions.
Type & operator()(int i1)
Elementwise subsetting 1D array. Also allowed in general to access the underlying vector of n-dim arr...
array< Type > rotate(int n)
Array rotate (Special case of array permutation)
int rows()
Number of inner-most dimensions.
tmbutils::vector< Type > vec()
Convert TMB array to vector.
Matrix class used by TMB.
array< Type > transpose()
Array transpose (Special case of array permutation)
Vector class used by TMB.
array< Type > col(int i)
Extract sub-array with write access Index i refers to the outer-most (i.e. final) dimension...
array(vector< int > dim_)
Construct array from dimension vector and fill with zeros.