AutoGrad.jl
AutoGrad.jl copied to clipboard
cannot take derivative of a scalar function
See https://github.com/denizyuret/Knet.jl/issues/410
This turned out to be tough nut to crack: it has to do with broadcast multiplying a Result{Array} with an Array{Any} that has Result's in it. I am not sure this code does anything useful but it certainly proved useful as a test case. @ekinakyurek where did you find this code and what is it supposed to compute?
This the forward part of my code for calculating gradients via backslash. I was just trying to benchmark it with AutoGrad, then I got this message.
On Sat, Jan 5, 2019 at 5:16 AM denizyuret [email protected] wrote:
This turned out to be tough nut to crack: it has to do with broadcast multiplying a Result{Array} with an Array{Any} that has Result's in it. I am not sure this code does anything useful but it certainly proved useful as a test case. @ekinakyurek https://github.com/ekinakyurek where did you find this code and what is it supposed to compute?
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/denizyuret/AutoGrad.jl/issues/106#issuecomment-451619783, or mute the thread https://github.com/notifications/unsubscribe-auth/AOpr8YTMIDT47N_U1RMCMVRBlaVbVbC6ks5vAAsKgaJpZM4ZcNZ_ .
I am not sure if that is exactly the same problem, but gives "AssertionError: Only scalar valued functions supported." with the code below.
using CuArrays
using AutoGrad
a= Param([cu(rand(4,1)) for i=1:4])
f(x) = (maximum.(a)).^2
@show f(a)
dvals = @diff f(a)
parameters = collect(params(dvals))
map(x->grad(dvals, x),parameters)
The plot of F(t) runs. But Fd(t) can not run. I see the same error (AssertionError: Only scalar valued functions supported.)
using Knet, Plots F(t) = sin.(t) Fd = grad(F)
t=0:0.1:2*3.14 plot(F(t)) plot(Fd(t))
To take the grad of F, F should return a scalar value. Then you can apply broadcasted version of both F and Fd on t.
using Knet, Plots
F(t) = sin(t)
Fd = grad(F)
t=0:0.1:2*3.14
plot(F.(t))
plot(Fd.(t))
Thank you very much Ozan. The answer is true.