小编san*_*ter的帖子

Lua中的()()语法是否有特殊含义

我在最近阅读的一些Lua源文件中看到了这种类型的语法,这是什么意思,特别是第二对括号一个例子,在https://github.com/karpathy/char-rnn/blob中的第8行 /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
  -- ...
Run Code Online (Sandbox Code Playgroud)

https://github.com/torch/nn/blob/master/Identity.lua的源代码nn.Identity

**********更新**************

()()模式在火炬库'nn'中使用了很多.第一对括号创建容器/节点的对象,第二对括号引用依赖节点.

例如,y = nn.Linear(2,4)(x)表示x连接到y,并且变换是从1*2到1*4的线性.我只是理解它的用法,它的连接方式似乎可以通过下面的答案之一来回答.

无论如何,接口的使用在下面有详细记录. https://github.com/torch/nngraph/blob/master/README.md

lua torch

17
推荐指数
2
解决办法
1892
查看次数

标签 统计

lua ×1

torch ×1