Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9755f54
Showing
6 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
lib-cov | ||
*.seed | ||
*.log | ||
*.csv | ||
*.dat | ||
*.out | ||
*.pid | ||
*.gz | ||
|
||
pids | ||
logs | ||
results | ||
|
||
npm-debug.log | ||
node_modules/* | ||
*.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
lib-cov | ||
*.seed | ||
*.log | ||
*.csv | ||
*.dat | ||
*.out | ||
*.pid | ||
*.gz | ||
|
||
pids | ||
logs | ||
results | ||
|
||
npm-debug.log | ||
node_modules/* | ||
*.DS_Store | ||
test/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
The MIT License (MIT) | ||
|
||
Copyright (c) 2013 Mikola Lysenko | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
ndarray-unpack | ||
============== | ||
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. | ||
|
||
## Example | ||
|
||
```javascript | ||
//Create an ndarray and set a value | ||
var x = require("zeros")([5,5]) | ||
x.set(2,2,1) | ||
|
||
//Convert ndarray into array-of-arrays | ||
console.log(require("unpack")(x)) | ||
``` | ||
|
||
## Install | ||
|
||
npm install ndarray-unpack | ||
|
||
### `require("ndarray-unpack")(array)` | ||
Converts `array` into an array-of-arrays style array. | ||
|
||
* `array` is an ndarray | ||
|
||
**Returns** An array-of-arrays having the same contents as `array` | ||
|
||
## Credits | ||
(c) 2013 Mikola Lysenko. MIT License |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var zeros = require("zeros") | ||
var unpack = require("../unpack.js") | ||
|
||
require("tape")("ndarray-unpack", function(t) { | ||
|
||
var x = zeros([5,5]) | ||
x.set(2,3,1) | ||
|
||
t.same(unpack(x), [[0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 0], | ||
[0, 0, 0, 1, 0], | ||
[0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 0]]) | ||
|
||
t.end() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"use strict" | ||
|
||
var dup = require("dup") | ||
var cwise = require("cwise") | ||
|
||
var do_unpack = cwise({ | ||
args: ["array", "scalar", "index"], | ||
body: function unpack(arr, a, idx) { | ||
var v = a | ||
for(var i=0; i<idx.length-1; ++i) { | ||
v = v[idx[i]] | ||
} | ||
v[idx[idx.length-1]] = arr | ||
} | ||
}) | ||
|
||
module.exports = function unpack(arr) { | ||
var result = dup(arr.shape) | ||
do_unpack(arr, result) | ||
return result | ||
} |