@@ -123,11 +123,11 @@ T SparseMatrix<T>::get(int row, int col) const
123
123
124
124
int currCol;
125
125
126
- for (int pos = this ->rows -> at ( row - 1 ) - 1 ; pos < this ->rows -> at (row) - 1 ; pos++ ) {
127
- currCol = this ->cols -> at (pos) ;
126
+ for (int pos = (*( this ->rows ))[ row - 1 ] - 1 ; pos < (*( this ->rows ))[row] - 1 ; ++pos ) {
127
+ currCol = (*( this ->cols ))[pos] ;
128
128
129
129
if (currCol == col) {
130
- return this ->vals -> at (pos) ;
130
+ return (*( this ->vals ))[pos] ;
131
131
132
132
} else if (currCol > col) {
133
133
break ;
@@ -143,11 +143,11 @@ SparseMatrix<T> & SparseMatrix<T>::set(T val, int row, int col)
143
143
{
144
144
this ->validateCoordinates (row, col);
145
145
146
- int pos = this ->rows -> at ( row - 1 ) - 1 ;
146
+ int pos = (*( this ->rows ))[ row - 1 ] - 1 ;
147
147
int currCol = 0 ;
148
148
149
- for (; pos < this ->rows -> at (row) - 1 ; pos++) {
150
- currCol = this ->cols -> at (pos) ;
149
+ for (; pos < (*( this ->rows ))[row] - 1 ; pos++) {
150
+ currCol = (*( this ->cols ))[pos] ;
151
151
152
152
if (currCol >= col) {
153
153
break ;
@@ -163,7 +163,7 @@ SparseMatrix<T> & SparseMatrix<T>::set(T val, int row, int col)
163
163
this ->remove (pos, row);
164
164
165
165
} else {
166
- this ->vals -> at (pos) = val;
166
+ (*( this ->vals ))[pos] = val;
167
167
}
168
168
169
169
return *this ;
@@ -184,8 +184,8 @@ vector<T> SparseMatrix<T>::multiply(const vector<T> & x) const
184
184
if (this ->vals != NULL ) { // only if any value set
185
185
for (int i = 0 ; i < this ->m ; i++) {
186
186
T sum = T ();
187
- for (int j = this ->rows -> at (i) ; j < this ->rows -> at ( i + 1 ) ; j++) {
188
- sum = sum + this ->vals -> at ( j - 1 ) * x[this ->cols -> at ( j - 1 ) - 1 ];
187
+ for (int j = (*( this ->rows ))[i] ; j < (*( this ->rows ))[ i + 1 ] ; j++) {
188
+ sum = sum + (*( this ->vals ))[ j - 1 ] * x[(*( this ->cols ))[ j - 1 ] - 1 ];
189
189
}
190
190
191
191
result[i] = sum;
@@ -322,7 +322,7 @@ void SparseMatrix<T>::insert(int index, int row, int col, T val)
322
322
}
323
323
324
324
for (int i = row; i <= this ->m ; i++) {
325
- this ->rows -> at (i) = this ->rows -> at (i) + 1 ;
325
+ (*( this ->rows ))[i] = (*( this ->rows ))[i] + 1 ;
326
326
}
327
327
}
328
328
@@ -334,7 +334,7 @@ void SparseMatrix<T>::remove(int index, int row)
334
334
this ->cols ->erase (this ->cols ->begin () + index);
335
335
336
336
for (int i = row; i <= this ->m ; i++) {
337
- this ->rows -> at (i) = this ->rows -> at (i) - 1 ;
337
+ (*( this ->rows ))[i] = (*( this ->rows ))[i] - 1 ;
338
338
}
339
339
}
340
340
0 commit comments