Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more precise typing #29

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions .eslintrc.js

This file was deleted.

20 changes: 20 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"root": true,
"env": { "browser": true, "es2020": true },
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"ignorePatterns": ["dist", ".eslintrc.js", ".prettierrc.js"],
"parser": "@typescript-eslint/parser",
"rules": {
"indent": ["error", 2],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "single"],
"semi": ["error", "always"],
"no-var": ["off"]
},
"ignorePatterns": ["**/node_modules/", ".eslintrc.json", "/dist/*"],
"settings": {
"react": {
"version": "detect"
}
}
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ npm-debug.log
*.log
*.pdf
*.gz
*.lock
.DS_Store
package-lock.json
*.lock
54 changes: 26 additions & 28 deletions bench/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
'use strict';
import FFT from '../dist/fft.js';
import jensnockert from 'fft';
import dspjs from 'dsp.js';
import drom from 'fourier';
import fourierTransform from 'fourier-transform';
import benchmark from 'benchmark';

const FFT = require('../');
const external = {
jensnockert: require('fft'),
dspjs: require('dsp.js'),
drom: require('fourier'),
fourierTransform: require('fourier-transform')
jensnockert,
dspjs,
drom,
fourierTransform,
};
const benchmark = require('benchmark');

function regexFilter(value) {
if (value !== undefined && value.length !== 0)
return new RegExp(value, 'ig');
else
return /./g;
if (value !== undefined && value.length !== 0) return new RegExp(value, 'ig');
else return /./g;
}

/*eslint-disable no-undef */
Expand All @@ -22,16 +23,14 @@ const filter1 = regexFilter(process.argv[3]);
/*eslint-enable no-undef */

function addFiltered(suite, name, body) {
if (name.match(filter1) === null)
return;
if (name.match(filter1) === null) return;

suite.add(name, body);
}

function createInput(size) {
const res = new Array(size);
for (let i = 0; i < res.length; i++)
res[i] = Math.random() * 2 - 1;
for (let i = 0; i < res.length; i++) res[i] = Math.random() * 2 - 1;
return res;
}

Expand All @@ -49,10 +48,9 @@ function addSelf(suite, size) {
const f = new FFT(size);
const input = createInput(f.size);
const data = f.toComplexArray(input);
const out = f.createComplexArray();

addFiltered(suite, 'fft.js', () => {
f.transform(out, data);
f.transform(data);
});
}

Expand Down Expand Up @@ -84,7 +82,7 @@ function addDrom(suite, size) {
const stdlib = {
Math: Math,
Float32Array: Float32Array,
Float64Array: Float64Array
Float64Array: Float64Array,
};
const f = new external.drom.custom[`fft_f64_${size}_asm`](stdlib, null, heap);

Expand All @@ -110,10 +108,9 @@ function addRealSelf(suite, size) {
const f = new FFT(size);
const input = createInput(f.size);
const data = f.toComplexArray(input);
const out = f.createComplexArray();

addFiltered(suite, 'fft.js', () => {
f.realTransform(out, data);
f.realTransform(data);
});
}

Expand Down Expand Up @@ -147,18 +144,19 @@ const benchmarks = [
{ title: 'realTransform size=2048', suite: realTransform(2048) },
{ title: 'realTransform size=4096', suite: realTransform(4096) },
{ title: 'realTransform size=8192', suite: realTransform(8192) },
{ title: 'realTransform size=16384', suite: realTransform(16384) }
{ title: 'realTransform size=16384', suite: realTransform(16384) },
];

/* eslint-disable no-console */
benchmarks.forEach((bench) => {
if (bench.title.match(filter0) === null)
return;
if (bench.title.match(filter0) === null) return;
console.log('===== %s =====', bench.title);
bench.suite.on('cycle', (event) => {
console.log(' '+ String(event.target));
}).on('complete', function() {
console.log(' Fastest is ' + this.filter('fastest').map('name'));
});
bench.suite
.on('cycle', (event) => {
console.log(' ' + String(event.target));
})
.on('complete', function () {
console.log(' Fastest is ' + this.filter('fastest').map('name'));
});
bench.suite.run();
});
1 change: 1 addition & 0 deletions bench/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"private": true,
"description": "Benchmarks for fft.js",
"type": "module",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down
24 changes: 24 additions & 0 deletions dist/fft.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export default class FFT {
size: number;
table: number[];
_csize: number;
_width: number;
_bitrev: number[];
_out: number[];
_data: number[];
_inv: number;
constructor(size: number);
fromComplexArray(complex: number[]): number[];
createComplexArray(): number[];
toComplexArray(input: number[]): number[];
completeSpectrum(spectrum: number[]): number[];
transform(data: number[]): number[];
realTransform(data: number[]): number[];
inverseTransform(data: number[]): number[];
_transform4(): void;
_singleTransform2(outOff: number, off: number, step: number): void;
_singleTransform4(outOff: number, off: number, step: number): void;
_realTransform4(): void;
_singleRealTransform2(outOff: number, off: number, step: number): void;
_singleRealTransform4(outOff: number, off: number, step: number): void;
}
Loading