Skip to content

Commit

Permalink
adding files
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolalysenko committed Jun 26, 2013
0 parents commit 9755f54
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .gitignore
@@ -0,0 +1,16 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results

npm-debug.log
node_modules/*
*.DS_Store
17 changes: 17 additions & 0 deletions .npmignore
@@ -0,0 +1,17 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results

npm-debug.log
node_modules/*
*.DS_Store
test/*
22 changes: 22 additions & 0 deletions LICENSE
@@ -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.
28 changes: 28 additions & 0 deletions README.md
@@ -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
16 changes: 16 additions & 0 deletions test/test.js
@@ -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()
})
21 changes: 21 additions & 0 deletions unpack.js
@@ -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
}

0 comments on commit 9755f54

Please sign in to comment.