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

Skip to content

Commit 62ebaa4

Browse files
committed
.
0 parents  commit 62ebaa4

File tree

5 files changed

+404
-0
lines changed

5 files changed

+404
-0
lines changed

.gitignore

Lines changed: 16 additions & 0 deletions
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

LICENSE

Lines changed: 22 additions & 0 deletions
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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
ndarray-gradient
2+
================
3+
Computes the gradient of an ndarray using a 2-point central finite difference template.
4+
5+
# Example
6+
7+
```javascript
8+
var pack = require('ndarray-pack')
9+
var pool = require('ndarray-scratch')
10+
var grad = require('ndarray-gradient')
11+
var show = require('ndarray-show')
12+
13+
var X = pack([[0, 0, 0],
14+
[0, 1, 0],
15+
[0, 0, 0]])
16+
17+
//Compute gradient of X
18+
var dX = grad(pool.zero([3,3,2]), X)
19+
20+
console.log('grad(X) = \n', show(dX))
21+
```
22+
23+
Output:
24+
25+
```
26+
grad(X) =
27+
0.000 0.000 0.000
28+
-0.500 0.000 0.500
29+
0.000 0.000 0.000
30+
31+
0.000 -0.500 0.000
32+
0.000 0.000 0.000
33+
0.000 0.500 0.000
34+
```
35+
36+
# Install
37+
38+
```
39+
npm install ndarray-gradient
40+
```
41+
42+
# API
43+
44+
### `require('ndarray-gradient')(dst, src[, bc])`
45+
Computes the gradient of `src` storing the result into `dst`.
46+
47+
* `dst` is an array of gradient values. The shape of `dst` must be the shape of `src` with one additional dimension for the components of the gradient
48+
* `src` is the array to differentiate
49+
* `bc` is an array of boundary conditions. The boundary conditions are encoded as string values and must be one of the following values:
50+
51+
+ `'clamp'` (Default) clamp boundary edges to boundary
52+
+ `'mirror'` mirror values across the boundary
53+
+ `'wrap'` wrap values across boundary
54+
55+
**Returns** `dst`
56+
57+
# Credits
58+
(c) 2014 Mikola Lysenko. MIT License

example/example.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var pack = require('ndarray-pack')
2+
var pool = require('ndarray-scratch')
3+
var grad = require('../fdg')
4+
var show = require('ndarray-show')
5+
6+
var X = pack([[0, 0, 0],
7+
[0, 1, 1],
8+
[0, 0, 0]])
9+
10+
//Compute gradient of X
11+
var dX = grad(pool.zeros([3,3,2]), X, 'wrap')
12+
13+
console.log('X = \n', show(X))
14+
15+
console.log('grad(X) = \n', show(dX))

0 commit comments

Comments
 (0)