Spell out where views are allowed
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 25/100
- Issue 类型
- 文档
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
调研方向
从链接的副本、视图和变异部分开始,审查 array_api_compat PR 298,尤其是 sum 示例。将列出的生成视图的函数与 issue 中提出的其他操作进行比较,然后记录一份明确且达成共识的范围,说明何时允许使用视图;当标准能够明确解决这些情况时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
In https://data-apis.org/array-api/latest/design_topics/copies_views_and_mutation.html, the Standard says
Array API consumers are strongly advised to avoid any mutating operations when an array object may [...] be a “view” [...] It is not always clear, however, when a library will return a view and when it will return a copy. This standard does not attempt to specify this—libraries may do either.
The above is fine after __getitem__ , asarray(..., copy=None), astype(..., copy=False), and similar functions that are explicitly explained by the standard to potentially return views.
However, there are a few corner cases where views could be possible but a normal user is very unlikely to think about them.
I just stumbled on one in https://github.com/data-apis/array-api-compat/pull/298, where array_api_compat.torch.sum(x, dtype=x.dtype, axis=()) was accidentally returning x instead of a copy of it.
There are a few more cases where a library could try to be smart; for example
- search functions (
min,max, other?) could return a view to the minimum/maximum point - replacement functions (
minimum,maximum,clip,where) could return one of the input arrays when there is nothing to do - same for arithmetic functions (
__add__/__sub__vs. 0,__mul__/__div__vs. 1, etc.) - same for sort functions when they realise the input is already sorted
- possibly more
In real life, I expect end users to assume that the above functions will always return a copy.
I think the standard should spell this out, limiting the possibily of views to an explicit list of allowed functions:
__getitem__asarrayastype__dlpack__from_dlpackreshapebroacast_tobroadcast_arrays- ...more?
- 主要语言
- Python
- 星标
- 132
- 派生
- 49
- 平均合并
- 16 小时 2 分钟
- 30 天内合并 PR
- 2
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
data-apis/array-api-compat 的其他 Issue
-
blocked by upstream
难度 2/5 1-3 小时 新手友好度 68/100
data-apis/array-api-compat#439 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
data-apis/array-api-compat#395 · 2 条评论 ·
-
Release 1.16未关闭
难度 5/5 一周以上 新手友好度 25/100
data-apis/array-api-compat#476 ·
-
难度 5/5 一周以上 新手友好度 30/100
data-apis/array-api-compat#473 · 4 条评论 ·
-
难度 4/5 3-5 天 新手友好度 45/100
data-apis/array-api-compat#465 · 3 条评论 ·
查看 data-apis/array-api-compat 的全部 Issue
相似的 Issue
-
New Internship未关闭new_internship
难度 1/5 1 小时以内 新手友好度 70/100
-
[BUG] Reports tab: "Unban" button tooltip shows raw `{{ip}}` placeholder instead of the IP address未关闭bug javascript ui
难度 2/5 1-3 小时 新手友好度 68/100
bunkerity/bunkerweb#4001 · 1 条评论 ·
维护者通常 1 天内回复
-
bug
难度 1/5 1 小时以内 新手友好度 92/100
PedestrianDynamics/pyFDS-Evac#476 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
google/differential-privacy#516 ·
-
难度 2/5 1-3 小时 新手友好度 82/100
adobe-fonts/source-serif#153 ·