
everweb wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
r0d wrote:
Hello everybody,
i'm looking for the best way to modify the dimensions of an array. For example, i got this one:
boost::multi_array<int, 2> array ( boost::extents[3][3] );
and i want to change it in an array of 5 dimensions.
Now, what i'm doing is to create a new array of 5 dimensions and copying the first one into it, then delete the first one. But i'm sure that a more efficient way exists. No?
use resize() - see below
TEST(multi_array) { boost::multi_array<int, 2> myArray ( boost::extents[3][3] );
int values = 0; for(boost::multi_array<int, 2>::index i = 0; i != 3; ++i) { for(boost::multi_array<int, 2>::index j = 0; j != 3; ++j) { myArray[i][j] = values++; } }
// Verify values int verify1 = 0; for(boost::multi_array<int, 2>::index i = 0; i != 3; ++i) { for(boost::multi_array<int, 2>::index j = 0; j != 3; ++j) { CHECK_EQUAL(myArray[i][j],verify1++); } } myArray.resize(boost::extents[5][5]);
//continue setting 'values' in the newly added array space for(boost::multi_array<int, 2>::index i = 3; i != 5; ++i) { for(boost::multi_array<int, 2>::index j = 3; j != 5; ++j) { myArray[i][j] = values++; } }
//check the original data is still there int verify2 = 0; for(boost::multi_array<int, 2>::index i = 0; i != 3; ++i) { for(boost::multi_array<int, 2>::index j = 0; j != 3; ++j) { CHECK_EQUAL(myArray[i][j],verify2++); } }
//check that the new array space has correct values for(boost::multi_array<int, 2>::index i = 3; i != 5; ++i) { for(boost::multi_array<int, 2>::index j = 3; j != 5; ++j) { CHECK_EQUAL(myArray[i][j],verify1++); } }
}
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org
iD8DBQFIQGnW/X5Z5iyVCbERAmCmAJ4qgpbHzcUYqGor8kDUabQfDHwCLQCfZ7EH dTGc5PybZhGR0zgyUxx92q0= =VwiS -----END PGP SIGNATURE----- _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Thank you everweb, but that's not what i want to do. Surely i expained badly my problem (my english is too bad). I want to change the number of dimensions of the array. For example, i got an array: boost::multi_array<int, 2> and i want to change it in boost::multi_array<int, 5> Is it possible to di it easyly? -- View this message in context: http://www.nabble.com/-multi_array--how-to-modify-the-dimension-of-an-array-... Sent from the Boost - Users mailing list archive at Nabble.com.