8000 `*` transformed to `.*` for scalars · Issue #2 · dfdx/XDiff.jl · GitHub
[go: up one dir, main page]

Skip to content

* transformed to .* for scalars #2

@Evizero

Description

@Evizero

I am playing around with Espresso and XDiff, because I think it would be cool for some future version of LossFunctions.jl to generate all the losses, their derivatives, and their properties just based on defining the function (like @makeloss L(x) = 1/2 * x^2)

Taking the example of a simple popular version of the least squares loss L(x) = 1/2 * x^2, I found that rdiff changes the operation * to the broadcasted version .* which seems to prevent constant folding

julia> using Espresso, XDiff

julia> rdiff(:(1/2 * x^2), x=1.)
Dict{Symbol,Expr} with 1 entry:
  :x => :(0.5 .* (2x))

julia> simplify(:(0.5 .* (2x)))
:(0.5 .* (2x))

julia> simplify(:(0.5 * (2x)))
:x

Is this expected behaviour? How would you suggest to deal with such cases?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0