Changeset 1082
- Timestamp:
- Jun 24, 2004, 8:53:42 AM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/dataManip/psMatrixVectorArithmetic.c
r1065 r1082 29 29 * @author Ross Harman, MHPCC 30 30 * 31 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $32 * @date $Date: 2004-06-2 1 21:04:24$31 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 32 * @date $Date: 2004-06-24 18:53:42 $ 33 33 * 34 34 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 76 76 /*****************************************************************************/ 77 77 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)) 81 81 82 82 … … 85 85 { \ 86 86 int i = 0; \ 87 int n pt = 0;\88 ps##TYPE *o = NULL; \ 89 ps##TYPE *i1 = NULL; \ 90 ps##TYPE *i2 = NULL; \ 91 n pt = ((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; \ 92 92 o = ((psVector*)OUT)->data.TYPE; \ 93 93 i1 = ((psVector*)IN1)->data.TYPE; \ 94 94 i2 = &((psScalar*)IN2)->data.TYPE; \ 95 for (i=0; i < n pt; i++, o++, i1++) {\95 for (i=0; i < n1; i++, o++, i1++) { \ 96 96 *o = OP; \ 97 97 } \ … … 101 101 { \ 102 102 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 } \ 108 114 o = ((psVector*)OUT)->data.TYPE; \ 109 115 i1 = ((psVector*)IN1)->data.TYPE; \ 110 116 i2 = ((psVector*)IN2)->data.TYPE; \ 111 for (i=0; i < n pt; i++, o++, i1++, i2++) {\117 for (i=0; i < n1; i++, o++, i1++, i2++) { \ 112 118 *o = OP; \ 113 119 } \ 114 120 } 115 121 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 } 116 168 117 169 // IMAGE_XXXX operations … … 127 179 numRows = ((psImage*)IN1)->numRows; \ 128 180 numCols = ((psImage*)IN1)->numCols; \ 129 for(j = 0; j < num Cols; j++) { \181 for(j = 0; j < numRows; j++) { \ 130 182 o = ((psImage*)OUT)->data.TYPE[j]; \ 131 183 i1 = ((psImage*)IN1)->data.TYPE[j]; \ 132 184 i2 = &((psScalar*)IN2)->data.TYPE; \ 133 for(i = 0; i < num Rows; i++, o++, i1++) { \185 for(i = 0; i < numCols; i++, o++, i1++) { \ 134 186 *o = OP; \ 135 187 } \ … … 137 189 } 138 190 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 139 238 #define IMAGE_IMAGE(OUT,IN1,OP,IN2,TYPE) \ 140 239 { \ 141 240 int i = 0; \ 142 241 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++) { \ 151 259 o = ((psImage*)OUT)->data.TYPE[j]; \ 152 260 i1 = ((psImage*)IN1)->data.TYPE[j]; \ 153 261 i2 = ((psImage*)IN2)->data.TYPE[j]; \ 154 for(i = 0; i < num Rows; i++, o++, i1++, i2++) {\262 for(i = 0; i < numCols1; i++, o++, i1++, i2++) { \ 155 263 *o = OP; \ 156 264 } \ … … 161 269 #define SCALAR_SCALAR(OUT,IN1,OP,IN2,TYPE) \ 162 270 { \ 163 int i = 0; \164 271 ps##TYPE *o = NULL; \ 165 272 ps##TYPE *i1 = NULL; \ … … 187 294 } 188 295 189 // SCALAR_XXXX operations190 296 #define SCALAR_IMAGE(OUT,IN1,OP,IN2,TYPE) \ 191 297 { \ … … 242 348 break; \ 243 349 case 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); \ 246 351 break; \ 247 352 case 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); \ 250 354 break; \ 251 355 default: \ … … 257 361 LEVEL1(DIM1,DIM2,OUT,IN1,*i1 + *i2,IN2); \ 258 362 } else if(!strncmp(OP, "-", 1)) { \ 259 LEVEL1(DIM1, DIM2,OUT,IN1,*i1 - *i2,IN2);\363 LEVEL1(DIM1,DIM2,OUT,IN1,*i1 - *i2,IN2); \ 260 364 } else if(!strncmp(OP, "*", 1)) { \ 261 365 LEVEL1(DIM1,DIM2,OUT,IN1,*i1 * *i2,IN2); \ … … 263 367 LEVEL1(DIM1,DIM2,OUT,IN1,*i1 / *i2,IN2); \ 264 368 } 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 } \ 266 374 } 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); \ 268 376 } 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); \ 270 378 } else { \ 271 379 psError(__func__, ": Line %d - Invalid operator: %s", __LINE__, #OP); \ … … 277 385 psDimen dim2 = 0; 278 386 psDimen dimOut = 0; 387 psElemType elType1 = 0; 388 psElemType elType2 = 0; 389 psElemType elTypeOut = 0; 279 390 psType *psType1 = NULL; 280 391 psType *psType2 = NULL; … … 302 413 dim2 = psType2->dimen; 303 414 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); 307 422 return out; 308 423 } 309 424 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 313 436 } 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 317 448 } else { 318 449 psError(__func__, ": Line %d - Invalid dimensionality for in2 arg: %d", __LINE__, dim2); 319 450 } 320 451 } 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 323 456 } 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 335 458 } else { 336 459 psError(__func__, ": Line %d - Invalid dimensionality for in2 arg: %d", __LINE__, dim2); … … 342 465 return out; 343 466 } 344 345 346 347
Note:
See TracChangeset
for help on using the changeset viewer.
