C code for fusing multiple array transpositions into one pass - Stack Overflow

Suppose that A is a one-dimensional NumPy array and s, n_y, n_x,blk_y, and blk_x are integers > 0 a

Suppose that A is a one-dimensional NumPy array and s, n_y, n_x, blk_y, and blk_x are integers > 0 and s divides both blk_y and blk_x. The number of elements in A is equal to both n*s*s and ny*blk_y*n_x*blk_x. Write C code that fuses the following transpositions into one pass over the array:

A = A.reshape(n, s, s).transpose(0, 2, 1)
A = A.reshape(n_y, n_x, blk_y, blk_x).transpose(0, 2, 1, 3)
A = A.reshape(n_y * blk_y, n_x * blk_x))

It is straight-forward to convert the code to C if we are allowed to perform multiple passes over the array, but I don't think we have to. If we have a long chain of reshape/transposes,

A.reshape(...).transpose(...).reshape(...).transpose(...).reshape(...).transpose(...)

can we create a formula for how to reorder the array in one pass? I think we can since we are just permuting the array based on some pattern. Transpositions does not have to be in place. What matters is that the source array is only read once.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745239587a4618099.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信