IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 1, 2010, 12:52:06 PM (16 years ago)
Author:
Paul Price
Message:

Allocators should NEVER return NULL!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psHistogram.c

    r26892 r27553  
    5858    psTrace("psLib.math", 3, "---- %s() begin  ----\n", __func__);
    5959    psTrace("psLib.math", 5, "(lower, upper, n) is (%f, %f, %d)\n", lower, upper, n);
    60     PS_ASSERT_INT_POSITIVE(n, NULL);
    61     PS_ASSERT_FLOAT_LARGER_THAN_OR_EQUAL(upper, lower, NULL);
     60    psAssert(n > 0, "Number of bins must be positive");
     61    psAssert(upper >= lower, "Bounds must be sensical");
    6262
    6363    // Allocate memory for the new histogram structure.  If there are N bins, then there are N+1 bounds to
     
    287287                    double binSize = (out->bounds->data.F32[out->nums->n] - out->bounds->data.F32[0]) / (float) out->nums->n; // Histogram bin size
    288288                    binNum = (inF32->data.F32[i] - out->bounds->data.F32[0]) / binSize;
    289                     binNum = PS_MAX (binNum, 0);
    290                     binNum = PS_MIN (binNum, numBins - 1);
    291 
    292                     // value is in bin 'i' if bound[i] <= value < bound[i]
    293 
    294                     // we may slightly overshoot or undershoot.  creep up or down on the true bin
    295                     if (inF32->data.F32[i] < out->bounds->data.F32[binNum]) {
    296                         psTrace("psLib.math", 6, "missed target bin, adjusting: %f vs %f to %f\n", inF32->data.F32[i], out->bounds->data.F32[binNum], out->bounds->data.F32[binNum+1]);
    297                         while ((inF32->data.F32[i] < out->bounds->data.F32[binNum]) && (binNum > 0)) {
    298                             binNum --;
    299                         }
    300                        
    301                     }
    302                     if (inF32->data.F32[i] >= out->bounds->data.F32[binNum+1]) {
    303                         psTrace("psLib.math", 6, "missed target bin, adjusting: %f vs %f to %f\n", inF32->data.F32[i], out->bounds->data.F32[binNum], out->bounds->data.F32[binNum+1]);
    304                         while ((inF32->data.F32[i] >= out->bounds->data.F32[binNum+1]) && (binNum < numBins - 1)) {
    305                             binNum ++;
    306                         }
    307                     }
     289                    binNum = PS_MAX (binNum, 0);
     290                    binNum = PS_MIN (binNum, numBins - 1);
     291
     292                    // value is in bin 'i' if bound[i] <= value < bound[i]
     293
     294                    // we may slightly overshoot or undershoot.  creep up or down on the true bin
     295                    if (inF32->data.F32[i] < out->bounds->data.F32[binNum]) {
     296                        psTrace("psLib.math", 6, "missed target bin, adjusting: %f vs %f to %f\n", inF32->data.F32[i], out->bounds->data.F32[binNum], out->bounds->data.F32[binNum+1]);
     297                        while ((inF32->data.F32[i] < out->bounds->data.F32[binNum]) && (binNum > 0)) {
     298                            binNum --;
     299                        }
     300
     301                    }
     302                    if (inF32->data.F32[i] >= out->bounds->data.F32[binNum+1]) {
     303                        psTrace("psLib.math", 6, "missed target bin, adjusting: %f vs %f to %f\n", inF32->data.F32[i], out->bounds->data.F32[binNum], out->bounds->data.F32[binNum+1]);
     304                        while ((inF32->data.F32[i] >= out->bounds->data.F32[binNum+1]) && (binNum < numBins - 1)) {
     305                            binNum ++;
     306                        }
     307                    }
    308308
    309309                    if (errorsF32) {
     
    326326                    // correct bin number requires a bit more work.
    327327                    tmpScalar.data.F32 = inF32->data.F32[i];
    328                     psVectorBinaryDisectResult result;
     328                    psVectorBinaryDisectResult result;
    329329                    binNum = psVectorBinaryDisect(&result, out->bounds, &tmpScalar);
    330                     if (result != PS_BINARY_DISECT_PASS) {
    331                         continue;
    332                     }
    333                     if (errorsF32 != NULL) {
    334                         if (!UpdateHistogramBins(binNum, out, inF32->data.F32[i], errors->data.F32[i])) {
    335                             psLogMsg(__func__, PS_LOG_WARN, "WARNING: Failed to update the histogram "
    336                                      "bins with the errors vector.\n");
    337                         }
    338                     } else {
    339                         out->nums->data.F32[binNum] += 1.0;
    340                     }
     330                    if (result != PS_BINARY_DISECT_PASS) {
     331                        continue;
     332                    }
     333                    if (errorsF32 != NULL) {
     334                        if (!UpdateHistogramBins(binNum, out, inF32->data.F32[i], errors->data.F32[i])) {
     335                            psLogMsg(__func__, PS_LOG_WARN, "WARNING: Failed to update the histogram "
     336                                     "bins with the errors vector.\n");
     337                        }
     338                    } else {
     339                        out->nums->data.F32[binNum] += 1.0;
     340                    }
    341341                }
    342342            }
Note: See TracChangeset for help on using the changeset viewer.