RFC: add API to enforce a specified dimensionality
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 25/100
- issue の種類
- 機能追加
- 明瞭さ
- 説明が足りない
- 活発さ
- 停滞
- 技術スタック
- python, tensorflow
調査の方向性
まず issue #97 のこれまでの議論を読み、その後、この RFC にある提案された enforce_shape シグネチャと例を確認してください。API と、未知の次元数、シンボル、エリプシスの扱いについて合意があるかを判断してください。完了とは、実装計画ではなく、合意された仕様があることを意味します。
索引モデルが issue の本文から書いたものです。
説明
Previous discussion: https://github.com/data-apis/array-api/issues/97
Resolution was to ignore the case of data-dependent (unknown) dimensionalities.
I have a suggestion how to implement it by adding a new function to the API with a specific interface.
This allows to support variable dimensionality in a large number of practical cases.
Additionally, it allows to partially control dimension sizes that are currently unknown.
Example 1:
x, [d1, d2, d3] = xp.enforce_shape(x, [None, None, None])
enforces dimensionality to be 3, will fail for inputs of other dimensionalities.
If dimensionality is not yet known - will fail in runtime at this operation.
Elements d1, d2 and d3 are integers or symbols, not Nones.
Returned x is either the same tensor, or tensor with attached information about shape.
Main reason for returning a tensor is that operation could not be cut out of the graph if resulting shape is not used to obtain result.
Example 2:
x, [d1, d2, d3] = xp.enforce_shape(x, [d1_input, None, 4])
expects input to have 3 dimensions, first axis matches to (maybe) symbol d1_input, last axis of length 4.
Example 3:
x, [d1, d2, (axes, n_elements), d3] = xp.enforce_shape(x, [1, None, ..., 3])
expects input to have 3 or more dimensions. First axis is of length 1, second of any length, last of length 3.
Note here, that for ellipsis a tuple with two objects is returned: axes corresponds to x.shape[2:-1], and n_elements is a product of elements in axes.
axes is either a tuple of Union[int, Symbol] (if dimensionality is known)
or a Symbol for a tuple of unknown size (if dimensionality is unknown), same type as used to represent unknown shape.
n_elements is either int (if size of all axes is known) or symbol for axis.
Signature
Tensor, List[Union[int, None, AxisSymbol, ellipsis]] -> Tuple[Tensor, List[Union[int, AxisSymbol, EllipsisTuple]]]
EllipsisTuple = Tuple[TupleSymbol, AxisSymbol]
| Tuple[Tuple[SizeOrSymbol, ...], SizeOrSymbol]
SizeOrSymbol = Union[int, AxisSymbol]
I see this as a good intermediate point: sufficient to deal with multiple practical cases while requiring framework developers to maintain very little.
Downstream package dev perspective
- there are cases when a dimensionality should be enforced (e.g. 1d/2d). This is covered by proposed function
- there are cases when axes can be split into operation-important and non-important.
There is a generic path to deal with these cases by first reducing to a fixed dimensionality, and converting back afterwards.
Example: last dimension should be rgb, should convert to hsl. Assuming we have a function that implements conversion for 2d array.
x_rgb, [(axes, n_elements), last_axis] = xp.enforce_shape(x_rgb, [..., None])
x_rgb_2d = xp.reshape(x_rgb, (n_elements, last_axis))
x_hsv_2d = convert_rgb_to_hsv(x_rgb_2d) # or any other function that works with 'fixed' dimensionality
result = xp.reshape(x_hsv_2d, axes + (last_axis,))
- if there is a need to e.g. specify last or first dimension, now it is possible with graph-based frameworks too. Standard way is to add validations like
tf.assert(...)and bind them in the graph, which can't be done in a cross-framework manner
Frameworks perspective
While the function is novel, it does not introduce any new entities: symbols for axes and symbols for shapes (like TensorShape) should exist anyway.
Function behavior overlaps with and extends tf.set_shape by supporting ellipsis.
For frameworks without data-dependent shapes, this is straightforward to implement based on already exposed shape property.
- 主要言語
- Python
- スター
- 281
- フォーク
- 52
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
data-apis/array-api のほかの issue
-
bug Maintenance Narrative Content
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
-
Maintenance
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
data-apis/array-api の issue をすべて見る
似ている issue
-
agent-ready documentation needs-triage
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
-
documentation
難易度 1/5 1時間未満 初心者へのやさしさ 91/100
-
workflow-status page template still says reusable workflows are "triggered only by workflow_call:" オープン
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
-
instance instance add
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
searxng/searx-instances#939 · コメント 1 件 ·
-
area-deployment area-integrations triage:bot-seen
難易度 2/5 半日 初心者へのやさしさ 86/100