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

Skip to content

Commit 0ebe557

Browse files
committed
upgrade to ndarray 1.0
1 parent 87ea014 commit 0ebe557

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ Install
1919

2020
npm install pack
2121

22-
### `require("ndarray-pack")(nested_array[, dtype])`
22+
### `require("ndarray-pack")(nested_array)`
2323
Converts the nested array into a packed ndarray.
2424

2525
* `nested_array` is an array-of-arrays (ie a numeric.js array)
26-
* `dtype` is the data type of the packed ndarray. (Either, "uint8", "uint16", "uint32", "int8", "int16", "int32", "float" or "double")
2726

2827
**Returns** A packed ndarray representation of the nested arrays.
2928

convert.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use strict"
22

33
var ndarray = require("ndarray")
4-
var numeric = require("numeric")
54
var cwise = require("cwise")
65

76
var do_convert = cwise({
@@ -15,12 +14,17 @@ var do_convert = cwise({
1514
}
1615
})
1716

18-
module.exports = function convert(arr, dtype) {
19-
if(!dtype) {
20-
dtype = "float64"
17+
module.exports = function convert(arr) {
18+
var shape = [], c = arr, sz = 1
19+
while(c instanceof Array) {
20+
shape.push(c.length)
21+
sz *= c.length
22+
c = c[0]
2123
}
22-
var shape = numeric.dim(arr)
23-
var result = ndarray.zeros(shape, dtype)
24+
if(shape.length === 0) {
25+
return ndarray([])
26+
}
27+
var result = ndarray(new Float64Array(sz), shape)
2428
do_convert(result, arr)
2529
return result
26-
}
30+
}

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
{
22
"name": "ndarray-pack",
3-
"version": "0.0.1",
3+
"version": "1.0.0",
44
"description": "Packs an array-of-arrays into a single ndarray",
55
"main": "convert.js",
66
"directories": {
77
"test": "test"
88
},
99
"dependencies": {
10-
"cwise": "~0.1.2",
11-
"ndarray": "~0.2.1",
12-
"numeric": "~1.2.6"
10+
"cwise": "~0.3.2",
11+
"ndarray": "~1.0.0"
1312
},
1413
"devDependencies": {
1514
"tap": "~0.4.2"

0 commit comments

Comments
 (0)