Changeset 16450
- Timestamp:
- 10/17/13 21:56:32 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/toolkits/issm/SparseRow.h
r16438 r16450 72 72 if(!numvalues)return; 73 73 74 /*Figure out number of non-zero values ncols: */ 75 for(i=0;i<numvalues;i++)buffer[i]=0; 76 77 ncols=0; 74 /*Go through cols and resolve duplicates: */ 78 75 for(i=0;i<numvalues;i++){ 79 if(!buffer[cols[i]])ncols++; 80 if(mods[i]==ADD_VAL){ 81 if(buffer[cols[i]]!=2)buffer[cols[i]]=1; 76 for(j=i+1;j<numvalues;j++){ 77 if (cols[j]==cols[i]){ 78 if (mods[j]==ADD_VAL){ 79 vals[i]+=vals[j]; 80 } 81 else vals[i]=vals[j]; 82 cols[j]=-1; 83 } 84 /*Ensure that this value will not be used anymore: */ 82 85 } 83 else buffer[cols[i]]=2;84 86 } 85 87 86 /*Allocate:*/ 88 /*Now go through cols once more, and retrieve only what we need: */ 89 ncols=0; 90 for(i=0;i<numvalues;i++)if(cols[i]>=0)ncols++; 91 92 /*Allocate and fill: */ 87 93 indices=xNew<int>(ncols); _assert_(indices); 88 94 values=xNewZeroInit<doubletype>(ncols); _assert_(values); 89 90 /*Go through buffer and add values: */ 95 91 96 count=0; 92 for(i=0;i<M;i++){ 93 if(buffer[i]==1){ 94 indices[count]=i; 95 96 /*ADD_VALUE: chase all values with row index i*/ 97 for(j=0;j<numvalues;j++){ 98 if (cols[j]==i)values[count]+=vals[j]; 99 } 100 count++; 101 } 102 else if(buffer[i]==2){ 103 indices[count]=i; 104 105 /*INS_VALUE: chase first value with row index i*/ 106 for(j=0;j<numvalues;j++){ 107 if (cols[j]==i){ 108 values[count]=vals[j]; 109 break; 110 } 111 } 97 for(i=0;i<numvalues;i++){ 98 if(cols[i]>=0){ 99 indices[count]=cols[i]; 100 values[count]=vals[i]; 112 101 count++; 113 102 } 114 103 } 104 115 105 if(count!=ncols)_error_("counter problem during set values operations"); 116 106 } /*}}}*/
Note:
See TracChangeset
for help on using the changeset viewer.