IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 10, 2004, 1:22:32 PM (22 years ago)
Author:
gusciora
Message:

Working with macros.

File:
1 edited

Legend:

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

    r2327 r2329  
    77 *  polynomials.  It also contains a Gaussian functions.
    88 *
    9  *  @version $Revision: 1.61 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-11-10 23:05:49 $
     9 *  @version $Revision: 1.62 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-11-10 23:22:32 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    18761876
    18771877/*****************************************************************************
    1878 vectorBinDisectF32(): This is a private function which takes as input a
    1879 vector of floating point data as well as a single floating point values.
    1880 The input vector values are assumed to be non-decreasing (v[i-1] <= v[j] for
    1881 all j>=i).  This routine does a binary disection of the vector and returns
    1882 "i" such that (v[i] <= x <= v[i+1).  If x lies outside the range of v[],
    1883 then this routine prints a warning message and returns (-2 or -1).
    1884  
    1885 XXX: Macro this for a few different types.
    1886  
    1887 XXX: name since we don't take psVectors as input.
     1878vectorBinDisectF32(): This is a macro for a private function which takes as
     1879input a vector an array of data as well as a single value for that data.  The
     1880input vector values are assumed to be non-decreasing (v[i-1] <= v[i] for all
     1881i).  This routine does a binary disection of the vector and returns "i" such
     1882that (v[i] <= x <= v[i+1).  If x lies outside the range of v[], then this
     1883routine prints a warning message and returns (-2 or -1).
    18881884 *****************************************************************************/
    1889 /*
    1890 static psS32 vectorBinDisectF32(float *bins,
    1891                                 psS32 numBins,
    1892                                 float x)
    1893 {
    1894     psS32 min;
    1895     psS32 max;
    1896     psS32 mid;
    1897  
    1898     psTrace(".psLib.dataManip.psFunctions.vectorBinDisectF32", 4,
    1899             "---- Calling vectorBinDisectF32(%f)\n", x);
    1900  
    1901     if (x < bins[0]) {
    1902         psLogMsg(__func__, PS_LOG_WARN,
    1903                  "vectorBinDisectF32(): ordinate %f is outside vector range (%f - %f).",
    1904                  x, bins[0], bins[numBins-1]);
    1905         return(-2);
    1906     }
    1907  
    1908     if (x > bins[numBins-1]) {
    1909         psLogMsg(__func__, PS_LOG_WARN,
    1910                  "vectorBinDisectF32(): ordinate %f is outside vector range (%f - %f).",
    1911                  x, bins[0], bins[numBins-1]);
    1912         return(-1);
    1913     }
    1914  
    1915     min = 0;
    1916     max = numBins-2;
    1917     mid = ((max+1)-min)/2;
    1918  
    1919     while (min != max) {
    1920         psTrace(".psLib.dataManip.psFunctions.vectorBinDisectF32", 4,
    1921                 "(min, mid, max) is (%d, %d, %d): (x, bins) is (%f, %f)\n",
    1922                 min, mid, max, x, bins[mid]);
    1923  
    1924         if (x == bins[mid]) {
    1925             psTrace(".psLib.dataManip.psFunctions.vectorBinDisectF32", 4,
    1926                     "---- Exiting vectorBinDisectF32(): bin %d\n", mid);
    1927             return(mid);
    1928         } else if (x < bins[mid]) {
    1929             max = mid-1;
    1930         } else {
    1931             min = mid;
    1932         }
    1933         mid = ((max+1)+min)/2;
    1934     }
    1935  
    1936     psTrace(".psLib.dataManip.psFunctions.vectorBinDisectF32", 4,
    1937             "---- Exiting vectorBinDisectF32(): bin %d\n", min);
    1938     return(min);
    1939 }
    1940 */
    1941 /*****************************************************************************
    1942 vectorBinDisectS32(): integer version of above.
    1943  *****************************************************************************/
    1944 /*
    1945 static psS32 vectorBinDisectS32(psS32 *bins,
    1946                                 psS32 numBins,
    1947                                 psS32 x)
    1948 {
    1949     psS32 min;
    1950     psS32 max;
    1951     psS32 mid;
    1952  
    1953     psTrace(".psLib.dataManip.psFunctions.vectorBinDisectS32", 4,
    1954             "---- Calling vectorBinDisectS32(%f)\n", x);
    1955  
    1956     if ((x < bins[0]) ||
    1957             (x > bins[numBins-1])) {
    1958         psLogMsg(__func__, PS_LOG_WARN,
    1959                  "vectorBinDisectS32(): ordinate %f is outside vector range (%f - %f).",
    1960                  x, bins[0], bins[numBins-1]);
    1961         return(-1);
    1962     }
    1963  
    1964     min = 0;
    1965     max = numBins-2;
    1966     mid = ((max+1)-min)/2;
    1967  
    1968     while (min != max) {
    1969         psTrace(".psLib.dataManip.psFunctions.vectorBinDisectS32", 4,
    1970                 "(min, mid, max) is (%d, %d, %d): (x, bins) is (%f, %f)\n",
    1971                 min, mid, max, x, bins[mid]);
    1972  
    1973         if (x == bins[mid]) {
    1974             psTrace(".psLib.dataManip.psFunctions.vectorBinDisectS32", 4,
    1975                     "---- Exiting vectorBinDisectS32(): bin %d\n", min);
    1976             return(min);
    1977         } else if (x < bins[mid]) {
    1978             max = mid-1;
    1979         } else {
    1980             min = mid;
    1981         }
    1982         mid = ((max+1)+min)/2;
    1983     }
    1984  
    1985     psTrace(".psLib.dataManip.psFunctions.vectorBinDisectS32", 4,
    1986             "---- Exiting vectorBinDisectS32(): bin %d\n", min);
    1987     return(min);
    1988 }
    1989 */
    1990 
    19911885#define FUNC_MACRO_VECTOR_BIN_DISECT(TYPE) \
    19921886static psS32 vectorBinDisect##TYPE(ps##TYPE *bins, \
     
    20581952                          psScalar *x)
    20591953{
    2060     PS_PTR_CHECK_TYPE_EQUAL(x, bins, -2);
    2061 
    2062     if (x->type.type == PS_TYPE_S32) {
     1954    PS_PTR_CHECK_TYPE_EQUAL(x, bins, -3);
     1955
     1956    switch (x->type.type) {
     1957    case PS_TYPE_U8:
     1958        return(vectorBinDisectU8(bins->data.U8, bins->n, x->data.U8));
     1959    case PS_TYPE_U16:
     1960        return(vectorBinDisectU16(bins->data.U16, bins->n, x->data.U16));
     1961    case PS_TYPE_U32:
     1962        return(vectorBinDisectU32(bins->data.U32, bins->n, x->data.U32));
     1963    case PS_TYPE_U64:
     1964        return(vectorBinDisectU64(bins->data.U64, bins->n, x->data.U64));
     1965    case PS_TYPE_S8:
     1966        return(vectorBinDisectS8(bins->data.S8, bins->n, x->data.S8));
     1967    case PS_TYPE_S16:
     1968        return(vectorBinDisectS16(bins->data.S16, bins->n, x->data.S16));
     1969    case PS_TYPE_S32:
    20631970        return(vectorBinDisectS32(bins->data.S32, bins->n, x->data.S32));
    2064     } else if (x->type.type == PS_TYPE_F32) {
     1971    case PS_TYPE_S64:
     1972        return(vectorBinDisectS64(bins->data.S64, bins->n, x->data.S64));
     1973    case PS_TYPE_F32:
    20651974        return(vectorBinDisectF32(bins->data.F32, bins->n, x->data.F32));
    2066     } else {
    2067         char* strType;
    2068         PS_TYPE_NAME(strType,x->type.type);
    2069         psError(PS_ERR_BAD_PARAMETER_TYPE,
    2070                 PS_ERRORTEXT_psFunctions_TYPE_NOT_SUPPORTED,
    2071                 strType);
    2072         return(-2);
    2073     }
    2074     return(-1);
     1975    case PS_TYPE_F64:
     1976        return(vectorBinDisectF64(bins->data.F64, bins->n, x->data.F64));
     1977    }
     1978
     1979    char* strType;
     1980    PS_TYPE_NAME(strType,x->type.type);
     1981    psError(PS_ERR_BAD_PARAMETER_TYPE,
     1982            PS_ERRORTEXT_psFunctions_TYPE_NOT_SUPPORTED,
     1983            strType);
     1984    return(-3);
    20751985}
    20761986
Note: See TracChangeset for help on using the changeset viewer.