Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clamp gives TypeError from julia 1.11 #207

Closed
visr opened this issue Oct 20, 2024 · 3 comments · Fixed by #208
Closed

clamp gives TypeError from julia 1.11 #207

visr opened this issue Oct 20, 2024 · 3 comments · Fixed by #208
Labels
new overloads A new method on tracers is required by a user.

Comments

@visr
Copy link

visr commented Oct 20, 2024

using SparseConnectivityTracer
detector = TracerSparsityDetector()
jacobian_sparsity(x -> clamp!(x, 0.1, 0.9), rand(3), detector)

On Julia 1.10.5 this gives:

3×3 SparseArrays.SparseMatrixCSC{Bool, Int64} with 3 stored entries:
 1  ⋅  ⋅
 ⋅  1  ⋅
 ⋅  ⋅  1

But on Julia 1.11 and nightly it gives:

ERROR: TypeError: non-boolean (SparseConnectivityTracer.GradientTracer{SparseConnectivityTracer.IndexSetGradientPattern{Int64, BitSet}}) used in boolean context
Stacktrace:
 [1] clamp(x::SparseConnectivityTracer.GradientTracer{…}, lo::Float64, hi::Float64)
   @ Base .\intfuncs.jl:1266
 [2] clamp!
   @ .\intfuncs.jl:1322 [inlined]
 [3] (::var"#237#238")(x::Vector{SparseConnectivityTracer.GradientTracer{…}})
   @ Main .\REPL[33]:1
 [4] trace_function(::Type{SparseConnectivityTracer.GradientTracer{…}}, f::var"#237#238", x::Vector{Float64})
   @ SparseConnectivityTracer C:\Users\visser_mn\.julia\dev\SparseConnectivityTracer\src\trace_functions.jl:47
 [5] _jacobian_sparsity(f::Function, x::Vector{Float64}, ::Type{SparseConnectivityTracer.GradientTracer{…}})
   @ SparseConnectivityTracer C:\Users\visser_mn\.julia\dev\SparseConnectivityTracer\src\trace_functions.jl:73
 [6] jacobian_sparsity(f::Function, x::Vector{…}, ::TracerSparsityDetector{…})
   @ SparseConnectivityTracer C:\Users\visser_mn\.julia\dev\SparseConnectivityTracer\src\adtypes_interface.jl:56
 [7] top-level scope
   @ REPL[33]:1

I suspect the reason is moving clamp from isless on 1.10 to the ternary operator on 1.11.
This was changed in JuliaLang/julia#54038.

@adrhill adrhill added the new overloads A new method on tracers is required by a user. label Oct 21, 2024
@adrhill
Copy link
Owner

adrhill commented Oct 21, 2024

Thanks, this is definitely a function SCT should support.
So far, we haven't covered many three-argument functions, but this one should be doable.

@adrhill
Copy link
Owner

adrhill commented Oct 21, 2024

I tagged a v0.6.8 release which includes support for clamp and clamp!.

@visr
Copy link
Author

visr commented Oct 21, 2024

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new overloads A new method on tracers is required by a user.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants