最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论