@@ -199,45 +199,29 @@ export class SparseMatrix {
199
199
const p = other . columns ;
200
200
201
201
const result = matrixCreateEmpty ( m , p ) ;
202
- const useCscCsr = useCscCsrFormat ( this , other ) ;
203
202
204
203
const {
205
204
columns : otherCols ,
206
205
rows : otherRows ,
207
206
values : otherValues ,
208
- } = other . getNonZeros ( useCscCsr ? { format : 'csr' } : { } ) ;
207
+ } = other . getNonZeros ( { format : 'csr' } ) ;
209
208
const {
210
209
columns : thisCols ,
211
210
rows : thisRows ,
212
211
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 ] ;
241
225
}
242
226
}
243
227
}
@@ -355,15 +339,13 @@ export class SparseMatrix {
355
339
idx ++ ;
356
340
} , sort || format ) ;
357
341
358
- const cooMatrix = { rows, columns, values } ;
359
-
360
- if ( ! format ) return cooMatrix ;
342
+ if ( ! format ) return { rows, columns, values } ;
361
343
362
344
if ( ! [ 'csr' , 'csc' ] . includes ( format . toLowerCase ( ) ) ) {
363
345
throw new Error ( `format ${ format } is not supported` ) ;
364
346
}
365
347
366
- const csrMatrix = cooToCsr ( cooMatrix , this . rows ) ;
348
+ const csrMatrix = cooToCsr ( { rows , columns , values } , this . rows ) ;
367
349
return format . toLowerCase ( ) === 'csc'
368
350
? csrToCsc ( csrMatrix , this . columns )
369
351
: csrMatrix ;
0 commit comments