Skip to content

Commit 9755f54

Browse files
committed
adding files
0 parents  commit 9755f54

File tree

6 files changed

+120
-0
lines changed

6 files changed

+120
-0
lines changed

.gitignore

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
lib-cov
2+
*.seed
3+
*.log
4+
*.csv
5+
*.dat
6+
*.out
7+
*.pid
8+
*.gz
9+
10+
pids
11+
logs
12+
results
13+
14+
npm-debug.log
15+
node_modules/*
16+
*.DS_Store

.npmignore

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
lib-cov
2+
*.seed
3+
*.log
4+
*.csv
5+
*.dat
6+
*.out
7+
*.pid
8+
*.gz
9+
10+
pids
11+
logs
12+
results
13+
14+
npm-debug.log
15+
node_modules/*
16+
*.DS_Store
17+
test/*

LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2013 Mikola Lysenko
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.

README.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
ndarray-unpack
2+
==============
3+
Converts an [ndarray](https://github.com/mikolalysenko/ndarray) into an array-of-native-arrays. (Same format used by [numeric.js](http://www.numericjs.com/)). Like all ndarray modules this works both in node.js and in the browser.
4+
5+
## Example
6+
7+
```javascript
8+
//Create an ndarray and set a value
9+
var x = require("zeros")([5,5])
10+
x.set(2,2,1)
11+
12+
//Convert ndarray into array-of-arrays
13+
console.log(require("unpack")(x))
14+
```
15+
16+
## Install
17+
18+
npm install ndarray-unpack
19+
20+
### `require("ndarray-unpack")(array)`
21+
Converts `array` into an array-of-arrays style array.
22+
23+
* `array` is an ndarray
24+
25+
**Returns** An array-of-arrays having the same contents as `array`
26+
27+
## Credits
28+
(c) 2013 Mikola Lysenko. MIT License

test/test.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var zeros = require("zeros")
2+
var unpack = require("../unpack.js")
3+
4+
require("tape")("ndarray-unpack", function(t) {
5+
6+
var x = zeros([5,5])
7+
x.set(2,3,1)
8+
9+
t.same(unpack(x), [[0, 0, 0, 0, 0],
10+
[0, 0, 0, 0, 0],
11+
[0, 0, 0, 1, 0],
12+
[0, 0, 0, 0, 0],
13+
[0, 0, 0, 0, 0]])
14+
15+
t.end()
16+
})

unpack.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"use strict"
2+
3+
var dup = require("dup")
4+
var cwise = require("cwise")
5+
6+
var do_unpack = cwise({
7+
args: ["array", "scalar", "index"],
8+
body: function unpack(arr, a, idx) {
9+
var v = a
10+
for(var i=0; i<idx.length-1; ++i) {
11+
v = v[idx[i]]
12+
}
13+
v[idx[idx.length-1]] = arr
14+
}
15+
})
16+
17+
module.exports = function unpack(arr) {
18+
var result = dup(arr.shape)
19+
do_unpack(arr, result)
20+
return result
21+
}

0 commit comments

Comments
 (0)