Skip to content

Commit af2f345

Browse files
authored
Added basic table literal support. Fixes #652 (#689)
1 parent f7499c4 commit af2f345

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/plugins/ImportTorch/nn.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ define([
3030
isSetting = false;
3131
};
3232

33+
var stringify = function(table) {
34+
var strings = table.array.map(val => {
35+
if (val instanceof lua.types.LuaTable) {
36+
return stringify(val);
37+
} else {
38+
return val;
39+
}
40+
});
41+
return '{' + strings.join(', ') + '}';
42+
};
43+
3344
var allConnectedTo = function(current) {
3445
var connectedIds = {},
3546
node,
@@ -131,7 +142,9 @@ define([
131142
core.setPointer(node, name, cntr);
132143
logger.debug(`Moving ${nodes.length} to ${name}(${this._base})`);
133144
} else { // Something like {1, 2, 3}
134-
logger.warn(`No support for tables as args yet... ${value}`);
145+
value = stringify(value);
146+
logger.debug(`Setting ${name} to ${value} (${this._base})`);
147+
core.setAttribute(node, name, value);
135148
}
136149
} else { // attribute value
137150
if ((typeof value) === 'object') {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
local net = nn.Sequential()
2+
net:add(nn.Transpose({ 1, 2 }))
3+
net:add(nn.Transpose({ {1, 2}, {3, 4} }))
4+
5+
return net;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
- type: Transpose
2+
id: /O/c
3+
next:
4+
- /O/j
5+
attributes:
6+
ctor_arg_order: params
7+
params: '{1, 2}'
8+
- type: Transpose
9+
id: /O/j
10+
next: []
11+
attributes:
12+
ctor_arg_order: params
13+
params: '{{1, 2}, {3, 4}}'

0 commit comments

Comments
 (0)