IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 11, 2021, 2:35:51 PM (5 years ago)
Author:
eugene
Message:

do not raise an error on min/max for an empty vector (nan result suffices)

File:
1 edited

Legend:

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

    r36290 r41494  
    353353    // Sort the temporary vector.
    354354    if (!psVectorSort(outVector, outVector)) { // Sort in-place (since it's a copy, it's OK)
    355         // an error in psVectorSort is a serious error
     355        // an error in psVectorSort is a serious error:
     356        // NULL input vector, psVectorCopy failure, invalid vector type
    356357        psError(PS_ERR_UNEXPECTED_NULL, false, _("Failed to sort input data."));
    357358        stats->sampleUQ = NAN;
     
    18881889    // ************************************************************************
    18891890    if (stats->options & PS_STAT_SAMPLE_MEAN) {
     1891        // NOTE: vectorSampleMean cannot return 'false'
    18901892        if (!vectorSampleMean(inF32, errorsF32, maskVector, maskVal, stats)) {
    18911893            psError(PS_ERR_UNKNOWN, false, "Failed to calculate vector sample mean");
     
    18961898    // ************************************************************************
    18971899    if (stats->options & (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_QUARTILE)) {
     1900        // NOTE: vectorSampleMedian only returns 'false' for very bad cases:
     1901        // NULL input vector, psVectorCopy failure, invalid vector type (likely programming errors)
    18981902        if (!vectorSampleMedian(inF32, maskVector, maskVal, stats)) {
    18991903            psError(PS_ERR_UNKNOWN, false, "Failed to calculate sample median");
     
    19041908    // ************************************************************************
    19051909    if (stats->options & PS_STAT_SAMPLE_STDEV) {
     1910        // NOTE: vectorSampleStdev cannot return 'false'
    19061911        if (!vectorSampleStdev(inF32, errorsF32, maskVector, maskVal, stats)) {
    19071912            psError(PS_ERR_UNKNOWN, false, "Failed to calculate sample stdev");
     
    19111916
    19121917    if (stats->options & (PS_STAT_SAMPLE_SKEWNESS | PS_STAT_SAMPLE_KURTOSIS)) {
     1918        // NOTE: vectorSampleMoments cannot return 'false'
    19131919        if (!vectorSampleMoments(inF32, maskVector, maskVal, stats)) {
    19141920            psError(PS_ERR_UNKNOWN, false, "Failed to calculate sample moments");
     
    19191925    // ************************************************************************
    19201926    if (stats->options & (PS_STAT_MAX | PS_STAT_MIN)) {
    1921         if (vectorMinMax(inF32, maskVector, maskVal, stats) == 0) {
    1922             psError(PS_ERR_UNKNOWN, false, "Failed to calculate vector minimum and maximum");
    1923             status &= false;
    1924         }
     1927        // NOTE: vectorMinMax returns 0 if there are no valid values,
     1928        // but this is not an error condition.  stats.min,max are set to NAN.
     1929        // vectorMinMax cannot raise an error
     1930        vectorMinMax(inF32, maskVector, maskVal, stats);
    19251931    }
    19261932
Note: See TracChangeset for help on using the changeset viewer.