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

make callback function takes original data array #94

Merged
merged 2 commits into from
Jan 15, 2017

Conversation

Xuefeng-Zhu
Copy link
Contributor

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map

Make each, map, reduce methods take callback function similar to the one in js Array.

Copy link
Owner

@mateogianolio mateogianolio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but can I just request that you run benchmarks before and after to make sure the performance isn't affected by these changes?

I'm thinking it's slower to apply a callback function in every step of the loop as opposed to executing an expression, but I might be wrong.

I'm aware that this library needs browser benchmarks and benchmarks without BLAS enabled, but for now you can change benchmarks/vector.js to include ../vector instead of ../vectorious.

Hope this isn't too much trouble! I'm grateful for your interest in improving this library.

@Xuefeng-Zhu
Copy link
Contributor Author

@mateogianolio

Here is the benchmark result for this PR

> vectorious@4.7.0 benchmark /Users/Frank/mygit/vectorious
> node ./benchmarks/vector.js && node ./benchmarks/matrix.js

a, b = Vector.random(1024)
Vector.zeros(1024) x 196,433 ops/sec ±3.21% (75 runs sampled)
Vector.ones(1024) x 191,771 ops/sec ±4.04% (66 runs sampled)
Vector.range(0, 1024) x 68,066 ops/sec ±2.76% (79 runs sampled)
Vector.combine(a, b) x 65,491 ops/sec ±6.38% (53 runs sampled)
Vector.add(a, b) x 184,138 ops/sec ±3.94% (59 runs sampled)
Vector.subtract(a, b) x 187,315 ops/sec ±4.04% (60 runs sampled)
Vector.scale(a, Math.random()) x 210,720 ops/sec ±1.60% (65 runs sampled)
Vector.project(a, b) x 194,279 ops/sec ±2.40% (68 runs sampled)
a.add(b) x 1,940,823 ops/sec ±1.58% (87 runs sampled)
a.subtract(b) x 1,973,579 ops/sec ±1.26% (87 runs sampled)
a.scale(Math.random()) x 5,110,356 ops/sec ±1.90% (85 runs sampled)
a.normalize() x 3,877,903 ops/sec ±2.25% (85 runs sampled)
a.dot(b) x 4,824,868 ops/sec ±1.03% (86 runs sampled)
a.magnitude() x 12,079,812 ops/sec ±1.32% (87 runs sampled)
a.angle(b) x 1,564,677 ops/sec ±0.71% (88 runs sampled)
a.project(b) x 1,836,948 ops/sec ±0.79% (91 runs sampled)
a, b = Matrix.random(128, 128)
Matrix.identity(128) x 11,587 ops/sec ±4.40% (76 runs sampled)
Matrix.magic(128) x 2,507 ops/sec ±3.25% (83 runs sampled)
Matrix.zeros(128, 128) x 11,120 ops/sec ±4.58% (71 runs sampled)
Matrix.ones(128, 128) x 11,396 ops/sec ±4.52% (72 runs sampled)
Matrix.plu(a) x 390 ops/sec ±1.85% (80 runs sampled)
Matrix.augment(a, b) x 3,329 ops/sec ±4.06% (77 runs sampled)
Matrix.add(a, b) x 9,808 ops/sec ±4.49% (77 runs sampled)
Matrix.subtract(a, b) x 9,931 ops/sec ±4.47% (78 runs sampled)
Matrix.scale(Math.random()) x 10,138 ops/sec ±4.59% (73 runs sampled)
Matrix.transpose(a):
a.add(b) x 137,383 ops/sec ±0.89% (89 runs sampled)
a.subtract(b) x 137,881 ops/sec ±0.59% (90 runs sampled)
a.scale(Math.random()) x 201,702 ops/sec ±0.81% (90 runs sampled)
a.multiply(b) x 5,346 ops/sec ±2.31% (80 runs sampled)
a.transpose() x 7,141 ops/sec ±4.07% (57 runs sampled)
a.gauss() x 6,430 ops/sec ±4.58% (79 runs sampled)
a.lu() x 590 ops/sec ±1.50% (83 runs sampled)
a.plu() x 764 ops/sec ±1.18% (84 runs sampled)
a.solve() x 719 ops/sec ±0.89% (87 runs sampled)
a.trace() x 420,398 ops/sec ±6.53% (67 runs sampled)
a.swap(i, j) x 106,601 ops/sec ±2.57% (85 runs sampled)

@Xuefeng-Zhu
Copy link
Contributor Author

This is the bench mark for master

> vectorious@4.7.0 benchmark /Users/Frank/mygit/vectorious
> node ./benchmarks/vector.js && node ./benchmarks/matrix.js

a, b = Vector.random(1024)
Vector.zeros(1024) x 202,087 ops/sec ±3.01% (79 runs sampled)
Vector.ones(1024) x 190,404 ops/sec ±3.98% (63 runs sampled)
Vector.range(0, 1024) x 65,465 ops/sec ±3.11% (78 runs sampled)
Vector.combine(a, b) x 68,050 ops/sec ±5.71% (56 runs sampled)
Vector.add(a, b) x 195,546 ops/sec ±3.88% (63 runs sampled)
Vector.subtract(a, b) x 200,427 ops/sec ±3.52% (63 runs sampled)
Vector.scale(a, Math.random()) x 217,565 ops/sec ±1.13% (63 runs sampled)
Vector.project(a, b) x 193,003 ops/sec ±3.04% (64 runs sampled)
a.add(b) x 2,065,532 ops/sec ±0.88% (88 runs sampled)
a.subtract(b) x 2,075,626 ops/sec ±0.85% (88 runs sampled)
a.scale(Math.random()) x 5,479,279 ops/sec ±0.89% (89 runs sampled)
a.normalize() x 4,181,604 ops/sec ±0.96% (91 runs sampled)
a.dot(b) x 4,962,911 ops/sec ±1.02% (86 runs sampled)
a.magnitude() x 12,940,876 ops/sec ±0.92% (92 runs sampled)
a.angle(b) x 1,516,228 ops/sec ±1.08% (87 runs sampled)
a.project(b) x 1,814,127 ops/sec ±0.96% (86 runs sampled)
a, b = Matrix.random(128, 128)
Matrix.identity(128) x 11,132 ops/sec ±4.64% (70 runs sampled)
Matrix.magic(128) x 2,554 ops/sec ±1.38% (85 runs sampled)
Matrix.zeros(128, 128) x 11,493 ops/sec ±4.41% (73 runs sampled)
Matrix.ones(128, 128) x 10,975 ops/sec ±4.59% (71 runs sampled)
Matrix.plu(a) x 370 ops/sec ±2.25% (80 runs sampled)
Matrix.augment(a, b) x 3,093 ops/sec ±4.87% (62 runs sampled)
Matrix.add(a, b) x 7,906 ops/sec ±7.19% (64 runs sampled)
Matrix.subtract(a, b) x 9,108 ops/sec ±5.21% (73 runs sampled)
Matrix.scale(Math.random()) x 9,528 ops/sec ±5.37% (71 runs sampled)
Matrix.transpose(a):
a.add(b) x 126,750 ops/sec ±1.25% (84 runs sampled)
a.subtract(b) x 127,694 ops/sec ±1.02% (86 runs sampled)
a.scale(Math.random()) x 200,087 ops/sec ±0.74% (89 runs sampled)
a.multiply(b) x 4,596 ops/sec ±3.39% (70 runs sampled)
a.transpose() x 6,929 ops/sec ±4.92% (62 runs sampled)
a.gauss() x 6,591 ops/sec ±4.68% (78 runs sampled)
a.lu() x 585 ops/sec ±1.28% (82 runs sampled)
a.plu() x 746 ops/sec ±0.89% (83 runs sampled)
a.solve() x 668 ops/sec ±1.00% (83 runs sampled)
a.trace() x 385,709 ops/sec ±7.68% (67 runs sampled)
a.swap(i, j) x 98,739 ops/sec ±2.06% (81 runs sampled)

@mateogianolio mateogianolio merged commit 939b31d into mateogianolio:master Jan 15, 2017
ukrbublik added a commit to ukrbublik/vectorious-plus that referenced this pull request Aug 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants