开发者

Transformation of Linear Column-Major Array Data to Row-Major

I have Fortran-based 3D column-major order array flattened into linear memory. What formula/algorithm can I use map it back to a Java 3D row开发者_开发问答-major order array? For example,

|1, 2, 3| |10, 11, 12| |19, 20, 21|
|4, 5, 6| |13, 14, 15| |22  23, 24|
|7, 8, 9| |16, 17, 18| |25, 26, 27|

Looks like this in memory

buffer = 1, 4, 7, 2, 5, 8, 3, 6, 9, 10, 13, 16, 11, 14, 17, 12, 15, 18, 19, 22, 25, 20, 23, 26, 21, 24, 27

Ideally, I need to pass in the array indices and get back the offset to the linear memory. In pseudo code, something like

for(;;)
{
   javaarray[2][2][1] = buffer[Util.LookupOffset(2,2,1)]
}

Thanks.


First thing, Java array indices are 0-based, so you'd want javaarray[1][2][0] instead of javaarray[2][3][1].

Second thing, I think I understand what you're trying to do.

  • Input: 0,0,0 (slot with 1 in it) => output: 0 (index of 1 in the flattened array)
  • Input: 1,2,0 (slot with 12 in it) => output: 15 (index of 12 in the flattened array)
  • Input: 2,1,2 (slot with 26 in it) => output: 23 (index of 26 in the flattened array)

Looks like you want, for an input of (i,j,k):

index = 9 * i + 3 * j + k
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜