@@ -36,8 +36,10 @@ export class SparseMatrix {
36
36
values : number [ ] ,
37
37
dims : number [ ]
38
38
) {
39
- if ( ( rows . length !== cols . length ) || ( rows . length !== values . length ) ) {
40
- throw new Error ( "rows, cols and values arrays must all have the same length" ) ;
39
+ if ( rows . length !== cols . length || rows . length !== values . length ) {
40
+ throw new Error (
41
+ 'rows, cols and values arrays must all have the same length'
42
+ ) ;
41
43
}
42
44
43
45
// TODO: Assert that dims are legit.
@@ -85,10 +87,11 @@ export class SparseMatrix {
85
87
86
88
getAll ( ordered = true ) : { value : number ; row : number ; col : number } [ ] {
87
89
const rowColValues : Entry [ ] = [ ] ;
88
- this . entries . forEach ( ( value ) => {
90
+ this . entries . forEach ( value => {
89
91
rowColValues . push ( value ) ;
90
92
} ) ;
91
- if ( ordered ) { // Ordering the result isn't required for processing but it does make it easier to write tests
93
+ if ( ordered ) {
94
+ // Ordering the result isn't required for processing but it does make it easier to write tests
92
95
rowColValues . sort ( ( a , b ) => {
93
96
if ( a . row === b . row ) {
94
97
return a . col - b . col ;
@@ -117,12 +120,12 @@ export class SparseMatrix {
117
120
}
118
121
119
122
forEach ( fn : ( value : number , row : number , col : number ) => void ) : void {
120
- this . entries . forEach ( ( value ) => fn ( value . value , value . row , value . col ) ) ;
123
+ this . entries . forEach ( value => fn ( value . value , value . row , value . col ) ) ;
121
124
}
122
125
123
126
map ( fn : ( value : number , row : number , col : number ) => number ) : SparseMatrix {
124
127
let vals : number [ ] = [ ] ;
125
- this . entries . forEach ( ( value ) => {
128
+ this . entries . forEach ( value => {
126
129
vals . push ( fn ( value . value , value . row , value . col ) ) ;
127
130
} ) ;
128
131
const dims = [ this . nRows , this . nCols ] ;
@@ -134,7 +137,7 @@ export class SparseMatrix {
134
137
const output = rows . map ( ( ) => {
135
138
return utils . zeros ( this . nCols ) ;
136
139
} ) ;
137
- this . entries . forEach ( ( value ) => {
140
+ this . entries . forEach ( value => {
138
141
output [ value . row ] [ value . col ] = value . value ;
139
142
} ) ;
140
143
return output ;
@@ -357,7 +360,7 @@ export function getCSR(x: SparseMatrix) {
357
360
if ( a . row === b . row ) {
358
361
return a . col - b . col ;
359
362
} else {
360
- return a . row - b . col ;
363
+ return a . row - b . row ;
361
364
}
362
365
} ) ;
363
366
0 commit comments