|
Boost Users : |
From: Sebastien Fortier (sebastien.fortier_at_[hidden])
Date: 2006-08-11 09:31:17
I would like to know if it is possible to use memcpy to copy a float
array to a particular dimension of a multi_array.
ex.:
I declare a 3 dimension multi_array of floats
typedef boost::multi_array < float, 3 > array_type3D_f_t;
int dim1 = 2;
int dim2 = 2;
int dim3 = 4;
array_type3D_f_t valueMatrix(boost::extents[dim1][dim2][dim3]);
then for each 3rd dimension I would like to copy a float array into it
using memcpy
(the final real multi_array will contain approx 21 000 000 elements, and
thts why I do wish to iterate ).
for (int i = 0; i < dim3; ++i) { // iterate over each 3rd dimension of
the multi_array
float *arr = NULL;
arr = (float*)malloc(sizeof(float) * dim1 * dim2);
function(&arr) // fills in the array (2D contiguous (dim1 * dim2))
memcpy(&valueMatrix[something...], arr, sizeof(float) * dim1 * dim2)
// I want to copy the vector into the multi_array's 3rd dimension
}
then when I want to access an element I simply do
valueMatrix[1][1][1];
what i used to do is
int level = 0;
while(it1 != it2){ // it1 and it2 are iterators to a list of records
holding the data
float* arr;
readData(it1, &arr); // read the data into the array
for (int j = 0; j < dim2; ++j){
for (int i = 0; i < dim1; ++i){
valueMatrix[i][j][level] = datavec[ j * dim1+i ];
}
}
++it1;
// change level
++level;
}
I would like to replace the nested loops by a memcpy, is this possible?
-- Sébastien Fortier
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net