Skip to content

Commit 1847ab0

Browse files
committed
updated readme, added sanity check for array sizes
1 parent 7915612 commit 1847ab0

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ ndarray-fft
22
===========
33
A fast Fourier transform implementation for [ndarrays](https://github.com/mikolalysenko/ndarray). You can use this to do image processing operations on big, higher dimensional typed arrays in JavaScript.
44

5-
**WORK IN PROGRESS**
6-
75
## Example
86

97
```javascript
@@ -21,12 +19,20 @@ fft(1, x, y)
2119
fft(-1, x, y)
2220
```
2321

22+
## Install
23+
Via npm:
24+
25+
npm install ndarray-fft
26+
27+
2428
### `require("ndarray-fft")(dir, x, y)`
2529
Executes a fast Fourier transform on the complex valued array x/y.
2630

2731
* `dir` - Either +/- 1. Determines whether to use a forward or inverse FFT
28-
* `x` the real part of the typed array
29-
* `y` the imaginary part of the typed array.
32+
* `x` the real part of the signal, encoded as an ndarray
33+
* `y` the imaginary part of the signal, encoded as an ndarray
34+
35+
`x` and `y` are transformed in place.
3036

3137
**Note** This code is fastest when the components of the shapes arrays are all powers of two. For non-power of two shapes, Bluestein's fft is used which is somewhat slower. Also note that this code clobbers [scratch](https://github.com/mikolalysenko/scratch) memory.
3238

fft.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ function ndfft(dir, x, y) {
1717
stride[i] = size
1818
size *= shape[i]
1919
pad = Math.max(pad, fftm.scratchMemory(shape[i]))
20+
if(x.shape[i] !== y.shape[i]) {
21+
throw new Error("Shape mismatch, real and imaginary arrays must have same size")
22+
}
2023
}
21-
2224
var buffer = scratch(4 * size + pad, "double")
2325
var x1 = ndarray(buffer, shape.slice(0), stride, 0)
2426
, y1 = ndarray(buffer, shape.slice(0), stride.slice(0), size)

0 commit comments

Comments
 (0)