jacobian allocates its result with chunksize(cfg) columns, which is structural_length(x), but reshape_jacobian reshapes it to length(xdual) columns. For inputs whose structural length differs from their length the two disagree, so chunk mode always throws while vector mode works.
julia> using ForwardDiff, LinearAlgebra
julia> g(z) = [sum(z), sum(abs2, z)];
julia> x = UpperTriangular(rand(3, 3));
julia> size(ForwardDiff.jacobian(g, x)) # vector mode
(2, 6)
julia> ForwardDiff.jacobian(g, x, ForwardDiff.JacobianConfig(g, x, ForwardDiff.Chunk{2}()))
ERROR: DimensionMismatch: new dimensions (2, 9) must be consistent with array length 12
All three wrapper types, only the full-length chunk survives:
| input |
chunk=1 |
chunk=2 |
chunk=structural_length(x) |
UpperTriangular(rand(3,3)) |
DimensionMismatch |
DimensionMismatch |
(2, 6) |
LowerTriangular(rand(3,3)) |
DimensionMismatch |
DimensionMismatch |
(2, 6) |
Diagonal(rand(3,3)) |
DimensionMismatch |
DimensionMismatch |
(2, 3) |
Since Chunk(x) picks the full structural length for anything up to DEFAULT_CHUNK_THRESHOLD, this only shows up for larger inputs or an explicit Chunk. Introduced in #739.
Worth deciding the column convention at the same time: jacobian currently uses structural columns while gradient returns a result shaped like x. See the discussion in #837, where I argued for indexing the Hessian by the linear indices of x on both axes.
ForwardDiff v1.4.5, Julia 1.12.6.
jacobianallocates its result withchunksize(cfg)columns, which isstructural_length(x), butreshape_jacobianreshapes it tolength(xdual)columns. For inputs whose structural length differs from their length the two disagree, so chunk mode always throws while vector mode works.All three wrapper types, only the full-length chunk survives:
structural_length(x)UpperTriangular(rand(3,3))DimensionMismatchDimensionMismatch(2, 6)LowerTriangular(rand(3,3))DimensionMismatchDimensionMismatch(2, 6)Diagonal(rand(3,3))DimensionMismatchDimensionMismatch(2, 3)Since
Chunk(x)picks the full structural length for anything up toDEFAULT_CHUNK_THRESHOLD, this only shows up for larger inputs or an explicitChunk. Introduced in #739.Worth deciding the column convention at the same time:
jacobiancurrently uses structural columns whilegradientreturns a result shaped likex. See the discussion in #837, where I argued for indexing the Hessian by the linear indices ofxon both axes.ForwardDiff v1.4.5, Julia 1.12.6.