2
我很困惑将2D阵列转换为1D阵列。 我想以宽度,行和列格式的形式为“a11”(在(1,1))编写一个相邻的8个元素,而不使用for循环。阵列2D到1D转换和混淆
|<--Width--->|
cols
____________
| a00 a01 a02
rows | a10 a11 a12
| a20 a21 a22
我想以这样的方式
a00 = pSrc[(cols-1)+ (rows - 1)*width];
a02 = pSrc[(cols-1)+ (rows + 1)*width];
a10 = pSrc[cols+ (rows -1)*width];
a12 = pSrc[cols+ (rows +1)*width];
a20 = pSrc[(cols+1)+ (rows - 1)*width];
a22 = pSrc[(cols+1)+ (rows + 1)*width];
a01 = pSrc[(cols-1)+ (rows)*width];
a21 = pSrc[(cols+1)+ (rows)*width];
但我认为我做了一些错误。可以任何一个可以帮助我在这。
为了您的信息'a [i] [j] = *(*(a + i)+ j)'。 – 2014-09-30 04:27:25
我不想使用for循环,因为我正在用OpenCL编写代码。我正在用内核代码替换循环。能否以上述格式给出我提到的答案 – Ashwin 2014-09-30 04:41:21
如何定义pSrc?你的例子中'cols'设置为'1'(并且'rows'设置为'1')? – 2014-09-30 04:58:57