Skip to content

Commit

Permalink
Fix type infer of slice
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnycase committed Mar 6, 2025
1 parent 5f9443a commit 73dcee7
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/Nncase.Evaluator/Tensors/Slice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,13 @@ private static Dimension TranslateBeginEnd(Dimension x, Dimension dim, long lowe
{
if (x.IsFixed)
{
return x.FixedValue < 0 ? dim + x : Dimension.Clamp(x, lowerBound, dim + upperBoundBias);
var newX = x.FixedValue < 0 ? dim + x : x;
return Dimension.Clamp(newX, lowerBound, dim + upperBoundBias);
}
else
{
return Select(
x.Value < 0L,
(dim + x).ToExpr(),
Dimension.Clamp(x, lowerBound, dim + upperBoundBias).ToExpr());
var newX = Select(x.Value < 0L, (dim + x).ToExpr(), x.ToExpr());
return Dimension.Clamp(newX, lowerBound, dim + upperBoundBias);
}
}

Expand Down Expand Up @@ -160,7 +159,7 @@ private IRType Visit(ITypeInferenceContext context, Slice target, TensorType inp

// while for negative stepping it is clamped to [-1, dims[axes[i]]-1].
var end = TranslateBeginEnd(ends[i], inDim, -1, -1);
return Dimension.CeilDiv(end - begin, Dimension.Abs(stride));
return Dimension.CeilDiv(begin - end, Dimension.Abs(stride));
}
else
{
Expand Down

0 comments on commit 73dcee7

Please sign in to comment.