Changeset 7550 for trunk/psLib/src/math/psSparse.c
- Timestamp:
- Jun 13, 2006, 2:02:47 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psSparse.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psSparse.c
r7380 r7550 29 29 30 30 // allocate a sparse matrix container for Nrows, with Nelem slots allocated 31 psSparse *psSparseAlloc( long Nrows, longNelem)31 psSparse *psSparseAlloc(int Nrows, int Nelem) 32 32 { 33 33 psSparse *sparse = (psSparse *)psAlloc(sizeof(psSparse)); … … 54 54 55 55 // user should only add elements above the diagonal, but we don't check this 56 bool psSparseMatrixElement(psSparse *sparse, long i, longj, float value)56 bool psSparseMatrixElement(psSparse *sparse, int i, int j, float value) 57 57 { 58 58 PS_ASSERT_PTR_NON_NULL(sparse, false); … … 62 62 if (i < j) { 63 63 psLogMsg(__func__, PS_LOG_WARN, "i=%ld, j=%ld refers to a sub-diagonal element; values switched.\n"); 64 longtemp = i;64 int temp = i; 65 65 i = j; 66 66 j = temp; … … 78 78 } 79 79 80 longk = sparse->Nelem; // Index at which to add80 int k = sparse->Nelem; // Index at which to add 81 81 sparse->Aij->data.F32[k] = value; 82 82 sparse->Si->data.S32[k] = i; … … 95 95 } 96 96 97 longk = sparse->Nelem; // Index at which to add97 int k = sparse->Nelem; // Index at which to add 98 98 sparse->Aij->data.F32[k] = value; 99 99 sparse->Si->data.S32[k] = i; … … 114 114 } 115 115 116 void inline psSparseVectorElement(psSparse *sparse, longi, float value)116 void inline psSparseVectorElement(psSparse *sparse, int i, float value) 117 117 { 118 118 … … 129 129 output = psVectorRecycle(output, vector->n, PS_TYPE_F32); 130 130 131 longNelem = 0; // Number of elements132 for ( longj = 0; j < vector->n; j++) {131 int Nelem = 0; // Number of elements 132 for (int j = 0; j < vector->n; j++) { 133 133 double F = 0; // Running total 134 134 while (matrix->Sj->data.S32[Nelem] == j) { 135 longi = matrix->Si->data.S32[Nelem];135 int i = matrix->Si->data.S32[Nelem]; 136 136 F += vector->data.F32[i] * matrix->Aij->data.F32[Nelem]; 137 137 Nelem++; … … 158 158 dQ->n = output->n; 159 159 160 for ( longj = 0; j < Niter; j++) {160 for (int j = 0; j < Niter; j++) { 161 161 dQ = psSparseMatrixTimesVector(dQ, sparse, output); 162 for ( longi = 0; i < dQ->n; i++) {162 for (int i = 0; i < dQ->n; i++) { 163 163 psF32 dG = (dQ->data.F32[i] - Bfj->data.F32[i]) / Qii->data.F32[i]; 164 164 if (fabs (dG) > constraint.paramDelta) { … … 181 181 bool psSparseResort(psSparse *sparse) 182 182 { 183 longNelem = sparse->Nelem;183 int Nelem = sparse->Nelem; 184 184 185 185 psVector *index = psVectorSortIndex(NULL, sparse->Sj); // Index key for sorting … … 198 198 tAij->n = tSi->n = tSj->n = Nelem; 199 199 200 for ( longi = 0; i < Nelem; i++) {201 longj = index->data.U32[i];200 for (int i = 0; i < Nelem; i++) { 201 int j = index->data.U32[i]; 202 202 tAij->data.F32[i] = Aij->data.F32[j]; 203 203 tSi->data.S32[i] = Si->data.S32[j];
Note:
See TracChangeset
for help on using the changeset viewer.
