Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 87ea014

Browse files
committed
bug fix
1 parent 5c89278 commit 87ea014

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

convert.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ var numeric = require("numeric")
55
var cwise = require("cwise")
66

77
var do_convert = cwise({
8-
args: ["array", "index", "scalar"],
9-
body: function(out, idx, a) {
8+
args: ["array", "scalar", "index"],
9+
body: function(out, a, idx) {
1010
var v = a
1111
for(var i=0; i<idx.length-1; ++i) {
12-
v = a[idx[i]]
12+
v = v[idx[i]]
1313
}
1414
out = v[idx[idx.length-1]]
1515
}
1616
})
1717

1818
module.exports = function convert(arr, dtype) {
19-
if(dtype === undefined) {
19+
if(!dtype) {
2020
dtype = "float64"
2121
}
2222
var shape = numeric.dim(arr)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ndarray-pack",
3-
"version": "0.0.0",
3+
"version": "0.0.1",
44
"description": "Packs an array-of-arrays into a single ndarray",
55
"main": "convert.js",
66
"directories": {

test/test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ require("tap").test("ndarray-pack", function(t) {
1414
t.equals(y.get(i,j), x[i][j])
1515
}
1616
}
17+
18+
var x = [[[1, 2]], [[3,4]], [[5,6]]]
19+
var y = require("../convert.js")(x)
20+
21+
t.equals(y.shape.join(","), "3,1,2")
22+
t.equals(y.get(0, 0, 0), 1)
1723

1824
t.end()
1925
})

0 commit comments

Comments
 (0)