Skip to content

Commit 807ab3d

Browse files
committed
chore: keep mmul simple
1 parent d78911d commit 807ab3d

File tree

1 file changed

+16
-34
lines changed

1 file changed

+16
-34
lines changed

src/index.js

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -199,45 +199,29 @@ export class SparseMatrix {
199199
const p = other.columns;
200200

201201
const result = matrixCreateEmpty(m, p);
202-
const useCscCsr = useCscCsrFormat(this, other);
203202

204203
const {
205204
columns: otherCols,
206205
rows: otherRows,
207206
values: otherValues,
208-
} = other.getNonZeros(useCscCsr ? { format: 'csr' } : {});
207+
} = other.getNonZeros({ format: 'csr' });
209208
const {
210209
columns: thisCols,
211210
rows: thisRows,
212211
values: thisValues,
213-
} = this.getNonZeros(useCscCsr ? { format: 'csc' } : {});
214-
215-
if (useCscCsr) {
216-
const thisNbCols = this.columns;
217-
for (let t = 0; t < thisNbCols; t++) {
218-
const tValues = thisValues.subarray(thisCols[t], thisCols[t + 1]);
219-
const tRows = thisRows.subarray(thisCols[t], thisCols[t + 1]);
220-
const oValues = otherValues.subarray(otherRows[t], otherRows[t + 1]);
221-
const oCols = otherCols.subarray(otherRows[t], otherRows[t + 1]);
222-
for (let f = 0; f < tValues.length; f++) {
223-
for (let k = 0; k < oValues.length; k++) {
224-
const i = tRows[f];
225-
const l = oCols[k];
226-
result[i][l] += tValues[f] * oValues[k];
227-
}
228-
}
229-
}
230-
} else {
231-
const nbOtherActive = otherCols.length;
232-
const nbThisActive = thisCols.length;
233-
for (let t = 0; t < nbThisActive; t++) {
234-
const i = thisRows[t];
235-
const j = thisCols[t];
236-
for (let o = 0; o < nbOtherActive; o++) {
237-
if (j === otherRows[o]) {
238-
const l = otherCols[o];
239-
result[i][l] += otherValues[o] * thisValues[t];
240-
}
212+
} = this.getNonZeros({ format: 'csc' });
213+
214+
const thisNbCols = this.columns;
215+
for (let t = 0; t < thisNbCols; t++) {
216+
const tStart = thisCols[t];
217+
const tEnd = thisCols[t + 1];
218+
const oStart = otherRows[t];
219+
const oEnd = otherRows[t + 1];
220+
for (let f = tStart; f < tEnd; f++) {
221+
for (let k = oStart; k < oEnd; k++) {
222+
const i = thisRows[f];
223+
const l = otherCols[k];
224+
result[i][l] += thisValues[f] * otherValues[k];
241225
}
242226
}
243227
}
@@ -355,15 +339,13 @@ export class SparseMatrix {
355339
idx++;
356340
}, sort || format);
357341

358-
const cooMatrix = { rows, columns, values };
359-
360-
if (!format) return cooMatrix;
342+
if (!format) return { rows, columns, values };
361343

362344
if (!['csr', 'csc'].includes(format.toLowerCase())) {
363345
throw new Error(`format ${format} is not supported`);
364346
}
365347

366-
const csrMatrix = cooToCsr(cooMatrix, this.rows);
348+
const csrMatrix = cooToCsr({ rows, columns, values }, this.rows);
367349
return format.toLowerCase() === 'csc'
368350
? csrToCsc(csrMatrix, this.columns)
369351
: csrMatrix;

0 commit comments

Comments
 (0)