diff options
author | Li Dong <donglixp@gmail.com> | 2016-02-21 01:45:56 +0300 |
---|---|---|
committer | Li Dong <donglixp@gmail.com> | 2016-02-21 01:45:56 +0300 |
commit | 5b10f21694cc07ab359c01061ac44b23c5469745 (patch) | |
tree | d195e69418f6cc3f9db16c14d2fa495e4992a9b5 | |
parent | c4c42770c33048ef2fb31a6e10c134485b4af75e (diff) |
checkgrad.lua: tensor type bug
When the _,dC = opfunc(x) is a gpu tensor, there will be an error:
/bin/luajit: bad argument #2 to '?' (number expected, got userdata)
stack traceback:
[C]: at 0x7fc541dc8040
[C]: in function '__sub'
This is fixed by ``local dC_est = torch.Tensor():typeAs(dC):resizeAs(dC)'' which ensures dC_est and dC have the same tensor type.
-rw-r--r-- | checkgrad.lua | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/checkgrad.lua b/checkgrad.lua index 6ab200e..aecb969 100644 --- a/checkgrad.lua +++ b/checkgrad.lua @@ -25,7 +25,7 @@ function optim.checkgrad(opfunc, x, eps) -- compute numeric approximations to gradient: local eps = eps or 1e-7 - local dC_est = torch.DoubleTensor(dC:size()) + local dC_est = torch.Tensor():typeAs(dC):resizeAs(dC) for i = 1,dC:size(1) do x[i] = x[i] + eps local C1 = opfunc(x) |