Skip to content

Commit d7f48f2

Browse files
committed
small tweaks, handle edge cases
1 parent fb45a7b commit d7f48f2

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

fdg.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ function generateGradient(boundaryConditions) {
257257
linkArgs.push(generateTemplate(i))
258258
}
259259
linkNames.push(code.join(''))
260-
260+
261261
var link = Function.apply(void 0, linkNames)
262262
var proc = link.apply(void 0, linkArgs)
263263
TEMPLATE_CACHE[token] = proc
@@ -288,6 +288,10 @@ function gradient(out, inp, bc) {
288288
if(inp.size === 0) {
289289
return out
290290
}
291+
if(inp.dimension === 0) {
292+
out.set(0)
293+
return out
294+
}
291295
var cached = generateGradient(bc)
292296
return cached(out, inp)
293297
}

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
"ndarray": "^1.0.15",
1616
"ndarray-pack": "^1.1.1",
1717
"ndarray-scratch": "^1.1.1",
18-
"ndarray-show": "^1.1.0"
18+
"ndarray-show": "^1.1.0",
19+
"tape": "^3.0.0",
20+
"ndarray-unpack": "^1.0.0"
1921
},
2022
"scripts": {
2123
"test": "tape test/*.js"

test/test.js

+4
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,9 @@ tape('ndarray-gradient', function(t) {
2626
t.same(g([1,2], 'clamp'), [[-0.5, -0.5]])
2727
t.same(g([1,2], 'mirror'), [[0,0]])
2828

29+
t.same(g([[1,2,3]], 'wrap'), [[[0,0,0]],[[0.5, -1, 0.5]]])
30+
t.same(g([[1,2,3]], 'clamp'), [[[0,0,0]],[[-0.5,-1, -0.5]]])
31+
t.same(g([[1,2,3]], 'mirror'), [[[0,0,0]],[[0, -1, 0]]])
32+
2933
t.end()
3034
})

0 commit comments

Comments
 (0)