Using ForwardDiff.jl with BlockDiagonals.jl

I want to calcuate the jacobian for a vector calculated with the following function.

function test(A1, A2, x)

    A = BlockDiagonal([A1 * x, A2])
    return A * vcat(x, x)
    
end

However, when I calculate the jacobian with ForwardDiff.jacobian, I get an error.

J = ForwardDiff.jacobian((x) -> test(A1, A2, x), x)
ERROR: MethodError: no method matching BlockDiagonal(::Vector{Array})

How can I resolve this error?

You don’t gave a runnable example, so I have to guess.

Does your method work if you just call it directly test(A1, A2, x)? To me it looks like you erroneously multiply matrix A1 by vector x in the construction of the blovk-diagonal matrix A. This would explain the error as a [vector, matrix] ist of type Vector{Array} and indeed you need a Vector{Matrix} to construct a BlockDiagonal.