Skip to content

Commit

Permalink
Fix clamp rule when max < min
Browse files Browse the repository at this point in the history
  • Loading branch information
Pangoraw committed Jul 24, 2024
1 parent dba6cb5 commit a49ef5d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/rulesets/Base/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ end
islow = x < low,
ishigh = high < x,
),
(!(islow | ishigh), islow, ishigh),
(!(islow | ishigh), islow & (low < high), ishigh),
)
@scalar_rule x \ y (-/ x), one(y) / x)

Expand Down
4 changes: 4 additions & 0 deletions test/rulesets/Base/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ end
# to right
test_frule(clamp, 4., 2., 3.)
test_rrule(clamp, 4., 2., 3.)

# max < min
test_frule(clamp, 3., 4., 2.)
test_rrule(clamp, 3., 4., 2.)
end

@testset "rounding" begin
Expand Down

0 comments on commit a49ef5d

Please sign in to comment.