This forum has been archived. All content is frozen. Please use KDE Discuss instead.

stack VectorXi unto int

Tags: None
(comma "," separated)
vak
Registered Member
Posts
23
Karma
0
OS

stack VectorXi unto int

Fri Mar 30, 2012 3:09 pm
hello all,

i need to put a eigen::VectorXi inside an *int container:


extern "C"{
void R_fastr(int* n, int* p, int* k0,float* x,int* k1,int* RIndexC,int* nsamp,int* J,float* objfunC,int* h_m){
Map<MatrixXf> x_cen(x,*n,*p);
MatrixXf x_cen1 = x_cen;
int h_i=*p+1;
while(Binomial(h_i,*p)<=*k0) h_i++;
int h,j,h_o,i;
float objfunA,objfunB=*objfunC;
VectorXi RIndexB(*h_m);
RIndexB=call_to_a_function_returning_vectorXi(x_cen1)

//here:

for(i=0;i<ih_m;i++){
RIndexC[i]=RIndexB(i);
}

}
}


I was wondering whether there was a way to replace

for(i=0;i<ih_m;i++){
RIndexC[i]=RIndexB(i);
}

by a map/cast/...i.e. a pre-written method.

Best,
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: stack VectorXi unto int

Fri Mar 30, 2012 7:14 pm
I did not read your code, but you can get inspiration from that:

int * data;
VectorXi vec(size);
Map<VectorXi> (data, size) = vec;
vak
Registered Member
Posts
23
Karma
0
OS

Re: stack VectorXi unto int

Fri Mar 30, 2012 9:15 pm
Dear ggael,

corrct me if i misunderstood your answer,

it seems your advice would help me move the content of data unto a vectXi object vec (this is covered in the manual).

i'm trying to do the opposite: move the content of a vectorXi to data.


//say:
int n=100;
vector<int> second (n,0);
VectorXi vec= VectorXi::Random(n);


for(int i=0;i<n;i++){
data[i]=vec(i);
}


my question is: is there a method to do this loop?
(a sort of reverse map, really)
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: stack VectorXi unto int  Topic is solved

Fri Mar 30, 2012 9:43 pm
what I wrote exactly does that. A Map object is just like an Eigen's matrix object.
vak
Registered Member
Posts
23
Karma
0
OS

Re: stack VectorXi unto int

Fri Mar 30, 2012 10:56 pm
thanks, lovely (and how silly oh mr :))


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]