Skip to content

Commit 8e8318c

Browse files
authored
feat: add withEachNonZero method and improve performance of mmul and kroneckerProduct (#14)
1 parent 9361aa3 commit 8e8318c

21 files changed

+2280
-155
lines changed

.github/workflows/typedoc.yml

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,15 @@
1-
name: Deploy TypeDoc on GitHub pages
1+
name: TypeDoc
22

33
on:
44
workflow_dispatch:
55
release:
66
types: [published]
77

8-
env:
9-
NODE_VERSION: 22.x
10-
ENTRY_FILE: 'src/index.js'
11-
128
jobs:
13-
deploy:
14-
runs-on: ubuntu-latest
15-
steps:
16-
- uses: actions/checkout@v4
17-
- uses: actions/setup-node@v4
18-
with:
19-
node-version: ${{ env.NODE_VERSION }}
20-
- name: Install dependencies
21-
run: npm install
22-
- name: Build documentation
23-
uses: zakodium/typedoc-action@v2
24-
with:
25-
entry: ${{ env.ENTRY_FILE }}
26-
- name: Deploy to GitHub pages
27-
uses: JamesIves/github-pages-deploy-action@releases/v4
28-
with:
29-
token: ${{ secrets.BOT_TOKEN }}
30-
branch: gh-pages
31-
folder: docs
32-
clean: true
9+
typedoc:
10+
# Documentation: https://github.com/zakodium/workflows#typedoc
11+
uses: zakodium/workflows/.github/workflows/typedoc.yml@typedoc-v1
12+
with:
13+
entry: 'src/index.js'
14+
secrets:
15+
github-token: ${{ secrets.BOT_TOKEN }}

benchmark/benchmarkLinePlot.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { bench, do_not_optimize, lineplot, run } from 'mitata';
2+
import { xSequentialFillFromStep } from 'ml-spectra-processing';
3+
4+
import { SparseMatrix } from '../src/index.js';
5+
6+
import { SparseMatrix as SparseMatrixOld } from './class/SparseMatrixOld.js';
7+
import { randomMatrix } from './utils/randomMatrix.js';
8+
9+
const density = 0.02; // Fixed density for this comparison;
10+
11+
// Prepare matrices once
12+
const sizes = Array.from(
13+
xSequentialFillFromStep({ from: 4, step: 4, size: 13 }),
14+
);
15+
lineplot(() => {
16+
bench('Sparse.mmul($size)', function* (ctx) {
17+
const size = ctx.get('size');
18+
19+
// Prepare matrices once
20+
const A = new SparseMatrix(randomMatrix(size, size, density));
21+
const B = new SparseMatrix(randomMatrix(size, size, density));
22+
// Benchmark the multiplication
23+
yield () => do_not_optimize(A.mmul(B));
24+
})
25+
.gc('inner')
26+
.args('size', sizes); // 16, 32, 64, 128, 256
27+
28+
bench('SparseOld.mmul($size)', function* (ctx) {
29+
const size = ctx.get('size');
30+
const A = randomMatrix(size, size, density);
31+
const B = randomMatrix(size, size, density);
32+
const AOld = new SparseMatrixOld(A);
33+
const BOld = new SparseMatrixOld(B);
34+
35+
// Benchmark the multiplication
36+
yield () => do_not_optimize(AOld.mmul(BOld));
37+
})
38+
.gc('inner')
39+
.args('size', sizes);
40+
41+
// bench('Dense.mmul($size)', function* (ctx) {
42+
// const size = ctx.get('size');
43+
44+
// // Prepare matrices once
45+
// const A = randomMatrix(size, size, density);
46+
// const B = randomMatrix(size, size, density);
47+
// const ADense = new Matrix(A);
48+
// const BDense = new Matrix(B);
49+
50+
// // Benchmark the multiplication
51+
// yield () => do_not_optimize(ADense.mmul(BDense));
52+
// }).gc('inner').range('size', min, max, multiplier);
53+
});
54+
55+
await run();

0 commit comments

Comments
 (0)