You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: mlir/docs/Traits/Broadcastable.md
+13-12Lines changed: 13 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -69,17 +69,17 @@ Given the shapes of two ranked input operands, the result's shape is inferred by
69
69
```python
70
70
InferShape(shape0, shape1):
71
71
72
-
# Equalize ranks
73
-
rank =max(GetRank(shape0), GetRank(shape1))
74
-
ExpandRank(shape0, rank)
75
-
ExpandRank(shape1, rank)
72
+
# Equalize ranks
73
+
rank =max(GetRank(shape0), GetRank(shape1))
74
+
ExpandRank(shape0, rank)
75
+
ExpandRank(shape1, rank)
76
76
77
-
# Infer shape
78
-
inferredShape = []
79
-
for (dim0, dim1) inzip(shape0, shape1):
80
-
inferredDim = InferDim(dim0, dim1)
81
-
inferredShape.append(inferredDim)
82
-
return inferredShape
77
+
# Infer shape
78
+
inferredShape = []
79
+
for (dim0, dim1) inzip(shape0, shape1):
80
+
inferredDim = InferDim(dim0, dim1)
81
+
inferredShape.append(inferredDim)
82
+
return inferredShape
83
83
```
84
84
85
85
The result shape for an operation with an arbitrary number of input operands is then inferred by discarding unranked operands, applying shape inference on the first ranked operand pair, and updating the inferred shape with each additional ranked operand. If the operation has no ranked operands, the result shape cannot be inferred. If the operation has exactly one ranked operand, its shape is directly provided as the inferred result shape. Formally:
@@ -111,7 +111,7 @@ Once a rank match is guaranteed, each dimension of the inferred shape is compare
| ? | static |**Error** <br> An inferred dimension being dynamic indicates that its size cannot be inferred at compile time from its input operands. The presence of a static dimension in the actual result is counterintuitive and is therefore not allowed. |
114
+
| ? | static |**OK** <br> A failure to guarantee that the runtime dimension size of the result is equal to `actualDim` causes undefined behavior. While unusual, this implicit dynamic-to-static cast is convenient in certain scenarios, such as an intermediate state of a shape inference pass. Ultimately, a static dimension in the result implies that all input dimension sizes are also known at compile time and may therefore become static as well, preferably. |
115
115
| static | ? |**OK** <br> The actual result dimension may be dynamic even when a static size can be inferred at compile time. The programmer may choose to relax the specificity of the result dimension for forward compatibility of the result type. |
116
116
| static | static |**OK if equal** <br> When both the inferred and actual dimensions are static, they must be set to the same size. |
117
117
@@ -134,7 +134,6 @@ Verify(op):
134
134
135
135
# Verify
136
136
for (inferredDim, actualDim) inzip(inferredShape, actualShape):
137
-
ERROR_IF(IsDynamic(inferredDim) and IsStatic(actualDim))
138
137
ERROR_IF(IsStatic(actualDim) and inferredDim != actualDim)
139
138
```
140
139
@@ -195,3 +194,5 @@ The following are incorrect uses of broadcastable ops:
195
194
// tensor<4xi32>. Broadcast semantics are not applicable for results.
0 commit comments