Problem
Functions returning tuples or NamedTuples fail with MethodError because to_array in src/trace_functions.jl doesn't handle these types.
MWE
using SparseConnectivityTracer
detector = TracerSparsityDetector()
# Tuple output fails
f_tuple(x) = (x[1]^2, x[2]^2)
jacobian_sparsity(f_tuple, [1.0, 2.0], detector)
# MethodError: no method matching to_array(::Tuple{GradientTracer...})
# NamedTuple output fails
f_nt(x) = (a=x[1]^2, b=x[2]^2)
jacobian_sparsity(f_nt, [1.0, 2.0], detector)
# MethodError: no method matching to_array(::NamedTuple...)
Expected behavior
These should work by collecting the tuple elements into an array:
to_array(x::Tuple) = collect(x)
to_array(x::NamedTuple) = collect(values(x))
Related
This is related to #298 (Better unpacking of output types) which mentions Rational/Complex types.
Problem
Functions returning tuples or NamedTuples fail with
MethodErrorbecauseto_arrayinsrc/trace_functions.jldoesn't handle these types.MWE
Expected behavior
These should work by collecting the tuple elements into an array:
Related
This is related to #298 (Better unpacking of output types) which mentions Rational/Complex types.