Skip to content

Commit

Permalink
WIP #541 Added check for class method match
Browse files Browse the repository at this point in the history
  • Loading branch information
brollb committed Jul 26, 2016
1 parent ec1a693 commit 0717598
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
20 changes: 11 additions & 9 deletions src/common/layer-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@
return null;
};

var isSetterMethod = function(curr, parent){
var isSetterMethod = function(curr, parent, className){
if (parent && parent.type === 'stat.method') {
// is it a fn w/ two statements (stats)
if (curr.type === 'function' && curr.block.stats.length === 2) {
if (parent.self.val === className && curr.type === 'function' &&
curr.block.stats.length === 2) {
// Is the first statement setting a value?
return returnsSelf(curr) && getSettingAttrName(curr.block.stats[0]); // does it return itself?
}
Expand Down Expand Up @@ -125,21 +126,22 @@
luajs.codegen.traverse((curr, parent) => {
var firstLine,
schema,
name;
attrName;

if (isSetterMethod(curr, parent)) {
if (isSetterMethod(curr, parent, name)) {
firstLine = curr.block.stats[0];
// just use the attribute name for now...
name = getSettingAttrName(firstLine);
// just use the attribute attrName for now...
attrName = getSettingAttrName(firstLine);

// merge schemas
schema = getSetterSchema(firstLine, parent);
if (setters[name] && setters[name].setterType === 'const') { // merge
if (setters[attrName] && setters[attrName].setterType === 'const') { // merge
for (var val in schema.setterFn) {
setters[name].setterFn[val] = schema.setterFn[val];
setters[attrName].setterFn[val] = schema.setterFn[val];
}
// TODO: Get the default value
} else {
setters[name] = schema;
setters[attrName] = schema;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/layers.json
Original file line number Diff line number Diff line change
Expand Up @@ -1490,4 +1490,4 @@
"setters": {},
"type": "Criterion"
}
]
]
1 change: 0 additions & 1 deletion utils/nn-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ fs.readdir(torchPath, function(err,files){
layerByName = {};

layers = files.filter(filename => path.extname(filename) === '.lua')
//.filter(filename => filename === 'SpatialMaxPooling.lua')
.map(filename => fs.readFileSync(torchPath + filename, 'utf8'))
.map(code => LayerParser.parse(code))
.filter(layer => !!layer && layer.name);
Expand Down

0 comments on commit 0717598

Please sign in to comment.