IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1082


Ignore:
Timestamp:
Jun 24, 2004, 8:53:42 AM (22 years ago)
Author:
harman
Message:

Added more macros

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/dataManip/psMatrixVectorArithmetic.c

    r1065 r1082  
    2929 *  @author Ross Harman, MHPCC
    3030 *
    31  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    32  *  @date $Date: 2004-06-21 21:04:24 $
     31 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     32 *  @date $Date: 2004-06-24 18:53:42 $
    3333 *
    3434 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    7676/*****************************************************************************/
    7777
    78 #define MIN(A,B) (((A) < (B)) ? (A) : (B))
    79 
    80 #define MAX(A,B) (((A) > (B)) ? (A) : (B))
     78#define MIN(A,B)(((double)(A)<(double)(B))?(A):(B))
     79
     80#define MAX(A,B)(((double)(A)>(double)(B))?(A):(B))
    8181
    8282
     
    8585{                                                                                                            \
    8686    int i = 0;                                                                                               \
    87     int npt = 0;                                                                                             \
    88     ps##TYPE *o = NULL;                                                                                      \
    89     ps##TYPE *i1 = NULL;                                                                                     \
    90     ps##TYPE *i2 = NULL;                                                                                     \
    91     npt  = ((psVector*)IN1)->n;                                                                              \
     87    int n1 = 0;                                                                                              \
     88    ps##TYPE *o = NULL;                                                                                      \
     89    ps##TYPE *i1 = NULL;                                                                                     \
     90    ps##TYPE *i2 = NULL;                                                                                     \
     91    n1  = ((psVector*)IN1)->n;                                                                               \
    9292    o  = ((psVector*)OUT)->data.TYPE;                                                                        \
    9393    i1 = ((psVector*)IN1)->data.TYPE;                                                                        \
    9494    i2 = &((psScalar*)IN2)->data.TYPE;                                                                       \
    95     for (i=0; i < npt; i++, o++, i1++) {                                                                     \
     95    for (i=0; i < n1; i++, o++, i1++) {                                                                      \
    9696        *o = OP;                                                                                             \
    9797    }                                                                                                        \
     
    101101{                                                                                                            \
    102102    int i = 0;                                                                                               \
    103     int npt = 0;                                                                                             \
    104     ps##TYPE *o = NULL;                                                                                      \
    105     ps##TYPE *i1 = NULL;                                                                                     \
    106     ps##TYPE *i2 = NULL;                                                                                     \
    107     npt  = ((psVector*)IN1)->n;                                                                              \
     103    int n1 = 0;                                                                                              \
     104    int n2 = 0;                                                                                              \
     105    ps##TYPE *o = NULL;                                                                                      \
     106    ps##TYPE *i1 = NULL;                                                                                     \
     107    ps##TYPE *i2 = NULL;                                                                                     \
     108    n1  = ((psVector*)IN1)->n;                                                                               \
     109    n2  = ((psVector*)IN2)->n;                                                                               \
     110    if(n1 != n2) {                                                                                           \
     111        psError(__func__, ": Inconsistent element count: %d vs %d", n1, n2);                                \
     112        return OUT;                                                                                         \
     113    }                                                                                                        \
    108114    o  = ((psVector*)OUT)->data.TYPE;                                                                        \
    109115    i1 = ((psVector*)IN1)->data.TYPE;                                                                        \
    110116    i2 = ((psVector*)IN2)->data.TYPE;                                                                        \
    111     for (i=0; i < npt; i++, o++, i1++, i2++) {                                                               \
     117    for (i=0; i < n1; i++, o++, i1++, i2++) {                                                                \
    112118        *o = OP;                                                                                             \
    113119    }                                                                                                        \
    114120}
    115121
     122#define VECTOR_IMAGE(OUT,IN1,OP,IN2,TYPE)                                                                    \
     123{                                                                                                            \
     124    int i = 0;                                                                                               \
     125    int j = 0;                                                                                               \
     126    int n1 = 0;                                                                                              \
     127    int numRows2 = 0;                                                                                        \
     128    int numCols2 = 0;                                                                                        \
     129    psDimen dim1 = 0;                                                                                        \
     130    ps##TYPE *o = NULL;                                                                                      \
     131    ps##TYPE *i1 = NULL;                                                                                     \
     132    ps##TYPE *i2 = NULL;                                                                                     \
     133    n1  = ((psVector*)IN1)->n;                                                                               \
     134    dim1 = ((psVector*)IN1)->type.dimen;                                                                     \
     135    numRows2 = ((psImage*)IN2)->numRows;                                                                     \
     136    numCols2 = ((psImage*)IN2)->numCols;                                                                     \
     137    \
     138    if(dim1 == PS_DIMEN_VECTOR) { /* Regular vectors */                                                      \
     139        if(n1!=numRows2) {                                                                                   \
     140            psError(__func__, ": Inconsistent element count: %d vs %d", n1, numRows2);                      \
     141            return OUT;                                                                                     \
     142        }                                                                                                    \
     143        \
     144        i1 = ((psVector*)IN1)->data.TYPE;                                                                    \
     145        for(j = 0; j < numRows2; j++, i1++) {                                                                \
     146            o  = ((psImage*)OUT)->data.TYPE[j];                                                              \
     147            i2 = ((psImage*)IN2)->data.TYPE[j];                                                              \
     148            for(i = 0; i < numCols2; i++, o++, i2++) {                                                       \
     149                *o = OP;                                                                                     \
     150            }                                                                                                \
     151        }                                                                                                    \
     152    } else {  /* Transposed vectors */                                                                       \
     153        if(n1!=numCols2) {                                                                                   \
     154            psError(__func__, ": Inconsistent element count: %d vs %d", n1, numCols2);                       \
     155            return OUT;                                                                                      \
     156        }                                                                                                    \
     157        \
     158        for(j = 0; j < numRows2; j++) {                                                                     \
     159            o  = ((psImage*)OUT)->data.TYPE[j];                                                             \
     160            i1 = ((psVector*)IN1)->data.TYPE;                                                               \
     161            i2 = ((psImage*)IN2)->data.TYPE[j];                                                             \
     162            for(i = 0; i < numCols2; i++, o++, i1++, i2++) {                                                \
     163                *o = OP;                                                                                    \
     164            }                                                                                               \
     165        }                                                                                                   \
     166    }                                                                                                        \
     167}
    116168
    117169// IMAGE_XXXX operations
     
    127179    numRows = ((psImage*)IN1)->numRows;                                                                      \
    128180    numCols = ((psImage*)IN1)->numCols;                                                                      \
    129     for(j = 0; j < numCols; j++) {                                                                           \
     181    for(j = 0; j < numRows; j++) {                                                                           \
    130182        o  = ((psImage*)OUT)->data.TYPE[j];                                                                  \
    131183        i1 = ((psImage*)IN1)->data.TYPE[j];                                                                  \
    132184        i2 = &((psScalar*)IN2)->data.TYPE;                                                                   \
    133         for(i = 0; i < numRows; i++, o++, i1++) {                                                            \
     185        for(i = 0; i < numCols; i++, o++, i1++) {                                                            \
    134186            *o = OP;                                                                                         \
    135187        }                                                                                                    \
     
    137189}
    138190
     191#define IMAGE_VECTOR(OUT,IN1,OP,IN2,TYPE)                                                                    \
     192{                                                                                                            \
     193    int i = 0;                                                                                               \
     194    int j = 0;                                                                                               \
     195    int n2 = 0;                                                                                              \
     196    int numRows1 = 0;                                                                                        \
     197    int numCols1 = 0;                                                                                        \
     198    psDimen dim2 = 0;                                                                                        \
     199    ps##TYPE *o = NULL;                                                                                      \
     200    ps##TYPE *i1 = NULL;                                                                                     \
     201    ps##TYPE *i2 = NULL;                                                                                     \
     202    n2  = ((psVector*)IN2)->n;                                                                               \
     203    dim2 = ((psVector*)IN2)->type.dimen;                                                                     \
     204    numRows1 = ((psImage*)IN1)->numRows;                                                                     \
     205    numCols1 = ((psImage*)IN1)->numCols;                                                                     \
     206    \
     207    if(dim2 == PS_DIMEN_VECTOR) { /* Regular vectors */                                                      \
     208        if(n2!=numRows1) {                                                                                   \
     209            psError(__func__, ": Inconsistent element count: %d vs %d", n2, numRows1);                      \
     210            return OUT;                                                                                     \
     211        }                                                                                                    \
     212        \
     213        i2 = ((psVector*)IN2)->data.TYPE;                                                                    \
     214        for(j = 0; j < numRows1; j++, i1++) {                                                                \
     215            o  = ((psImage*)OUT)->data.TYPE[j];                                                              \
     216            i1 = ((psImage*)IN1)->data.TYPE[j];                                                              \
     217            for(i = 0; i < numCols1; i++, o++, i1++) {                                                       \
     218                *o = OP;                                                                                     \
     219            }                                                                                                \
     220        }                                                                                                    \
     221    } else {  /* Transposed vectors */                                                                       \
     222        if(n2!=numCols1) {                                                                                   \
     223            psError(__func__, ": Inconsistent element count: %d vs %d", n2, numCols1);                       \
     224            return OUT;                                                                                      \
     225        }                                                                                                    \
     226        \
     227        for(j = 0; j < numRows1; j++) {                                                                     \
     228            o  = ((psImage*)OUT)->data.TYPE[j];                                                             \
     229            i1 = ((psVector*)IN2)->data.TYPE;                                                               \
     230            i2 = ((psImage*)IN1)->data.TYPE[j];                                                             \
     231            for(i = 0; i < numCols1; i++, o++, i2++, i1++) {                                                \
     232                *o = OP;                                                                                    \
     233            }                                                                                               \
     234        }                                                                                                   \
     235    }                                                                                                        \
     236}
     237
    139238#define IMAGE_IMAGE(OUT,IN1,OP,IN2,TYPE)                                                                     \
    140239{                                                                                                            \
    141240    int i = 0;                                                                                               \
    142241    int j = 0;                                                                                               \
    143     int numRows = 0;                                                                                         \
    144     int numCols = 0;                                                                                         \
    145     ps##TYPE *o = NULL;                                                                                      \
    146     ps##TYPE *i1 = NULL;                                                                                     \
    147     ps##TYPE *i2 = NULL;                                                                                     \
    148     numRows = ((psImage*)IN1)->numRows;                                                                      \
    149     numCols = ((psImage*)IN1)->numCols;                                                                      \
    150     for(j = 0; j < numCols; j++) {                                                                           \
     242    int numRows1 = 0;                                                                                        \
     243    int numCols1 = 0;                                                                                        \
     244    int numRows2 = 0;                                                                                        \
     245    int numCols2 = 0;                                                                                        \
     246    ps##TYPE *o = NULL;                                                                                      \
     247    ps##TYPE *i1 = NULL;                                                                                     \
     248    ps##TYPE *i2 = NULL;                                                                                     \
     249    numRows1 = ((psImage*)IN1)->numRows;                                                                     \
     250    numCols1 = ((psImage*)IN1)->numCols;                                                                     \
     251    numRows2 = ((psImage*)IN2)->numRows;                                                                     \
     252    numCols2 = ((psImage*)IN2)->numCols;                                                                     \
     253    if(numRows1!=numRows2 || numCols1!=numCols2) {                                                           \
     254        psError(__func__, ": Inconsistent element count: numRows: %d vs %d numCols: %d vs %d", numRows1,    \
     255                numRows2, numCols1, numCols2);                                                                      \
     256        return OUT;                                                                                         \
     257    }                                                                                                        \
     258    for(j = 0; j < numRows1; j++) {                                                                          \
    151259        o  = ((psImage*)OUT)->data.TYPE[j];                                                                  \
    152260        i1 = ((psImage*)IN1)->data.TYPE[j];                                                                  \
    153261        i2 = ((psImage*)IN2)->data.TYPE[j];                                                                  \
    154         for(i = 0; i < numRows; i++, o++, i1++, i2++) {                                                      \
     262        for(i = 0; i < numCols1; i++, o++, i1++, i2++) {                                                     \
    155263            *o = OP;                                                                                         \
    156264        }                                                                                                    \
     
    161269#define SCALAR_SCALAR(OUT,IN1,OP,IN2,TYPE)                                                                   \
    162270{                                                                                                            \
    163     int i = 0;                                                                                               \
    164271    ps##TYPE *o = NULL;                                                                                      \
    165272    ps##TYPE *i1 = NULL;                                                                                     \
     
    187294}
    188295
    189 // SCALAR_XXXX operations
    190296#define SCALAR_IMAGE(OUT,IN1,OP,IN2,TYPE)                                                                    \
    191297{                                                                                                            \
     
    242348    break;                                                                                                   \
    243349case PS_TYPE_C32:                                                                                            \
    244     psError(__func__, ": Line %d - C32 support not implemented", __LINE__);                                  \
    245     /*DIM1##_##DIM2(OUT,IN1,OP,IN2,C32);       */                                                            \
     350    DIM1##_##DIM2(OUT,IN1,OP,IN2,C32);                                                                       \
    246351    break;                                                                                                   \
    247352case PS_TYPE_C64:                                                                                            \
    248     psError(__func__, ": Line %d - C64 support not implemented", __LINE__);                                  \
    249     /*DIM1##_##DIM2(OUT,IN1,OP,IN2,C64);         */                                                          \
     353    DIM1##_##DIM2(OUT,IN1,OP,IN2,C64);                                                                       \
    250354    break;                                                                                                   \
    251355default:                                                                                                     \
     
    257361    LEVEL1(DIM1,DIM2,OUT,IN1,*i1 + *i2,IN2);                                                                 \
    258362} else if(!strncmp(OP, "-", 1)) {                                                                            \
    259     LEVEL1(DIM1, DIM2,OUT,IN1,*i1 - *i2,IN2);                                                                \
     363    LEVEL1(DIM1,DIM2,OUT,IN1,*i1 - *i2,IN2);                                                                 \
    260364} else if(!strncmp(OP, "*", 1)) {                                                                            \
    261365    LEVEL1(DIM1,DIM2,OUT,IN1,*i1 * *i2,IN2);                                                                 \
     
    263367    LEVEL1(DIM1,DIM2,OUT,IN1,*i1 / *i2,IN2);                                                                 \
    264368} else if(!strncmp(OP, "^", 1)) {                                                                            \
    265     LEVEL1(DIM1,DIM2,OUT,IN1,pow(*i1,*i2),IN2);                                                              \
     369    if(PS_IS_PSELEMTYPE_COMPLEX(IN1->type)) {                                                                \
     370        LEVEL1(DIM1,DIM2,OUT,IN1,cpow(*i1,*i2),IN2);                                                         \
     371    } else {                                                                                                 \
     372        LEVEL1(DIM1,DIM2,OUT,IN1,pow(*i1,*i2),IN2);                                                          \
     373    }                                                                                                        \
    266374} else if(!strncmp(OP, "min", 3)) {                                                                          \
    267     LEVEL1(DIM1,DIM2,OUT,IN1,MIN(*i1,*i2),IN2);                                                              \
     375    LEVEL1(DIM1,DIM2,OUT,IN1,MIN(*i1,*i2),IN2);                                                          \
    268376} else if(!strncmp(OP, "max", 3)) {                                                                          \
    269     LEVEL1(DIM1,DIM2,OUT,IN1,MAX(*i1,*i2),IN2);                                                              \
     377    LEVEL1(DIM1,DIM2,OUT,IN1,MAX(*i1,*i2),IN2);                                                          \
    270378} else {                                                                                                     \
    271379    psError(__func__, ": Line %d - Invalid operator: %s", __LINE__, #OP);                                    \
     
    277385    psDimen dim2 = 0;
    278386    psDimen dimOut = 0;
     387    psElemType elType1 = 0;
     388    psElemType elType2 = 0;
     389    psElemType elTypeOut = 0;
    279390    psType *psType1 = NULL;
    280391    psType *psType2 = NULL;
     
    302413    dim2 = psType2->dimen;
    303414    dimOut = psTypeOut->dimen;
    304 
    305     if(dimOut == PS_DIMEN_OTHER) {
    306         psError(__func__, ": Line %d - Invalid dimensionality for out arg: %d", __LINE__, dimOut);
     415    elType1 = psType1->type;
     416    elType2 = psType2->type;
     417    elTypeOut = psTypeOut->type;
     418
     419    if(elType1!=elType2 &&  elType1!=elTypeOut) {
     420        psError(__func__, ": Line %d - Element types for arguments inconsistent: (%d, %d, %d)", __LINE__,
     421                elType1, elType2, elTypeOut);
    307422        return out;
    308423    }
    309424
    310     if(dim1 == PS_DIMEN_VECTOR) {
    311         if(dim2 == PS_DIMEN_VECTOR) {
    312             LEVEL2(VECTOR,VECTOR,out,psType1,op,psType2);       // vector op vector
     425    if(dim1==PS_DIMEN_OTHER || dim2==PS_DIMEN_OTHER || dimOut==PS_DIMEN_OTHER) {
     426        psError(__func__, ": Line %d - PS_DIMEN_OTHER not allowed for arguments: (%d, %d, %d)", __LINE__,
     427                dim1, dim2, dimOut);
     428        return out;
     429    }
     430
     431    if(dim1 == PS_DIMEN_SCALAR) {
     432        if(dim2 == PS_DIMEN_SCALAR) {
     433            LEVEL2(SCALAR,SCALAR,out,psType1,op,psType2);               // scalar op scalar
     434        } else if(dim2==PS_DIMEN_VECTOR || dim2==PS_DIMEN_TRANSV) {
     435            LEVEL2(SCALAR,VECTOR,out,psType1,op,psType2);               // scalar op vector
    313436        } else if(dim2 == PS_DIMEN_IMAGE) {
    314             //LEVEL2();              // vector op image
    315         } else if(dim2 == PS_DIMEN_SCALAR) {
    316             LEVEL2(VECTOR,VECTOR,out,psType1,op,psType2);               // vector op scalar
     437            LEVEL2(SCALAR,IMAGE,out,psType1,op,psType2);                // scalar op image
     438        } else {
     439            psError(__func__, ": Line %d - Invalid dimensionality for in2 arg: %d", __LINE__, dim2);
     440        }
     441    } else if(dim1==PS_DIMEN_VECTOR || dim1==PS_DIMEN_TRANSV) {
     442        if(dim2 == PS_DIMEN_SCALAR) {
     443            LEVEL2(VECTOR,SCALAR,out,psType1,op,psType2);               // vector op scalar
     444        } else if(dim2==PS_DIMEN_VECTOR || dim2==PS_DIMEN_TRANSV) {
     445            LEVEL2(VECTOR,VECTOR,out,psType1,op,psType2);               // vector op vector
     446        } else if(dim2 == PS_DIMEN_IMAGE) {
     447            LEVEL2(VECTOR,IMAGE,out,psType1,op,psType2);                // vector op image
    317448        } else {
    318449            psError(__func__, ": Line %d - Invalid dimensionality for in2 arg: %d", __LINE__, dim2);
    319450        }
    320451    } else if(dim1 == PS_DIMEN_IMAGE) {
    321         if(dim2 == PS_DIMEN_VECTOR) {
    322             //LEVEL2();              // image op vector
     452        if(dim2 == PS_DIMEN_SCALAR) {
     453            LEVEL2(IMAGE,SCALAR,out,psType1,op,psType2);                // image op scalar
     454        } else if(dim2==PS_DIMEN_VECTOR || dim2==PS_DIMEN_TRANSV) {
     455            LEVEL2(IMAGE,VECTOR,out,psType1,op,psType2);                // image op vector
    323456        } else if(dim2 == PS_DIMEN_IMAGE) {
    324             LEVEL2(IMAGE,IMAGE,out,psType1,op,psType2);             // image op image
    325         } else if(dim2 == PS_DIMEN_SCALAR) {
    326             LEVEL2(IMAGE,SCALAR,out,psType1,op,psType2);            // image op scalar
    327         } else {
    328             psError(__func__, ": Line %d - Invalid dimensionality for in2 arg: %d", __LINE__, dim2);
    329         }
    330     } else if(dim1 == PS_DIMEN_SCALAR) {
    331         if(dim2 == PS_DIMEN_VECTOR) {
    332             LEVEL2(SCALAR,VECTOR,out,psType1,op,psType2);           // scalar op vector
    333         } else if(dim2 == PS_DIMEN_IMAGE) {
    334             LEVEL2(SCALAR,IMAGE,out,psType1,op,psType2);            // scalar op image
     457            LEVEL2(IMAGE,IMAGE,out,psType1,op,psType2);                 // image op image
    335458        } else {
    336459            psError(__func__, ": Line %d - Invalid dimensionality for in2 arg: %d", __LINE__, dim2);
     
    342465    return out;
    343466}
    344 
    345 
    346 
    347 
Note: See TracChangeset for help on using the changeset viewer.