Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dense_ad(backend::AutoSparse{<:AutoSymbolics}) = ADTypes.dense_ad(backend)

variablize(::Number, name::Symbol) = variable(name)
variablize(x::AbstractArray, name::Symbol) = variables(name, axes(x)...)
variablize(::T, name::Symbol) where {T} = variable(name; T)

function variablize(contexts::NTuple{C, DI.Context}) where {C}
return ntuple(Val(C)) do k
Expand Down
20 changes: 20 additions & 0 deletions DifferentiationInterface/test/Back/Symbolics/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,23 @@ test_differentiation(
@test sparsity_pattern(jac!_prep) == Diagonal(trues(10))
@test sparsity_pattern(hess_prep) == Diagonal(trues(10))
end

@testset "Non-numeric arguments" begin
function differentiate_me!(out, x, c)
@assert c isa Any # Just to use it somewhere
return copyto!(out, x)
end
function differentiate_me(x, c)
tmp = similar(x)
differentiate_me!(tmp, x, c)
return tmp
end
x = rand(10)
xbuffer = copy(x)
c = "I am a string"
backend = AutoSymbolics()
jac_prep = prepare_jacobian(differentiate_me, backend, x, Constant(c))
jac!_prep = prepare_jacobian(differentiate_me!, xbuffer, backend, x, Constant(c))
@test jacobian(differentiate_me, jac_prep, backend, x, Constant(c)) ≈ I
@test jacobian(differentiate_me!, xbuffer, jac!_prep, backend, x, Constant(c)) ≈ I
end
Loading