Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/cwise-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -44,4 +44,4 @@ function cwiseTransform(file, opts) {
}
})
return sm
}
}
2 changes: 1 addition & 1 deletion test/browserify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
42 changes: 42 additions & 0 deletions test/fill.js
Original file line number Diff line number Diff line change
@@ -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()
})