Skip to content

Implementation of Dual for NaNMath.pow does not use NaNMath.log #716

Closed
@jClugstor

Description

@jClugstor

I would expect this:

using ForwardDiff
using NaNMath

function new_pow(x)
    NaNMath.pow(x[1],x[2])
end

ForwardDiff.gradient(new_pow, [-1.0, 1.0])

to return a NaN I think?

The issue is right here,

for f in (:(Base.:^), :(NaNMath.pow))
    @eval begin
        @define_binary_dual_op(
            $f,
            begin
                vx, vy = value(x), value(y)
                expv = ($f)(vx, vy)
                powval = vy * ($f)(vx, vy - 1)
                if isconstant(y)
                    logval = one(expv)
                elseif iszero(vx) && vy > 0
                    logval = zero(vx)
                else
                    logval = expv * log(vx)
                end
                new_partials = _mul_partials(partials(x), partials(y), powval, logval)
                return Dual{Txy}(expv, new_partials)
            end,

in logval = expv*log(vx) , I think NaNMath.log should be used if f is NaNMath.pow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions