From 3fe6bc8a0e29efac0c025f56dd3781dbe996d248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Mon, 13 Mar 2017 17:26:21 -0400 Subject: [PATCH] compress compiled block using { unsued: "keep_assign" } - this fixes browserify-transformed ndarray-fill with uglify-js@2.8.x - see https://github.com/mishoo/UglifyJS2/pull/1450/files for more details - add test --- lib/cwise-transform.js | 4 ++-- test/browserify.js | 2 +- test/fill.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 test/fill.js diff --git a/lib/cwise-transform.js b/lib/cwise-transform.js index 1c0537a..93cf7bb 100644 --- a/lib/cwise-transform.js +++ b/lib/cwise-transform.js @@ -11,7 +11,7 @@ var OPTIONAL_FIELDS = [ "pre", "post", "printCode", "funcName", "blockSize" ] function processFunc(func) { var codeStr = "var X=" + func - var minified = uglify.minify(codeStr, {fromString: true}).code + var minified = uglify.minify(codeStr, {fromString: true, compress: { unused: "keep_assign" }}).code var code = minified.substr(6, minified.length-7) return parse(code) } @@ -44,4 +44,4 @@ function cwiseTransform(file, opts) { } }) return sm -} \ No newline at end of file +} diff --git a/test/browserify.js b/test/browserify.js index 88410db..e00a1cd 100644 --- a/test/browserify.js +++ b/test/browserify.js @@ -5,7 +5,7 @@ var vm = require("vm") var path = require("path") var tape = require("tape") -var cases = [ "unary", "binary", "offset" ] +var cases = [ "unary", "binary", "offset", "fill" ] bundleCasesFrom(0) diff --git a/test/fill.js b/test/fill.js new file mode 100644 index 0000000..10672b5 --- /dev/null +++ b/test/fill.js @@ -0,0 +1,42 @@ +var cwise = require("cwise") +var ndarray = require("ndarray") + +if(typeof test === "undefined") { + test = require("tape") +} + +test("fill", function(t) { + + var fill = cwise({ + args: ["index", "array", "scalar"], + body: function(idx, out, f) { + out = f.apply(undefined, idx) + } + }) + + var xlen = 10 + var ylen = 5 + var array = ndarray(new Float32Array(xlen * ylen), [xlen, ylen]) + + fill(array, function(row, col) { + return 0 + }) + + for(var i = 0; i < xlen; i++) { + for(var j = 0; j < ylen; j++) { + t.equals(array.get(i, j), 0, 'fill ('+ i + ',' + j + ')') + } + } + + fill(array, function(row, col) { + return 10 * (row + col) + }) + + for(var i = 0; i < xlen; i++) { + for(var j = 0; j < ylen; j++) { + t.equals(array.get(i, j), 10 * (i + j), 'fill ('+ i + ',' + j + ')') + } + } + + t.end() +})