adrhill / SparseConnectivityTracer.jl

Fast operator-overloading Jacobian & Hessian sparsity detection.
MIT License
26 stars 2 forks source link

Add support for `round` #152

Closed SouthEndMusic closed 1 month ago

SouthEndMusic commented 1 month ago

I tried to make a MWE for this, but I came across a different problem:

using SparseConnectivityTracer: TracerLocalSparsityDetector, jacobian_sparsity
using DataInterpolations: LinearInterpolation
detector = TracerLocalSparsityDetector()
A = LinearInterpolation([0.0, 2.0], [0.0, 2.0])

function f!(output, input)
    output .= A.(input)
end

input = rand(5)
output = zero(input)

jacobian_sparsity(f!, output, input, detector)

This gives

MethodError: no method matching round(::Type{Int64}, ::SparseConnectivityTracer.Dual{Float64, SparseConnectivityTracer.GradientTracer{…}})

This is by the way because the searching method within ordered vector used by FindFirstFunctions depends on the way that vector is distributed.

adrhill commented 1 month ago

This is fixed in #162, however the next method error pops up in FindFirstFunctions.jl:

julia> jacobian_sparsity(f!, output, input, detector)
ERROR: MethodError: no method matching searchsortedlastcorrelated(::Vector{…}, ::SparseConnectivityTracer.Dual{…}, ::SparseConnectivityTracer.Dual{…})

Closest candidates are:
  searchsortedlastcorrelated(::T, ::Any, ::FindFirstFunctions.Guesser{T}) where T<:(AbstractVector)
   @ FindFirstFunctions ~/.julia/packages/FindFirstFunctions/2w5qZ/src/FindFirstFunctions.jl:284
  searchsortedlastcorrelated(::AbstractVector, ::Any, ::T) where T<:Integer
   @ FindFirstFunctions ~/.julia/packages/FindFirstFunctions/2w5qZ/src/FindFirstFunctions.jl:265
  searchsortedlastcorrelated(::AbstractRange, ::Any, ::Integer)
   @ FindFirstFunctions ~/.julia/packages/FindFirstFunctions/2w5qZ/src/FindFirstFunctions.jl:271

Stacktrace:
  [1] get_idx(A::LinearInterpolation{…}, t::SparseConnectivityTracer.Dual{…}, iguess::Int64; lb::Int64, ub_shift::Int64, idx_shift::Int64, side::Symbol)
    @ DataInterpolations ~/.julia/packages/DataInterpolations/i1xgb/src/interpolation_utils.jl:133
adrhill commented 1 month ago

We'll soon to write a guide on how to extend your own methods on tracers (see #163). This should allow you to support searchsortedlastcorrelated.