新手求教,有关函数调用的问题
lua吧
全部回复
仅看楼主
level 1
365634450
楼主
请问调用函数中的nn.Identity后面为什么会有两个括号?
nn.Identity的定义如下:
2015年10月08日 13点10分
1
level 11
协调意志_Tox
可能nn.Identity()返回的是个函数
你这里没有写出你那图片和原文的关系
2015年10月08日 14点10分
2
365634450
你说的原文是table.insert(input,nn.Identity()())的原谅吗?我放到3楼了
2015年10月09日 01点10分
level 1
365634450
楼主
2015年10月09日 01点10分
3
level 1
365634450
楼主
2015年10月09日 01点10分
4
level 11
协调意志_Tox
已经确认nn.Identity()返回的是一个类的函数所以可以双括号
2015年10月09日 01点10分
6
365634450
THX,不过你是怎么看出来返回值是一个函数的
2015年10月09日 08点10分
协调意志_Tox
@365634450
这不是很简单吗
2015年10月09日 08点10分
365634450
@协调意志_Tox
刚开始学,不太懂....
2015年10月09日 09点10分
level 8
ks_isaf
我猜nn.Identity返回的是一个table,这个table有call元方法,所以可以使用()。详情请看参考手册关于metatable和metamethod这一节。
2015年10月09日 09点10分
7
365634450
THX,我去看看
2015年10月09日 10点10分
协调意志_Tox
古尸复活记
2015年10月09日 15点10分
365634450
wen ti jie jue le,xie xie
2015年10月10日 02点10分
level 1
365634450
楼主
th>module = nn.Identity()
th>getmetatable(module)
nn.Module
2015年10月10日 02点10分
9
level 1
365634450
楼主
local Module = torch.class('nn.Module')
function Module:__call__(input, gradOutput)
self:forward(input)
if gradOutput then
self:backward(input, gradOutput)
return self.output, self.gradInput
else return self.output
end
end
2015年10月10日 02点10分
10
1