{"id":24765934,"url":"https://github.com/infinitensor/mem-rearrange","last_synced_at":"2026-03-08T05:31:58.947Z","repository":{"id":269810483,"uuid":"908531145","full_name":"InfiniTensor/mem-rearrange","owner":"InfiniTensor","description":null,"archived":false,"fork":false,"pushed_at":"2025-05-13T12:40:36.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-26T02:22:47.734Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/InfiniTensor.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-12-26T09:50:43.000Z","updated_at":"2025-05-13T12:40:24.000Z","dependencies_parsed_at":"2025-07-27T19:47:18.640Z","dependency_job_id":null,"html_url":"https://github.com/InfiniTensor/mem-rearrange","commit_stats":null,"previous_names":["infinitensor/mem-rearrange"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/InfiniTensor/mem-rearrange","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InfiniTensor%2Fmem-rearrange","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InfiniTensor%2Fmem-rearrange/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InfiniTensor%2Fmem-rearrange/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InfiniTensor%2Fmem-rearrange/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/InfiniTensor","download_url":"https://codeload.github.com/InfiniTensor/mem-rearrange/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InfiniTensor%2Fmem-rearrange/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30246724,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-08T00:58:18.660Z","status":"online","status_checked_at":"2026-03-08T02:00:06.215Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-28T23:17:46.176Z","updated_at":"2026-03-08T05:31:58.932Z","avatar_url":"https://github.com/InfiniTensor.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿# mem-rearrange\n\n[![CI](https://github.com/InfiniTensor/mem-rearrange/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/InfiniTensor/mem-rearrange/actions)\n[![Latest version](https://img.shields.io/crates/v/mem-rearrange.svg)](https://crates.io/crates/mem-rearrange)\n[![Documentation](https://docs.rs/mem-rearrange/badge.svg)](https://docs.rs/mem-rearrange)\n[![license](https://img.shields.io/github/license/InfiniTensor/mem-rearrange)](https://mit-license.org/)\n[![codecov](https://codecov.io/github/InfiniTensor/mem-rearrange/branch/main/graph/badge.svg)](https://codecov.io/github/InfiniTensor/mem-rearrange)\n\n![GitHub repo size](https://img.shields.io/github/repo-size/InfiniTensor/mem-rearrange)\n![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/InfiniTensor/mem-rearrange)\n[![GitHub Issues](https://img.shields.io/github/issues/InfiniTensor/mem-rearrange)](https://github.com/InfiniTensor/mem-rearrange/issues)\n[![GitHub Pull Requests](https://img.shields.io/github/issues-pr/InfiniTensor/mem-rearrange)](https://github.com/InfiniTensor/mem-rearrange/pulls)\n![GitHub contributors](https://img.shields.io/github/contributors/InfiniTensor/mem-rearrange)\n![GitHub commit activity](https://img.shields.io/github/commit-activity/m/InfiniTensor/mem-rearrange)\n\n根据布局参数重排数据，将数据从一个高维数组中转移到另一个具有不同存储布局的高维数组中。\n\n不妨将数据来源的数组称为 `src`，去向的数组称为 `dst`。由于两个数组形状相同，二者的元素是一一对应的。算子将 `src` 中的数据拷贝到 `dst` 中的对应位置。\n\n例如，要转置存放在数组中的 $2 \\times 3$ 矩阵：\n\n\u003e - 符号表示数据元素；\n\u003e - 下标表示数据在存储空间中排布的位置；\n\n$$\nsrc:\n\\left(\n    \\begin{gathered}\n    a_0, b_1, c_2\\\\\n    d_3, e_4, f_5\\\\\n    \\end{gathered}\n\\right)\n\\stackrel{转置}{\\rightarrow}\ndst:\n\\left(\n    \\begin{gathered}\n    a_0, d_1\\\\\n    b_2, e_3\\\\\n    c_4, f_5\\\\\n    \\end{gathered}\n\\right)\n$$\n\n这个操作实际改变了存储空间中的数据排布，因此必须进行数据重排。下式直观展示了数据重排的功能：\n\n\u003e 注意观察表示数据排布的下角标。\n\n$$\nsrc:\n\\left(\n    \\begin{gathered}\n    a_0, b_1, c_2\\\\\n    d_3, e_4, f_5\\\\\n    \\end{gathered}\n\\right)\n\\stackrel{布局转置}{\\rightarrow}\n\\left(\n    \\begin{gathered}\n    a_0, d_3\\\\\n    b_1, e_4\\\\\n    c_2, f_5\\\\\n    \\end{gathered}\n\\right)\n\\stackrel{数据重排}{\\rightarrow}\ndst:\n\\left(\n    \\begin{gathered}\n    a_0, d_1\\\\\n    b_2, e_3\\\\\n    c_4, f_5\\\\\n    \\end{gathered}\n\\right)\n$$\n\n由于重排操作不关心数据的内容，仅在存储空间上操作数据，可以对算法进行硬件无关的预排布和优化。\n\n优化过程包括 3 个主要步骤：\n\n1. 剔除长度为 1 的维度；\n2. 按步长对维度排序；\n3. 合并在存储排布上连续的维度；\n\n完成以上步骤后，关于重排运算的全部信息将存储在 `Rearranging` 结构体中。通过为结构体传入不同的数据指针可以反复执行相同的重排变换。CPU 的重排运算实现使用 rayon 进行并行加速。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfinitensor%2Fmem-rearrange","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finfinitensor%2Fmem-rearrange","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfinitensor%2Fmem-rearrange/lists"}