Skip to content

Commit 22d602d

Browse files
committed
Chore: use default value of initialCapacity from ml-hast-table
1 parent 44b9822 commit 22d602d

File tree

4 files changed

+20
-31
lines changed

4 files changed

+20
-31
lines changed

benchmark/benchmarkLinePlot.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { run, bench, lineplot, do_not_optimize } from 'mitata';
22
import { SparseMatrix } from '../src/index.js';
3-
import { randomSparseMatrix } from './utils/randomSparseMatrix.js';
4-
import { Matrix } from 'ml-matrix';
3+
import { xSequentialFillFromStep } from 'ml-spectra-processing';
54
import { SparseMatrix as SparseMatrixOld } from './class/SparseMatrixOld.js';
65
import { randomMatrix } from './utils/randomMatrix.js';
7-
const density = 0.01; // Fixed density for this comparison;
8-
const min = 32;
9-
const max = 128;
10-
// Prepare matrices once
6+
const density = 0.02; // Fixed density for this comparison;
117

8+
// Prepare matrices once
9+
const sizes = Array.from(
10+
xSequentialFillFromStep({ from: 4, step: 4, size: 13 }),
11+
);
1212
lineplot(() => {
1313
bench('Sparse.mmul($size)', function* (ctx) {
1414
const size = ctx.get('size');
@@ -18,7 +18,7 @@ lineplot(() => {
1818
const B = new SparseMatrix(randomMatrix(size, size, density));
1919
// Benchmark the multiplication
2020
yield () => do_not_optimize(A.mmul(B));
21-
}).range('size', min, max, 2); // 16, 32, 64, 128, 256
21+
}).args('size', sizes); // 16, 32, 64, 128, 256
2222

2323
bench('SparseOld.mmul($size)', function* (ctx) {
2424
const size = ctx.get('size');
@@ -29,20 +29,20 @@ lineplot(() => {
2929

3030
// Benchmark the multiplication
3131
yield () => do_not_optimize(AOld.mmul(BOld));
32-
}).range('size', min, max, 2);
32+
}).args('size', sizes);
3333

34-
bench('Dense.mmul($size)', function* (ctx) {
35-
const size = ctx.get('size');
34+
// bench('Dense.mmul($size)', function* (ctx) {
35+
// const size = ctx.get('size');
3636

37-
// Prepare matrices once
38-
const A = randomMatrix(size, size, density);
39-
const B = randomMatrix(size, size, density);
40-
const ADense = new Matrix(A);
41-
const BDense = new Matrix(B);
37+
// // Prepare matrices once
38+
// const A = randomMatrix(size, size, density);
39+
// const B = randomMatrix(size, size, density);
40+
// const ADense = new Matrix(A);
41+
// const BDense = new Matrix(B);
4242

43-
// Benchmark the multiplication
44-
yield () => do_not_optimize(ADense.mmul(BDense));
45-
}).range('size', min, max, 2);
43+
// // Benchmark the multiplication
44+
// yield () => do_not_optimize(ADense.mmul(BDense));
45+
// }).range('size', min, max, multiplier);
4646
});
4747

4848
await run();

benchmark/benchmarkMitata.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { run, bench, group, do_not_optimize } from 'mitata';
22
import { Matrix } from 'ml-matrix';
33
import { SparseMatrix as SparseMatrixOld } from './class/SparseMatrixOld2.js';
4-
import fs from 'fs';
54
import { randomSparseMatrix } from './utils/randomSparseMatrix.js';
65

76
const sizes = [64, 128, 256];
87
const densities = [0.01, 0.015, 0.02, 0.025, 0.03];
9-
const results = [];
108

119
for (const density of densities) {
1210
for (const size of sizes) {
@@ -19,11 +17,6 @@ for (const density of densities) {
1917
denseA = new Matrix(denseA);
2018
denseB = new Matrix(denseB);
2119

22-
// Warm up
23-
A.mmul(B);
24-
25-
let mmulNewAvg, mmulAvg, denseAvg;
26-
2720
group(`size:${size}-density:${density}`, () => {
2821
bench('mmulNew', () => {
2922
do_not_optimize(A.mmul(B));
@@ -35,11 +28,7 @@ for (const density of densities) {
3528
do_not_optimize(denseA.mmul(denseB));
3629
}); //.gc('inner');
3730
});
38-
39-
// mitata will handle timing and reporting
40-
// You can extract results from mitata's output or use the save() function
4131
}
4232
}
4333

4434
await run({ silent: false });
45-
// await save({ file: './benchmark/mitata_results.json', format: 'json' });

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"eslint-config-cheminfo-typescript": "^18.0.1",
4343
"mitata": "^1.0.34",
4444
"ml-matrix": "^6.12.1",
45+
"ml-spectra-processing": "^14.12.0",
4546
"prettier": "^3.5.3",
4647
"rimraf": "^6.0.1",
4748
"typescript": "^5.8.3",

src/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ export class SparseMatrix {
1919
if (Array.isArray(rows)) {
2020
const matrix = rows;
2121
const nbRows = matrix.length;
22-
const nbColmuns = matrix[0].length;
23-
options = columns || { initialCapacity: nbRows * nbColmuns };
22+
options = columns || {};
2423
columns = matrix[0].length;
2524
this._init(nbRows, columns, new HashTable(options), options.threshold);
2625
for (let i = 0; i < nbRows; i++) {

0 commit comments

Comments
 (0)