Lua中的()()语法有什么特别的含义吗?
我最近在一些Lua源文件中看到这种类型的语法,这是什么意思,特别是第二对括号
一个例子,第8行 https://github.com/karpathy/char-rnn/blob/master/model/LSTM.lua local LSTM = {} function LSTM.lstm(input_size,rnn_size,n,dropout) dropout = dropout or 0 -- there will be 2*n+1 inputs local inputs = {} table.insert(inputs,nn.Identity()()) -- line 8 -- ... nn.Identity的源代码 **********更新************** ()()模式在火炬库’nn’中使用很多.第一对括号创建容器/节点的对象,第二对括号引用依赖节点. 例如,y = nn.Linear(2,4)(x)表示x连接到y,并且变换从1 * 2到1 * 4是线性的. 无论如何,界面的使用在下面有很好的记录. 解决方法
补充余浩的答案让我给出一些火炬相关的精神:
> nn.Identity()创建一个身份模块, 因此,每个nn.Identity()()调用都有效果返回一个nngraph.Node({module = self})节点,其中self指向当前的nn.Identity()实例. – 更新:可以在LSTM-s的上下文中找到此语法的图示here: local i2h = nn.Linear(input_size,4 * rnn_size)(input) -- input to hidden
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |