Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Spell out where views are allowed

未关闭
#331 15 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
文档
描述清晰度
基本清楚
活跃度
停滞
技术栈
python, pytorch
领域
documentation

调研方向

从链接的副本、视图和变异部分开始,审查 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__
  • asarray
  • astype
  • __dlpack__
  • from_dlpack
  • reshape
  • broacast_to
  • broadcast_arrays
  • ...more?
主要语言
Python
星标
132
派生
49
平均合并
16 小时 2 分钟
30 天内合并 PR
2

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

data-apis/array-api-compat 的其他 Issue

查看 data-apis/array-api-compat 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。