WanderingMathematician
WanderingMathematician

Reputation: 443

How to use a 2d array to declare an array_view or array object in c++ AMP

I'm trying to use an array such as int myarray[2][3] to initialize an array_view object. I've tried array_view<int, 2> a(2,3, myarray); However that does not work. I would also like to be able to do the same thing with a vector. Any ideas?

Upvotes: 2

Views: 1618

Answers (2)

Kevin
Kevin

Reputation: 31

Baltram’s method is correct. And you can replace

array_view<int, 2> a(2, 3, &my_composed_vector.front()); 

by

array_view<int, 2> a(2, 3, my_composed_vector); 

to make it simpler.

Here is an even more simpler way:

int myarray[2][3];
int *p = &myarray[0][0];
array_view<int, 2> a(2, 3, p);

Thanks,

Upvotes: 3

Baltram
Baltram

Reputation: 681

Try array_view<int, 2> a(2, 3, *myarray);

EDIT :

A vector of (fixed-size) vectors can't be used directly to init an array_view object.

However you could do something like that:

vector< vector<int> > my_multi_vector; // Fill my_multi_vector with data
vector<int> my_composed_vector;
for(int i = 0, ie = my_multi_vector.size(); i != ie; ++i)
    my_composed_vector.insert(my_composed_vector.end(), my_multi_vector[i].begin(), my_multi_vector[i].end());
array_view<int, 2> a(2, 3, &my_composed_vector.front());

Upvotes: 3

Related Questions