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

feat: optimize SVD ? #167

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
39 changes: 39 additions & 0 deletions scripts/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@



let { Matrix, SVD, LU, EVD } = require('../matrix');

const algorithms = [SVD, LU, EVD];

const benchmarks = [];

test(10);
test(100);
test(500);
test(1000);
test(1500);

console.table(benchmarks);

function test(size) {
const benchmark = {};
benchmark.size = size;
benchmarks.push(benchmark);

for (const Algo of algorithms) {
const matrix = Matrix.rand(size, size);
let count = 1;
const start = performance.now();
const results = [new Algo(matrix)];
const current = performance.now() - start;
if (current < 5000) {
count = Math.ceil(5000 / current);
for (let i = 0; i < count - 1; i++) {
results.push(new Algo(matrix));
}
}
const time = (performance.now() - start) / results.length;
benchmark[Algo.name] = time;
console.log(`${Algo.name} ${size}x${size} matrix: ${time}ms (${count}x)`)
}
}
2 changes: 2 additions & 0 deletions src/matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -1579,11 +1579,13 @@ export default class Matrix extends AbstractMatrix {

set(rowIndex, columnIndex, value) {
this.data[rowIndex][columnIndex] = value;
//this.data[columnIndex][rowIndex] = value;
return this;
}

get(rowIndex, columnIndex) {
return this.data[rowIndex][columnIndex];
//return this.data[columnIndex][rowIndex];
}

removeRow(index) {
Expand Down