Permalink
Browse files

Fix most lint errors using `npx standard --fix`

  • Loading branch information...
josdejong committed Jun 10, 2018
1 parent f76b3ae commit 024b2a9e2668c9c6954dc80542f9e78d8436deca
Showing 877 changed files with 47,563 additions and 49,450 deletions.
@@ -1,32 +1,32 @@
// test performance of the expression parser in node.js
var Benchmark = require('benchmark');
var padRight = require('pad-right');
var math = require('../index');
var Benchmark = require('benchmark')
var padRight = require('pad-right')
var math = require('../index')
function pad (text) {
return padRight(text, 40, ' ');
return padRight(text, 40, ' ')
}
var simplifyExpr = '2 * 1 * x ^ (2 - 1)';
var derivativeExpr = '2x^2 + log(3x) + 2x + 3';
var simplifyExpr = '2 * 1 * x ^ (2 - 1)'
var derivativeExpr = '2x^2 + log(3x) + 2x + 3'
console.log('simplify ' + simplifyExpr);
console.log(' ' + math.simplify(simplifyExpr));
console.log('derivative ' + derivativeExpr);
console.log(' ' + math.derivative(derivativeExpr, 'x'));
console.log('simplify ' + simplifyExpr)
console.log(' ' + math.simplify(simplifyExpr))
console.log('derivative ' + derivativeExpr)
console.log(' ' + math.derivative(derivativeExpr, 'x'))
var suite = new Benchmark.Suite();
var suite = new Benchmark.Suite()
suite
.add(pad('algebra simplify '), function() {
var res = math.simplify(simplifyExpr);
})
.add(pad('algebra derivative'), function() {
var res = math.derivative(derivativeExpr, 'x');
})
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', function() {
})
.run();
.add(pad('algebra simplify '), function () {
var res = math.simplify(simplifyExpr)
})
.add(pad('algebra derivative'), function () {
var res = math.derivative(derivativeExpr, 'x')
})
.on('cycle', function (event) {
console.log(String(event.target))
})
.on('complete', function () {
})
.run()
@@ -2,81 +2,79 @@
// browserify benchmark/expression_parser.js -o ./benchmark_expression_parser.js
var assert = require('assert');
var Benchmark = require('benchmark');
var padRight = require('pad-right');
var math = require('../index');
var assert = require('assert')
var Benchmark = require('benchmark')
var padRight = require('pad-right')
var math = require('../index')
var getSafeProperty = require('../lib/utils/customs').getSafeProperty
// expose on window when using bundled in a browser
if (typeof window !== 'undefined') {
window['Benchmark'] = Benchmark;
window['Benchmark'] = Benchmark
}
function pad (text) {
return padRight(text, 40, ' ');
return padRight(text, 40, ' ')
}
var expr = '2 + 3 * sin(pi / 4) - 4x';
var scope = {x: 2};
var compiled = math.parse(expr).compile(math, {});
var expr = '2 + 3 * sin(pi / 4) - 4x'
var scope = {x: 2}
var compiled = math.parse(expr).compile(math, {})
var sin = getSafeProperty(math, 'sin');
var pi = getSafeProperty(math, 'pi');
var sin = getSafeProperty(math, 'sin')
var pi = getSafeProperty(math, 'pi')
var compiledPlainJs = {
eval: function (scope) {
return 2 + 3 * ('sin' in scope ? getSafeProperty(scope, 'sin') : sin)(('pi' in scope ? getSafeProperty(scope, 'pi') : pi) / 4) - 4 * scope['x']
return 2 + 3 * ('sin' in scope ? getSafeProperty(scope, 'sin') : sin)(('pi' in scope ? getSafeProperty(scope, 'pi') : pi) / 4) - 4 * scope['x']
}
}
var correctResult = -3.878679656440358;
var correctResult = -3.878679656440358
console.log('expression:', expr);
console.log('scope:', scope);
console.log('result:', correctResult);
console.log('expression:', expr)
console.log('scope:', scope)
console.log('result:', correctResult)
assertApproxEqual(compiled.eval(scope), correctResult, 1e-7);
assertApproxEqual(compiledPlainJs.eval(scope), correctResult, 1e-7);
assertApproxEqual(compiled.eval(scope), correctResult, 1e-7)
assertApproxEqual(compiledPlainJs.eval(scope), correctResult, 1e-7)
var total = 0;
var total = 0
var suite = new Benchmark.Suite();
var suite = new Benchmark.Suite()
suite
.add(pad('(plain js) evaluate'), function() {
total+= compiledPlainJs.eval(scope);
})
.add(pad('(plain js) evaluate'), function () {
total += compiledPlainJs.eval(scope)
})
.add(pad('(mathjs) evaluate'), function() {
total += compiled.eval(scope);
})
.add(pad('(mathjs) parse, compile, evaluate'), function() {
total += math.parse(expr).compile().eval(scope);
})
.add(pad('(mathjs) parse, compile'), function() {
var node = math.parse(expr).compile();
})
.add(pad('(mathjs) parse'), function() {
var node = math.parse(expr);
})
.add(pad('(mathjs) evaluate'), function () {
total += compiled.eval(scope)
})
.add(pad('(mathjs) parse, compile, evaluate'), function () {
total += math.parse(expr).compile().eval(scope)
})
.add(pad('(mathjs) parse, compile'), function () {
var node = math.parse(expr).compile()
})
.add(pad('(mathjs) parse'), function () {
var node = math.parse(expr)
})
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', function() {
// we count at total to prevent the browsers from not executing
// the benchmarks ("dead code") when the results would not be used.
if (total > 1e6) {
console.log('')
}
else {
console.log('')
}
})
.run();
.on('cycle', function (event) {
console.log(String(event.target))
})
.on('complete', function () {
// we count at total to prevent the browsers from not executing
// the benchmarks ("dead code") when the results would not be used.
if (total > 1e6) {
console.log('')
} else {
console.log('')
}
})
.run()
function assertApproxEqual(actual, expected, tolerance) {
var diff = Math.abs(expected - actual);
if (diff > tolerance) assert.equal(actual, expected);
else assert.ok(diff <= tolerance, actual + ' === ' + expected);
function assertApproxEqual (actual, expected, tolerance) {
var diff = Math.abs(expected - actual)
if (diff > tolerance) assert.equal(actual, expected)
else assert.ok(diff <= tolerance, actual + ' === ' + expected)
};
@@ -1,4 +1,4 @@
// run all benchmarks
require ('./expression_parser');
require ('./algebra');
require ('./matrix_operations');
require('./expression_parser')
require('./algebra')
require('./matrix_operations')
@@ -1,6 +1,6 @@
/**
* Benchmark
*
*
* Compare performance of basic matrix operations of a number of math libraries.
*
* These are some rough benchmarks to get an idea of the performance of math.js
@@ -9,103 +9,103 @@
* has room for improvements, it's not a fully fletched benchmark suite.
*/
var Benchmark = require('benchmark');
var padRight = require('pad-right');
var suite = new Benchmark.Suite();
var Benchmark = require('benchmark')
var padRight = require('pad-right')
var suite = new Benchmark.Suite()
function pad (text) {
return padRight(text, 40, ' ');
return padRight(text, 40, ' ')
}
// fiedler matrix 25 x 25
var fiedler = [
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24],
[ 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23],
[ 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22],
[ 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21],
[ 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
[ 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
[ 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],
[ 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17],
[ 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
[ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
[11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
[12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
[13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
[14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
[15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8],
[17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7],
[18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6],
[19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5],
[20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4],
[21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3],
[22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2],
[23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1],
[24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24],
[ 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23],
[ 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22],
[ 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21],
[ 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
[ 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
[ 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],
[ 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17],
[ 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
[ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
[11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
[12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
[13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
[14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
[15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8],
[17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7],
[18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6],
[19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5],
[20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4],
[21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3],
[22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2],
[23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1],
[24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
];
// mathjs
(function () {
var math = require('../index');
var A = math.matrix(fiedler);
var math = require('../index')
var A = math.matrix(fiedler)
suite.add(pad('matrix operations mathjs A+A'), function () { return math.add(A, A) });
suite.add(pad('matrix operations mathjs A*A'), function () { return math.multiply(A, A) });
suite.add(pad('matrix operations mathjs A\''), function () { return math.transpose(A) });
suite.add(pad('matrix operations mathjs det(A)'), function () { return math.det(A) });
suite.add(pad('matrix operations mathjs A+A'), function () { return math.add(A, A) })
suite.add(pad('matrix operations mathjs A*A'), function () { return math.multiply(A, A) })
suite.add(pad('matrix operations mathjs A\''), function () { return math.transpose(A) })
suite.add(pad('matrix operations mathjs det(A)'), function () { return math.det(A) })
})();
// sylvester
(function () {
var sylvester = require('sylvester');
var A = sylvester.Matrix.create(fiedler);
var sylvester = require('sylvester')
var A = sylvester.Matrix.create(fiedler)
suite.add(pad('matrix operations sylvester A+A'), function () { return A.add(A) });
suite.add(pad('matrix operations sylvester A*A'), function () { return A.multiply(A) });
suite.add(pad('matrix operations sylvester A\''), function () { return A.transpose() });
suite.add(pad('matrix operations sylvester det(A)'), function () { return A.det() });
suite.add(pad('matrix operations sylvester A+A'), function () { return A.add(A) })
suite.add(pad('matrix operations sylvester A*A'), function () { return A.multiply(A) })
suite.add(pad('matrix operations sylvester A\''), function () { return A.transpose() })
suite.add(pad('matrix operations sylvester det(A)'), function () { return A.det() })
})();
// numericjs
(function () {
var numeric = require('numericjs');
var A = fiedler;
var numeric = require('numericjs')
var A = fiedler
suite.add(pad('matrix operations numericjs A+A'), function () { return numeric.add(A, A) });
suite.add(pad('matrix operations numericjs A*A'), function () { return numeric.dot(A, A) });
suite.add(pad('matrix operations numericjs A\''), function () { return numeric.transpose(A) });
suite.add(pad('matrix operations numericjs det(A)'), function () { return numeric.det(A) });
suite.add(pad('matrix operations numericjs A+A'), function () { return numeric.add(A, A) })
suite.add(pad('matrix operations numericjs A*A'), function () { return numeric.dot(A, A) })
suite.add(pad('matrix operations numericjs A\''), function () { return numeric.transpose(A) })
suite.add(pad('matrix operations numericjs det(A)'), function () { return numeric.det(A) })
})();
// ndarray
(function () {
var ndarray = require('ndarray');
var gemm = require('ndarray-gemm');
var zeros = require('zeros');
var ops = require('ndarray-ops');
var pack = require('ndarray-pack');
var det = require('ndarray-determinant');
var A = pack(fiedler);
var B = zeros([25, 25]);
var ndarray = require('ndarray')
var gemm = require('ndarray-gemm')
var zeros = require('zeros')
var ops = require('ndarray-ops')
var pack = require('ndarray-pack')
var det = require('ndarray-determinant')
suite.add(pad('matrix operations ndarray A+A'), function () { return ops.add(B, A, A) });
suite.add(pad('matrix operations ndarray A*A'), function () { return gemm(B, A, A) });
suite.add(pad('matrix operations ndarray A\''), function () { return ops.assign(B, A); B.transpose(1, 0); });
suite.add(pad('matrix operations ndarray det(A)'), function () { return det(A) });
})();
var A = pack(fiedler)
var B = zeros([25, 25])
suite.add(pad('matrix operations ndarray A+A'), function () { return ops.add(B, A, A) })
suite.add(pad('matrix operations ndarray A*A'), function () { return gemm(B, A, A) })
suite.add(pad('matrix operations ndarray A\''), function () { return ops.assign(B, A); B.transpose(1, 0) })
suite.add(pad('matrix operations ndarray det(A)'), function () { return det(A) })
})()
var durations = []
suite
.on('cycle', function(event) {
var benchmark = event.target
console.log(String(event.target));
durations.push(benchmark.name + ' avg duration per operation: ' + Math.round(benchmark.stats.mean * 1e6) + ' microseconds');
})
.run();
.on('cycle', function (event) {
var benchmark = event.target
console.log(String(event.target))
durations.push(benchmark.name + ' avg duration per operation: ' + Math.round(benchmark.stats.mean * 1e6) + ' microseconds')
})
.run()
console.log();
console.log(durations.join('\n'));
console.log()
console.log(durations.join('\n'))
Oops, something went wrong.

0 comments on commit 024b2a9

Please sign in to comment.