File tree Expand file tree Collapse file tree 1 file changed +9
-12
lines changed
mlir/lib/Dialect/Tosa/Utils Expand file tree Collapse file tree 1 file changed +9
-12
lines changed Original file line number Diff line number Diff line change @@ -77,24 +77,21 @@ computeReshapeOutput(ArrayRef<int64_t> higherRankShape,
7777 // Initialize new shapes with [1] * higherRank.
7878 int64_t higherRank = higherRankShape.size ();
7979 int64_t lowerRank = lowerRankShape.size ();
80-
8180 reshapeOutputShape.assign (higherRank, 1 );
8281
8382 int64_t higherRankDim;
8483 int64_t lowerRankDim;
84+ const int64_t rankDiff = higherRank - lowerRank;
85+
86+ for (int64_t i = lowerRank - 1 ; i >= 0 ; i--) {
87+ higherRankDim = higherRankShape[i + rankDiff];
88+ lowerRankDim = lowerRankShape[i];
8589
86- for (int64_t i = higherRank - 1 , j = lowerRank - 1 ; i >= 0 && j >= 0 ;
87- i--, j--) {
88- higherRankDim = higherRankShape[i];
89- lowerRankDim = lowerRankShape[j];
90-
91- if (lowerRankDim == 1 && higherRankDim > 1 )
92- reshapeOutputShape[i] = 1 ;
93- else if ((lowerRankDim > 1 && higherRankDim == 1 ) ||
94- (lowerRankDim == higherRankDim))
95- reshapeOutputShape[i] = lowerRankDim;
96- else if (higherRankDim != lowerRankDim)
90+ if (lowerRankDim != 1 && higherRankDim != 1 &&
91+ lowerRankDim != higherRankDim)
9792 return failure ();
93+
94+ reshapeOutputShape[i + rankDiff] = lowerRankDim == 1 ? 1 : lowerRankDim;
9895 }
9996 return success ();
10097}
You can’t perform that action at this time.
0 commit comments