-
Notifications
You must be signed in to change notification settings - Fork 64
Closed
Labels
Structural TangentRelated to the `Tangent` type for structured (composite) valuesRelated to the `Tangent` type for structured (composite) valuesdocumentationImprovements or additions to documentationImprovements or additions to documentation
Description
Why is scaling a Tangent by an array allowed?
julia> Tangent{Any}(a=5, b=0) * [1 2; 3 4]
Tangent{Any}(a = [5 10; 15 20], b = [0 0; 0 0])Scaling by a number I understand. But shouldn't - also work?
julia> (a=10, b=20) + 0.1 * Tangent{NamedTuple}(a=5, b=0)
(a = 10.5, b = 20.0)
julia> (a=10, b=20) - 0.1 * Tangent{NamedTuple}(a=5, b=0)
ERROR: MethodError: no method matching -(::NamedTuple{(:a, :b), Tuple{Int64, Int64}}, ::Tangent{NamedTuple, NamedTuple{(:a, :b), Tuple{Float64, Float64}}})
julia> -Tangent{Any}(a=5, b=0)
ERROR: MethodError: no method matching -(::Tangent{Any, NamedTuple{(:a, :b), Tuple{Int64, Int64}}})Even better would be to fuse these updates -- if I understand right, 0.1 * Tangent will allocate a new copy of any arrays inside. But ideally something like this would be one pass over everything:
julia> (a=10, b=20) .+ 0.1 .* Tangent{NamedTuple}(a=5, b=0)
ERROR: ArgumentError: broadcasting over dictionaries and `NamedTuple`s is reservedMetadata
Metadata
Assignees
Labels
Structural TangentRelated to the `Tangent` type for structured (composite) valuesRelated to the `Tangent` type for structured (composite) valuesdocumentationImprovements or additions to documentationImprovements or additions to documentation