<br>I would like to point out something (that may be known), but may be confusing to others that read this post and will affect the data written to the arrays as it appears linearly.� This is regarding the fastest increasing axis:<br>
<br>in C/C++ float� c_array[z_dim][y_dim][x_dim] ;<br><br>defines a row major array with the x_dim axis being the axis of the fastest increasing index.<br><br>You can specify any axis you want to be the fastest increasing dimension just so long is that is how you expect the data to appear in linear memory and it is accessed accordingly.<br>
<br>I think:<br><br>boost::extents[xDim][yDim][zDim]<br><br>should be:<br><br>boost::extents[zDim][yDim][xDim]<br><br>as:<br><br>#include &lt;boost/multi_array.hpp&gt;<br><br>int main( void )<br>{<br><br>��� ��� int x_dim = 4;<br>
��� ��� int y_dim = 3;<br>��� ��� int z_dim = 2;<br><br>��� ��� float* mat_1_data = new float[x_dim * y_dim * z_dim];<br>��� ��� float* mat_2_data = new float[x_dim * y_dim * z_dim];<br><br>��� ��� boost::multi_array_ref&lt;float, 3&gt; mat_1( mat_1_data, boost::extents[z_dim][y_dim][x_dim] );<br>
��� ��� boost::multi_array_ref&lt;float, 3&gt; mat_2( mat_2_data, boost::extents[x_dim][y_dim][z_dim] );<br><br>��� ��� for( int z = 0; z &lt; z_dim; z++ ){<br>��� ��� for( int y = 0; y &lt; y_dim; y++ ){��� ��� <br>��� ��� for( int x = 0; x &lt; x_dim; x++ ){<br>
��� ��� ��� mat_1[z][y][x] =� z * x_dim * y_dim + y * x_dim + x;��� ��� ��� ��� ��� <br>��� ��� }��� <br>��� ��� }<br>��� ��� }<br><br>��� ��� for( int x = 0; x &lt; x_dim; x++ ){��� ��� <br>��� ��� for( int y = 0; y &lt; y_dim; y++ ){<br>
��� ��� for( int z = 0; z &lt; z_dim; z++ ){<br>��� ��� ��� mat_2[x][y][z] = x * y_dim * z_dim + y * z_dim + z;<br>��� ��� }��� <br>��� ��� }<br>��� ��� }<br><br>��� ��� for( int i = 0; i &lt; 12; i++ )<br>��� ��� {<br>��� ��� ��� printf( &quot;%f : %f\n&quot;, mat_1_data[i], mat_2_data[i] );<br>
��� ��� }<br><br><br>��� ��� delete [] mat_1_data;<br>��� ��� delete [] mat_2_data;<br><br>}<br><br>yields:<br><br>0.000000 : 0.000000<br>1.000000 : 1.000000<br>2.000000 : 2.000000<br>3.000000 : 3.000000<br>4.000000 : 4.000000<br>
5.000000 : 5.000000<br>6.000000 : 6.000000<br>7.000000 : 7.000000<br>8.000000 : 8.000000<br>9.000000 : 9.000000<br>10.000000 : 10.000000<br>11.000000 : 11.000000<br><br>with the first matrix mat_1 being &quot;typical usage&quot; where x is the axis of fastest increase as:<br>
<br>mat_2[x][y][z] = x * y_dim * z_dim + y * z_dim + z;<br><br>indexing is a bit odd, but perfectly acceptable so long as this is what is desired<br><br>if the order of the for loops is changed for mat_2 so it loops z then y then x the array will not be written linearly and can be seen if the array is printed while it is being filled in.<br>
<br>though what was originally posted may very well be what is desired by the original author.<br><br><br><br><br><br>