Changeset 2021
- Timestamp:
- Oct 7, 2004, 4:48:01 PM (22 years ago)
- Location:
- trunk/psLib
- Files:
-
- 1 added
- 8 edited
-
psLib.kdevelop.pcs (modified) ( previous)
-
psLib.kdevses (modified) (4 diffs)
-
src/dataManip/psMatrix.c (modified) (5 diffs)
-
src/dataManip/psMatrixVectorArithmetic.c (modified) (25 diffs)
-
src/math/psMatrix.c (modified) (5 diffs)
-
test/astronomy/verified/tst_psAstrometry.stderr (added)
-
test/dataManip/tst_psMatrixVectorArithmetic03.c (modified) (6 diffs)
-
test/dataManip/verified/tst_psMatrixVectorArithmetic03.stderr (modified) (3 diffs)
-
test/dataManip/verified/tst_psMatrixVectorArithmetic03.stdout (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/psLib.kdevses
r1984 r2021 2 2 <!DOCTYPE KDevPrjSession> 3 3 <KDevPrjSession> 4 <DocsAndViews NumberOfDocuments=" 6" >4 <DocsAndViews NumberOfDocuments="15" > 5 5 <Doc0 NumberOfViews="1" URL="file:/home/desonia/psLib/src/image/psImageConvolve.c" > 6 6 <View0 line="412" Type="???" > … … 10 10 <Doc1 NumberOfViews="1" URL="file:/home/desonia/psLib/src/image/psImageFFT.c" > 11 11 <View0 line="36" Type="???" > 12 <AdditionalSettings Top="2" Width="1 181" Attach="1" Height="701" Left="2" MinMaxMode="0" />12 <AdditionalSettings Top="2" Width="1526" Attach="1" Height="1007" Left="2" MinMaxMode="0" /> 13 13 </View0> 14 14 </Doc1> … … 29 29 </Doc4> 30 30 <Doc5 NumberOfViews="1" URL="file:/home/desonia/psLib/src/collections/psVector.c" > 31 <View0 line=" 86" Type="???" >32 <AdditionalSettings Top="2" Width="1 181" Attach="1" Height="701" Left="2" MinMaxMode="0" />31 <View0 line="100" Type="???" > 32 <AdditionalSettings Top="2" Width="1212" Attach="1" Height="809" Left="2" MinMaxMode="0" /> 33 33 </View0> 34 34 </Doc5> 35 <Doc6 NumberOfViews="1" URL="file:/home/desonia/psLib/src/dataManip/psMatrix.c" > 36 <View0 line="212" Type="???" > 37 <AdditionalSettings Top="2" Width="1212" Attach="1" Height="809" Left="2" MinMaxMode="0" /> 38 </View0> 39 </Doc6> 40 <Doc7 NumberOfViews="1" URL="file:/home/desonia/psLib/src/dataManip/psFunctions.c" > 41 <View0 line="0" Type="???" > 42 <AdditionalSettings Top="2" Width="1212" Attach="1" Height="809" Left="2" MinMaxMode="0" /> 43 </View0> 44 </Doc7> 45 <Doc8 NumberOfViews="1" URL="file:/home/desonia/psLib/src/dataManip/psMatrixVectorArithmetic.c" > 46 <View0 line="684" Type="???" > 47 <AdditionalSettings Top="2" Width="1212" Attach="1" Height="538" Left="2" MinMaxMode="0" /> 48 </View0> 49 </Doc8> 50 <Doc9 NumberOfViews="1" URL="file:/home/desonia/psLib/src/collections/psScalar.c" > 51 <View0 line="0" Type="???" > 52 <AdditionalSettings Top="2" Width="1212" Attach="1" Height="809" Left="2" MinMaxMode="0" /> 53 </View0> 54 </Doc9> 55 <Doc10 NumberOfViews="1" URL="file:/home/desonia/psLib/src/collections/psScalar.h" > 56 <View0 line="0" Type="???" > 57 <AdditionalSettings Top="2" Width="1212" Attach="1" Height="807" Left="2" MinMaxMode="0" /> 58 </View0> 59 </Doc10> 60 <Doc11 NumberOfViews="1" URL="file:/home/desonia/psLib/src/sysUtils/psType.h" > 61 <View0 line="196" Type="???" > 62 <AdditionalSettings Top="2" Width="1212" Attach="1" Height="771" Left="2" MinMaxMode="0" /> 63 </View0> 64 </Doc11> 65 <Doc12 NumberOfViews="1" URL="file:/home/desonia/psLib/test/dataManip/tst_psMatrixVectorArithmetic01.c" > 66 <View0 line="202" Type="???" > 67 <AdditionalSettings Top="2" Width="1212" Attach="1" Height="538" Left="2" MinMaxMode="0" /> 68 </View0> 69 </Doc12> 70 <Doc13 NumberOfViews="1" URL="file:/home/desonia/psLib/test/dataManip/tst_psMatrixVectorArithmetic02.c" > 71 <View0 line="265" Type="???" > 72 <AdditionalSettings Top="2" Width="1212" Attach="1" Height="538" Left="2" MinMaxMode="0" /> 73 </View0> 74 </Doc13> 75 <Doc14 NumberOfViews="1" URL="file:/home/desonia/psLib/test/dataManip/tst_psMatrixVectorArithmetic03.c" > 76 <View0 line="199" Type="???" > 77 <AdditionalSettings Top="2" Width="1212" Attach="1" Height="538" Left="2" MinMaxMode="0" /> 78 </View0> 79 </Doc14> 35 80 </DocsAndViews> 36 81 <pluginList> … … 41 86 <mark line="652" /> 42 87 <mark line="593" /> 88 </bookmark> 89 <bookmark url="/home/desonia/psLib/src/dataManip/psMatrixVectorArithmetic.c" > 90 <mark line="60" /> 43 91 </bookmark> 44 92 <bookmark url="/home/desonia/psLib/src/collections/psBitSet.c" > -
trunk/psLib/src/dataManip/psMatrix.c
r1845 r2021 1 2 1 /** @file psMatrix.c 3 2 * … … 21 20 * @author Ross Harman, MHPCC 22 21 * 23 * @version $Revision: 1.1 4$ $Name: not supported by cvs2svn $24 * @date $Date: 2004- 09-21 23:44:10$22 * @version $Revision: 1.15 $ $Name: not supported by cvs2svn $ 23 * @date $Date: 2004-10-08 02:48:01 $ 25 24 * 26 25 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 28 27 29 28 /******************************************************************************/ 30 31 29 /* INCLUDE FILES */ 32 33 30 /******************************************************************************/ 34 31 #include <string.h> … … 44 41 #include "psMatrix.h" 45 42 46 /******************************************************************************/47 48 /* DEFINE STATEMENTS */49 50 /******************************************************************************/51 52 // None53 54 /******************************************************************************/55 56 /* TYPE DEFINITIONS */57 58 /******************************************************************************/59 60 // None61 62 /*****************************************************************************/63 64 /* GLOBAL VARIABLES */65 66 /*****************************************************************************/67 68 // None69 70 /*****************************************************************************/71 72 /* FILE STATIC VARIABLES */73 74 /*****************************************************************************/75 76 // None77 78 /*****************************************************************************/79 80 /* FUNCTION IMPLEMENTATION - LOCAL */81 82 /*****************************************************************************/83 84 43 /** Preprocessor macro to generate error a NULL image */ 85 44 #define PS_CHECK_NULL_VECTOR(NAME, RETURN) \ … … 155 114 156 115 /*****************************************************************************/ 157 158 116 /* FUNCTION IMPLEMENTATION - PUBLIC */ 159 160 117 /*****************************************************************************/ 161 118 -
trunk/psLib/src/dataManip/psMatrixVectorArithmetic.c
r1648 r2021 1 2 1 /** @file psMatrixVectorArithmetic.c 3 2 * … … 30 29 * @author Ross Harman, MHPCC 31 30 * 32 * @version $Revision: 1.2 7$ $Name: not supported by cvs2svn $33 * @date $Date: 2004- 08-27 23:33:31 $31 * @version $Revision: 1.28 $ $Name: not supported by cvs2svn $ 32 * @date $Date: 2004-10-08 02:48:01 $ 34 33 * 35 34 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 36 35 */ 37 36 38 /******************************************************************************/ 39 40 /* INCLUDE FILES */ 41 42 /******************************************************************************/ 37 /****************************************************************************** 38 * INCLUDE FILES * 39 ******************************************************************************/ 43 40 #include <string.h> 44 41 #include <math.h> … … 50 47 #include "psVector.h" 51 48 #include "psScalar.h" 52 53 /******************************************************************************/ 54 55 /* DEFINE STATEMENTS */ 56 57 /******************************************************************************/ 58 59 // None 60 61 /******************************************************************************/ 62 63 /* TYPE DEFINITIONS */ 64 65 /******************************************************************************/ 66 67 // None 68 69 /*****************************************************************************/ 70 71 /* GLOBAL VARIABLES */ 72 73 /*****************************************************************************/ 74 75 // None 76 77 /*****************************************************************************/ 78 79 /* FILE STATIC VARIABLES */ 80 81 /*****************************************************************************/ 82 83 // None 84 85 /*****************************************************************************/ 86 87 /* FUNCTION IMPLEMENTATION - LOCAL */ 88 89 /*****************************************************************************/ 49 #include "psLogMsg.h" 50 51 /***************************************************************************** 52 * FUNCTION IMPLEMENTATION - LOCAL * 53 *****************************************************************************/ 90 54 91 55 // Conversion for degrees to radians … … 95 59 #define R2D 57.29577950924861 /* 180.0/PI */ 96 60 61 /* IEEE Standards on floating-point makes this function pointless, really. 97 62 // Division with NAN checking 98 63 static complex double psNanDiv(complex double a, complex double b) 99 64 { 100 65 complex double out = 0 + 0i; 101 66 102 67 out = a / b; 103 68 if (isnan(creal(out)) || isnan(cimag(out))) { 104 69 psError(__func__, ": Divide by zero"); 105 70 } 106 71 107 72 return out; 108 73 } 74 */ 109 75 110 76 // Binary SCALAR_XXXX operations … … 186 152 if(n1 != n2) { \ 187 153 psError(__func__, ": Inconsistent element count: %d vs %d", n1, n2); \ 188 return OUT; \ 154 if (OUT != IN1 && OUT != IN2) { \ 155 psFree(OUT); \ 156 } \ 157 return NULL; \ 189 158 } \ 190 159 o = ((psVector* )OUT)->data.TYPE; \ … … 215 184 if(n1!=numRows2) { \ 216 185 psError(__func__, ": Inconsistent element count: %d vs %d", n1, numRows2); \ 217 return OUT; \ 186 if (OUT != IN1 && OUT != IN2) { \ 187 psFree(OUT); \ 188 } \ 189 return NULL; \ 218 190 } \ 219 191 \ … … 229 201 if(n1!=numCols2) { \ 230 202 psError(__func__, ": Inconsistent element count: %d vs %d", n1, numCols2); \ 231 return OUT; \ 203 if (OUT != IN1 && OUT != IN2) { \ 204 psFree(OUT); \ 205 } \ 206 return NULL; \ 232 207 } \ 233 208 \ … … 284 259 if(n2!=numRows1) { \ 285 260 psError(__func__, ": Inconsistent element count: %d vs %d", n2, numRows1); \ 286 return OUT; \ 261 if (OUT != IN1 && OUT != IN2) { \ 262 psFree(OUT); \ 263 } \ 264 return NULL; \ 287 265 } \ 288 266 \ … … 298 276 if(n2!=numCols1) { \ 299 277 psError(__func__, ": Inconsistent element count: %d vs %d", n2, numCols1); \ 300 return OUT; \ 278 if (OUT != IN1) { \ 279 psFree(OUT); \ 280 } \ 281 return NULL; \ 301 282 } \ 302 283 \ … … 330 311 psError(__func__, ": Inconsistent element count: numRows: %d vs %d numCols: %d vs %d", numRows1, \ 331 312 numRows2, numCols1, numCols2); \ 332 return OUT; \ 313 if (OUT != IN1 && OUT != IN2) { \ 314 psFree(OUT); \ 315 } \ 316 return NULL; \ 333 317 } \ 334 318 for(j = 0; j < numRows1; j++) { \ … … 345 329 #define BINARY_TYPE(DIM1,DIM2,OUT,IN1,OP,IN2) \ 346 330 switch (IN1->type) { \ 331 case PS_TYPE_U8: \ 332 DIM1##_##DIM2(OUT,IN1,OP,IN2,U8); \ 333 break; \ 334 case PS_TYPE_U16: \ 335 DIM1##_##DIM2(OUT,IN1,OP,IN2,U16); \ 336 break; \ 337 case PS_TYPE_U32: \ 338 DIM1##_##DIM2(OUT,IN1,OP,IN2,U32); \ 339 break; \ 340 case PS_TYPE_U64: \ 341 DIM1##_##DIM2(OUT,IN1,OP,IN2,U64); \ 342 break; \ 343 case PS_TYPE_S8: \ 344 DIM1##_##DIM2(OUT,IN1,OP,IN2,S8); \ 345 break; \ 346 case PS_TYPE_S16: \ 347 DIM1##_##DIM2(OUT,IN1,OP,IN2,S16); \ 348 break; \ 347 349 case PS_TYPE_S32: \ 348 350 DIM1##_##DIM2(OUT,IN1,OP,IN2,S32); \ 349 351 break; \ 352 case PS_TYPE_S64: \ 353 DIM1##_##DIM2(OUT,IN1,OP,IN2,S64); \ 354 break; \ 350 355 case PS_TYPE_F32: \ 351 356 DIM1##_##DIM2(OUT,IN1,OP,IN2,F32); \ … … 357 362 DIM1##_##DIM2(OUT,IN1,OP,IN2,C32); \ 358 363 break; \ 364 case PS_TYPE_C64: \ 365 DIM1##_##DIM2(OUT,IN1,OP,IN2,C64); \ 366 break; \ 359 367 default: \ 360 case PS_TYPE_S8: \361 case PS_TYPE_U8: \362 case PS_TYPE_S16: \363 case PS_TYPE_U16: \364 case PS_TYPE_U32: \365 case PS_TYPE_S64: \366 case PS_TYPE_U64: \367 case PS_TYPE_C64: \368 368 psError(__func__, ": Invalid PS_TYPE: %d", IN1->type); \ 369 if (OUT != IN1 && OUT != IN2) { \ 370 psFree(OUT); \ 371 } \ 372 return NULL; \ 369 373 } 370 374 … … 378 382 BINARY_TYPE(DIM1,DIM2,OUT,IN1,*i1 * *i2,IN2); \ 379 383 } else if(!strncmp(OP, "/", 1)) { \ 380 BINARY_TYPE(DIM1,DIM2,OUT,IN1, psNanDiv(*i1,*i2),IN2); \384 BINARY_TYPE(DIM1,DIM2,OUT,IN1,*i1 / *i2,IN2); \ 381 385 } else if(!strncmp(OP, "^", 1)) { \ 382 386 if(PS_IS_PSELEMTYPE_COMPLEX(IN1->type)) { \ … … 388 392 if(PS_IS_PSELEMTYPE_COMPLEX(IN1->type)) { \ 389 393 psError(__func__, ": Minimum operation not supported for complex numbers"); \ 394 if (OUT != IN1 && OUT != IN2) { \ 395 psFree(OUT); \ 396 } \ 397 return NULL; \ 390 398 } else { \ 391 399 BINARY_TYPE(DIM1,DIM2,OUT,IN1,fmin(*i1,*i2),IN2); \ … … 394 402 if(PS_IS_PSELEMTYPE_COMPLEX(IN1->type)) { \ 395 403 psError(__func__, ": Maximum operation not supported for complex numbers"); \ 404 if (OUT != IN1 && OUT != IN2) { \ 405 psFree(OUT); \ 406 } \ 407 return NULL; \ 396 408 } else { \ 397 409 BINARY_TYPE(DIM1,DIM2,OUT,IN1,fmax(*i1,*i2),IN2); \ … … 399 411 } else { \ 400 412 psError(__func__, ": Invalid operation: %s", OP); \ 413 if (OUT != IN1 && OUT != IN2) { \ 414 psFree(OUT); \ 415 } \ 416 return NULL; \ 401 417 } 402 418 … … 405 421 psDimen dim1 = 0; 406 422 psDimen dim2 = 0; 407 psDimen dimOut = 0;408 423 psElemType elType1 = 0; 409 424 psElemType elType2 = 0; 410 psElemType elTypeOut = 0;411 425 psType* psType1 = NULL; 412 426 psType* psType2 = NULL; 413 psType* psTypeOut = NULL;414 415 psTypeOut = (psType* ) out;416 if (psTypeOut == NULL) {417 psError(__func__, ": Line %d - Null out argument", __LINE__);418 return out;419 }420 427 421 428 psType1 = (psType* ) in1; 422 429 if (psType1 == NULL) { 423 430 psError(__func__, ": Line %d - Null in1 argument", __LINE__); 424 return out; 431 if (out != in1 && out != in2) { 432 psFree(out); 433 } 434 return NULL; 425 435 } 426 436 … … 428 438 if (psType2 == NULL) { 429 439 psError(__func__, ": Line %d - Null in2 argument", __LINE__); 430 return out; 440 if (out != in1 && out != in2) { 441 psFree(out); 442 } 443 return NULL; 431 444 } 432 445 433 446 if (op == NULL) { 434 447 psError(__func__, ": Line %d - Null op argument", __LINE__); 435 return out; 448 if (out != in1 && out != in2) { 449 psFree(out); 450 } 451 return NULL; 436 452 } 437 453 438 454 dim1 = psType1->dimen; 439 455 dim2 = psType2->dimen; 440 dimOut = psTypeOut->dimen;441 456 elType1 = psType1->type; 442 457 elType2 = psType2->type; 443 elTypeOut = psTypeOut->type; 444 445 if (elType1 != elType2 && elType1 != elTypeOut) { 446 psError(__func__, ": Line %d - Element types for arguments inconsistent: (%d, %d, %d)", __LINE__, 447 elType1, elType2, elTypeOut); 448 return out; 449 } 450 451 if (dim1 == PS_DIMEN_OTHER || dim2 == PS_DIMEN_OTHER || dimOut == PS_DIMEN_OTHER) { 452 psError(__func__, ": Line %d - PS_DIMEN_OTHER not allowed for arguments: (%d, %d, %d)", __LINE__, 453 dim1, dim2, dimOut); 454 return out; 455 } 456 457 if (dim1 == PS_DIMEN_VECTOR) { 458 459 if (elType1 != elType2) { 460 psError(__func__, ": Line %d - Element types for arguments inconsistent: (%d, %d)", __LINE__, 461 elType1, elType2); 462 if (out != in1 && out != in2) { 463 psFree(out); 464 } 465 return NULL; 466 } 467 468 if (dim1 == PS_DIMEN_OTHER || dim2 == PS_DIMEN_OTHER) { 469 psError(__func__, ": Line %d - PS_DIMEN_OTHER not allowed for arguments: (%d, %d)", __LINE__, 470 dim1, dim2); 471 if (out != in1 && out != in2) { 472 psFree(out); 473 } 474 return NULL; 475 } 476 477 if (dim1 == PS_DIMEN_VECTOR || dim1 == PS_DIMEN_TRANSV) { 458 478 if (((psVector* ) in1)->n == 0) { 459 ps Error(__func__, ": Line %d - Vector contains zero elements");479 psLogMsg(__func__, PS_LOG_WARN, ": Line %d - Vector contains zero elements"); 460 480 } 461 481 } else if (dim1 == PS_DIMEN_IMAGE) { 462 482 if (((psImage* ) in1)->numCols == 0 || ((psImage* ) in1)->numRows == 0) { 463 ps Error(__func__, ": Line %d - Image contains zero length row or cols");464 } 465 } 466 467 if (dim2 == PS_DIMEN_VECTOR ) {483 psLogMsg(__func__, PS_LOG_WARN, ": Line %d - Image contains zero length row or cols"); 484 } 485 } 486 487 if (dim2 == PS_DIMEN_VECTOR || dim2 == PS_DIMEN_TRANSV) { 468 488 if (((psVector* ) in2)->n == 0) { 469 ps Error(__func__, ": Line %d - Vector contains zero elements");489 psLogMsg(__func__, PS_LOG_WARN, ": Line %d - Vector contains zero elements"); 470 490 } 471 491 } else if (dim2 == PS_DIMEN_IMAGE) { 472 492 if (((psImage* ) in2)->numCols == 0 || ((psImage* ) in2)->numRows == 0) { 473 ps Error(__func__, ": Line %d - Image contains zero length row or cols");493 psLogMsg(__func__, PS_LOG_WARN, ": Line %d - Image contains zero length row or cols"); 474 494 } 475 495 } 476 496 477 497 if (dim1 == PS_DIMEN_SCALAR) { 498 if ( out != NULL && ((psType*)out)->dimen != dim2) { 499 if (out != in1 && out != in2) { 500 psFree(out); 501 } 502 out = NULL; 503 } 478 504 if (dim2 == PS_DIMEN_SCALAR) { 505 if (out == NULL || ((psScalar*)out)->type.type != elType1) { 506 if (out != in1 && out != in2) { 507 psFree(out); 508 } 509 out = psScalarAlloc(0.0,elType1); 510 } 479 511 BINARY_OP(SCALAR, SCALAR, out, psType1, op, psType2); // scalar op scalar 480 512 } else if (dim2 == PS_DIMEN_VECTOR || dim2 == PS_DIMEN_TRANSV) { 513 out = psVectorRecycle(out,((psVector*)in2)->n,elType1); 514 if (out == NULL) { 515 psError(__func__, "Couldn't create a proper output psVector."); 516 return NULL; 517 } 481 518 BINARY_OP(SCALAR, VECTOR, out, psType1, op, psType2); // scalar op vector 482 519 } else if (dim2 == PS_DIMEN_IMAGE) { 520 out = psImageRecycle(out, ((psImage* ) in2)->numCols, ((psImage* ) in2)->numRows,elType1); 521 if (out == NULL) { 522 psError(__func__, "Couldn't create a proper output psImage."); 523 return NULL; 524 } 483 525 BINARY_OP(SCALAR, IMAGE, out, psType1, op, psType2); // scalar op image 484 526 } else { … … 487 529 } else if (dim1 == PS_DIMEN_VECTOR || dim1 == PS_DIMEN_TRANSV) { 488 530 if (dim2 == PS_DIMEN_SCALAR) { 531 out = psVectorRecycle(out,((psVector*)in1)->n,elType1); 532 if (out == NULL) { 533 psError(__func__, "Couldn't create a proper output psVector."); 534 return NULL; 535 } 489 536 BINARY_OP(VECTOR, SCALAR, out, psType1, op, psType2); // vector op scalar 490 537 } else if (dim2 == PS_DIMEN_VECTOR || dim2 == PS_DIMEN_TRANSV) { 538 out = psVectorRecycle(out,((psVector*)in2)->n,elType2); 539 if (out == NULL) { 540 psError(__func__, "Couldn't create a proper output psVector."); 541 return NULL; 542 } 491 543 BINARY_OP(VECTOR, VECTOR, out, psType1, op, psType2); // vector op vector 492 544 } else if (dim2 == PS_DIMEN_IMAGE) { 545 out = psImageRecycle(out, ((psImage* ) in2)->numCols, ((psImage* ) in2)->numRows, elType2); 546 if (out == NULL) { 547 psError(__func__, "Couldn't create a proper output psImage."); 548 return NULL; 549 } 493 550 BINARY_OP(VECTOR, IMAGE, out, psType1, op, psType2); // vector op image 494 551 } else { … … 496 553 } 497 554 } else if (dim1 == PS_DIMEN_IMAGE) { 555 out = psImageRecycle(out, ((psImage*)in1)->numCols, ((psImage*)in1)->numRows, elType1); 556 if (out == NULL) { 557 psError(__func__, "Couldn't create a proper output psImage."); 558 return NULL; 559 } 498 560 if (dim2 == PS_DIMEN_SCALAR) { 499 561 BINARY_OP(IMAGE, SCALAR, out, psType1, op, psType2); // image op scalar … … 503 565 BINARY_OP(IMAGE, IMAGE, out, psType1, op, psType2); // image op image 504 566 } else { 567 if (out != in1 && out != in2) { 568 psFree(out); 569 } 505 570 psError(__func__, ": Line %d - Invalid dimensionality for in2 arg: %d", __LINE__, dim2); 571 return NULL; 506 572 } 507 573 } else { 574 if (out != in1 && out != in2) { 575 psFree(out); 576 } 508 577 psError(__func__, ": Line %d - Invalid dimensionality for in1 arg: %d", __LINE__, dim1); 578 return NULL; 509 579 } 510 580 … … 544 614 if(nIn != nOut) { \ 545 615 psError(__func__, ": Inconsistent element count: %d vs %d", nIn, nOut); \ 546 return OUT; \ 616 if (OUT != IN) { \ 617 psFree(OUT); \ 618 } \ 619 return NULL; \ 547 620 } \ 548 621 o = ((psVector* )OUT)->data.TYPE; \ … … 571 644 psError(__func__, ": Inconsistent element count: numRows: %d vs %d numCols: %d vs %d", numRowsIn, \ 572 645 numRowsOut, numColsIn, numColsOut); \ 573 return OUT; \ 646 if (OUT != IN) { \ 647 psFree(OUT); \ 648 } \ 649 return NULL; \ 574 650 } \ 575 651 for(j = 0; j < numRowsIn; j++) { \ … … 597 673 DIM(OUT,IN,OP,C32); \ 598 674 break; \ 675 case PS_TYPE_S8: \ 676 DIM(OUT,IN,OP,C32); \ 677 break; \ 678 case PS_TYPE_U8: \ 679 DIM(OUT,IN,OP,C32); \ 680 break; \ 681 case PS_TYPE_S16: \ 682 DIM(OUT,IN,OP,C32); \ 683 break; \ 684 case PS_TYPE_U16: \ 685 DIM(OUT,IN,OP,C32); \ 686 break; \ 687 case PS_TYPE_U32: \ 688 DIM(OUT,IN,OP,C32); \ 689 break; \ 690 case PS_TYPE_S64: \ 691 DIM(OUT,IN,OP,C32); \ 692 break; \ 693 case PS_TYPE_U64: \ 694 DIM(OUT,IN,OP,C32); \ 695 break; \ 696 case PS_TYPE_C64: \ 697 DIM(OUT,IN,OP,C32); \ 698 break; \ 599 699 default: \ 600 case PS_TYPE_S8: \601 case PS_TYPE_U8: \602 case PS_TYPE_S16: \603 case PS_TYPE_U16: \604 case PS_TYPE_U32: \605 case PS_TYPE_S64: \606 case PS_TYPE_U64: \607 case PS_TYPE_C64: \608 700 psError(__func__, ": Invalid PS_TYPE: %d", IN->type); \ 701 if (OUT != IN) { \ 702 psFree(OUT); \ 703 } \ 704 return NULL; \ 609 705 } 610 706 … … 725 821 { 726 822 psDimen dimIn = 0; 727 psDimen dimOut = 0;728 823 psElemType elTypeIn = 0; 729 psElemType elTypeOut = 0;730 824 psType* psTypeIn = NULL; 731 psType* psTypeOut = NULL;732 733 psTypeOut = (psType* ) out;734 if (psTypeOut == NULL) {735 psError(__func__, ": Line %d - Null out argument", __LINE__);736 return out;737 }738 825 739 826 psTypeIn = (psType* ) in; 740 827 if (psTypeIn == NULL) { 741 828 psError(__func__, ": Line %d - Null in argument", __LINE__); 742 return out; 829 if (out != in) { 830 psFree(out); 831 } 832 return NULL; 743 833 } 744 834 745 835 if (op == NULL) { 746 836 psError(__func__, ": Line %d - Null op argument", __LINE__); 747 return out; 837 if (out != in) { 838 psFree(out); 839 } 840 return NULL; 748 841 } 749 842 750 843 dimIn = psTypeIn->dimen; 751 dimOut = psTypeOut->dimen;752 844 elTypeIn = psTypeIn->type; 753 elTypeOut = psTypeOut->type; 754 755 if (elTypeIn != elTypeOut) { 756 psError(__func__, ": Line %d - Element types for arguments inconsistent: (%d, %d)", __LINE__, 757 elTypeIn, elTypeOut); 758 return out; 759 } 760 761 if (dimIn != dimOut) { 762 psError(__func__, ": Line %d - Dimensionality for arguments inconsistent: (%d, %d)", __LINE__, 763 dimIn, dimOut); 764 return out; 765 } 766 767 if (dimIn == PS_DIMEN_OTHER || dimOut == PS_DIMEN_OTHER) { 768 psError(__func__, ": Line %d - PS_DIMEN_OTHER not allowed for arguments: (%d, %d)", __LINE__, 769 dimIn, dimOut); 770 return out; 771 } 772 773 if (dimIn == PS_DIMEN_VECTOR) { 774 if (((psVector* ) in)->n == 0) { 845 846 switch (dimIn) { 847 case PS_DIMEN_SCALAR: 848 if (out == NULL || 849 ((psType*)out)->dimen != PS_DIMEN_SCALAR || 850 ((psScalar*)out)->type.type != elTypeIn) { 851 psFree(out); 852 out = psScalarAlloc(0.0,elTypeIn); 853 } 854 UNARY_OP(SCALAR, out, psTypeIn, op); // scalar 855 break; 856 case PS_DIMEN_VECTOR: 857 case PS_DIMEN_TRANSV: 858 if (((psVector*)in)->n == 0) { 859 if (out != in) { 860 psFree(out); 861 } 775 862 psError(__func__, ": Line %d - Vector contains zero elements"); 776 } 777 } else if (dimIn == PS_DIMEN_IMAGE) { 863 return NULL; 864 } 865 866 out = psVectorRecycle(out, 867 ((psVector*)in)->n, 868 elTypeIn); 869 if (out == NULL) { 870 psError(__func__, "Couldn't create a proper output psVector."); 871 return NULL; 872 } 873 874 UNARY_OP(VECTOR, out, psTypeIn, op); // vector 875 break; 876 case PS_DIMEN_IMAGE: 778 877 if (((psImage* ) in)->numCols == 0 || ((psImage* ) in)->numRows == 0) { 878 if (out != in) { 879 psFree(out); 880 } 779 881 psError(__func__, ": Line %d - Image contains zero length row or cols"); 780 } 781 } 782 783 if (dimOut == PS_DIMEN_VECTOR) { 784 if (((psVector* ) out)->n == 0) { 785 psError(__func__, ": Line %d - Vector contains zero elements"); 786 } 787 } else if (dimOut == PS_DIMEN_IMAGE) { 788 if (((psImage* ) out)->numCols == 0 || ((psImage* ) out)->numRows == 0) { 789 psError(__func__, ": Line %d - Image contains zero length row or cols"); 790 } 791 } 792 793 if (dimIn == PS_DIMEN_SCALAR) { 794 UNARY_OP(SCALAR, out, psTypeIn, op); // scalar 795 } else if (dimIn == PS_DIMEN_VECTOR || dimIn == PS_DIMEN_TRANSV) { 796 UNARY_OP(VECTOR, out, psTypeIn, op); // vector 797 } else if (dimIn == PS_DIMEN_IMAGE) { 882 return NULL; 883 } 884 885 out = psImageRecycle(out, 886 ((psImage*)in)->numCols, 887 ((psImage*)in)->numRows, 888 elTypeIn); 889 if (out == NULL) { 890 psError(__func__, "Couldn't create a proper output psImage."); 891 return NULL; 892 } 893 798 894 UNARY_OP(IMAGE, out, psTypeIn, op); // image 799 } else { 895 break; 896 default: 897 if (out != in) { 898 psFree(out); 899 } 800 900 psError(__func__, ": Line %d - Invalid dimensionality for in arg: %d", __LINE__, dimIn); 901 return NULL; 801 902 } 802 903 -
trunk/psLib/src/math/psMatrix.c
r1845 r2021 1 2 1 /** @file psMatrix.c 3 2 * … … 21 20 * @author Ross Harman, MHPCC 22 21 * 23 * @version $Revision: 1.1 4$ $Name: not supported by cvs2svn $24 * @date $Date: 2004- 09-21 23:44:10$22 * @version $Revision: 1.15 $ $Name: not supported by cvs2svn $ 23 * @date $Date: 2004-10-08 02:48:01 $ 25 24 * 26 25 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 28 27 29 28 /******************************************************************************/ 30 31 29 /* INCLUDE FILES */ 32 33 30 /******************************************************************************/ 34 31 #include <string.h> … … 44 41 #include "psMatrix.h" 45 42 46 /******************************************************************************/47 48 /* DEFINE STATEMENTS */49 50 /******************************************************************************/51 52 // None53 54 /******************************************************************************/55 56 /* TYPE DEFINITIONS */57 58 /******************************************************************************/59 60 // None61 62 /*****************************************************************************/63 64 /* GLOBAL VARIABLES */65 66 /*****************************************************************************/67 68 // None69 70 /*****************************************************************************/71 72 /* FILE STATIC VARIABLES */73 74 /*****************************************************************************/75 76 // None77 78 /*****************************************************************************/79 80 /* FUNCTION IMPLEMENTATION - LOCAL */81 82 /*****************************************************************************/83 84 43 /** Preprocessor macro to generate error a NULL image */ 85 44 #define PS_CHECK_NULL_VECTOR(NAME, RETURN) \ … … 155 114 156 115 /*****************************************************************************/ 157 158 116 /* FUNCTION IMPLEMENTATION - PUBLIC */ 159 160 117 /*****************************************************************************/ 161 118 -
trunk/psLib/test/dataManip/tst_psMatrixVectorArithmetic03.c
r1648 r2021 15 15 * @author Ross Harman, MHPCC 16 16 * 17 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $18 * @date $Date: 2004- 08-27 23:31:35$17 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 18 * @date $Date: 2004-10-08 02:48:01 $ 19 19 * 20 20 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 86 86 printNegativeTestHeader(stdout,"psMatrixVectorArithmetic", "Check for NULL arguments", 87 87 "Null XXX argument", 0); 88 psBinaryOp(NULL, image1, "+", image2); 89 psBinaryOp(image2, NULL, "+", image2); 90 psBinaryOp(image2, image1, "+", NULL); 91 psBinaryOp(image2, image1, NULL, image2); 92 psUnaryOp(NULL, image1, "sin"); 93 psUnaryOp(image2, NULL, "sin"); 94 psUnaryOp(image2, image1, NULL); 95 printFooter(stdout, "psBitSet", "Check for NULL arguments", true); 96 88 psImage* image6 = (psImage*)psBinaryOp(NULL, image1, "+", image2); 89 if (image6 == NULL) { 90 psLogMsg(__func__,PS_LOG_ERROR,"psBinaryOp failed to make an image given no output to recycle."); 91 return 1; 92 } 93 94 image6 = (psImage*)psBinaryOp(image6, NULL, "+", image2); 95 if (image6 != NULL) { 96 psLogMsg(__func__,PS_LOG_ERROR,"psBinaryOp returned a result given a NULL first operand."); 97 return 2; 98 } 99 100 image6 = (psImage*)psBinaryOp(image6, image1, "+", NULL); 101 if (image6 != NULL) { 102 psLogMsg(__func__,PS_LOG_ERROR,"psBinaryOp returned a result given a NULL second operand."); 103 return 3; 104 } 105 image6 = (psImage*)psBinaryOp(image6, image1, NULL, image2); 106 if (image6 != NULL) { 107 psLogMsg(__func__,PS_LOG_ERROR,"psBinaryOp returned a result given a NULL operator."); 108 return 4; 109 } 110 111 image6 = (psImage*)psUnaryOp(NULL, image1, "sin"); 112 if (image6 == NULL) { 113 psLogMsg(__func__,PS_LOG_ERROR,"psUnaryOp failed to make an image given no output to recycle."); 114 return 5; 115 } 116 117 image6 = (psImage*)psUnaryOp(image6, NULL, "sin"); 118 if (image6 != NULL) { 119 psLogMsg(__func__,PS_LOG_ERROR,"psUnaryOp returned a result given a NULL operand."); 120 return 6; 121 } 122 123 image6 = (psImage*)psUnaryOp(image6, image1, NULL); 124 if (image6 != NULL) { 125 psLogMsg(__func__,PS_LOG_ERROR,"psUnaryOp returned a result given a NULL operator."); 126 return 7; 127 } 128 129 printFooter(stdout, "psMatrixVectorArithmetic", "Check for NULL arguments", true); 97 130 98 131 // Inconsistent element types 99 132 printNegativeTestHeader(stdout,"psMatrixVectorArithmetic", "Inconsistent element types", 100 133 "Element types for arguments inconsistent", 0); 101 psBinaryOp(image2, image3, "+", image2); 102 psUnaryOp(image2, image3, "sin"); 103 printFooter(stdout, "psBitSet", "Inconsistent element types", true); 134 image6 = (psImage*)psBinaryOp(image6, image3, "+", image2); 135 if (image6 != NULL) { 136 psLogMsg(__func__,PS_LOG_ERROR,"psBinaryOp returned a result given operands of different types."); 137 return 8; 138 } 139 140 image6 = psImageCopy(image6,image2,PS_TYPE_F64); 141 image6 = (psImage*)psUnaryOp(image6, image3, "sin"); 142 if (image6 == NULL || image6->type.type != PS_TYPE_F32) { 143 psLogMsg(__func__,PS_LOG_ERROR,"psUnaryOp failed to convert the type of the output."); 144 return 9; 145 } 146 147 printFooter(stdout, "psMatrixVectorArithmetic", "Inconsistent element types", true); 104 148 105 149 … … 107 151 printNegativeTestHeader(stdout,"psMatrixVectorArithmetic", "Inconsistent element count", 108 152 "Inconsistent element count", 0); 109 psBinaryOp(image2, image4, "+", image2); 110 psUnaryOp(image2, image4, "sin"); 111 psBinaryOp(image2, vector1, "+", image2); 153 image6 = (psImage*)psBinaryOp(image6, image4, "+", image2); 154 if (image6 != NULL) { 155 psLogMsg(__func__,PS_LOG_ERROR,"psBinaryOp returned a result given operands of different sizes."); 156 return 10; 157 } 158 159 image6 = psImageCopy(image6,image2,PS_TYPE_F64); 160 image6 = (psImage*)psUnaryOp(image6, image4, "sin"); 161 if (image6 == NULL || 162 image6->numCols != image6->numCols || 163 image6->numRows != image6->numRows) { 164 psLogMsg(__func__,PS_LOG_ERROR,"psUnaryOp failed to resize the output."); 165 return 11; 166 } 167 168 image6 = (psImage*)psBinaryOp(image6, vector1, "+", image2); 169 if (image6 != NULL) { 170 psLogMsg(__func__,PS_LOG_ERROR,"psBinaryOp returned a result given operands of different sizes."); 171 return 12; 172 } 173 112 174 vector1->type.dimen = PS_DIMEN_TRANSV; 113 psBinaryOp(image2, vector1, "+", image2); 114 printFooter(stdout, "psBitSet", "Inconsistent element count", true); 175 image6 = (psImage*)psBinaryOp(image6, vector1, "+", image2); 176 if (image6 != NULL) { 177 psLogMsg(__func__,PS_LOG_ERROR,"psBinaryOp returned a result given operands of different sizes."); 178 return 13; 179 } 180 printFooter(stdout, "psMatrixVectorArithmetic", "Inconsistent element count", true); 115 181 116 182 … … 118 184 printNegativeTestHeader(stdout,"psMatrixVectorArithmetic", "Inconsistent dimensionality", 119 185 "Dimensionality for arguments inconsistent", 0); 120 psUnaryOp(image2, vector2, "sin"); 121 printFooter(stdout, "psBitSet", "Inconsistent dimensionality", true); 122 123 124 // Division by zero 125 printNegativeTestHeader(stdout,"psMatrixVectorArithmetic", "Divide by zero", 126 "Divide by zero", 0); 127 psBinaryOp(image1, image1, "/", image2); 128 printFooter(stdout, "psBitSet", "Division by zero", true); 129 186 image6 = psImageCopy(image6,image2,PS_TYPE_F64); 187 image6 = (psImage*)psUnaryOp(image6, vector2, "sin"); 188 if (image6 != NULL) { 189 psLogMsg(__func__,PS_LOG_ERROR,"psUnaryOp returned result given wrong type out parameter."); 190 return 14; 191 } 192 193 printFooter(stdout, "psMatrixVectorArithmetic", "Inconsistent dimensionality", true); 130 194 131 195 // Attempt to use min with complex numbers 132 196 printNegativeTestHeader(stdout,"psMatrixVectorArithmetic", "Use min with complex numbers", 133 197 "Minimum operation not supported for complex numbers", 0); 134 psBinaryOp(image5, image5, "min", image5);135 printFooter(stdout, "ps BitSet", "Use min with complex numbers", true);198 image6 = (psImage*)psBinaryOp(image6, image5, "min", image5); 199 printFooter(stdout, "psMatrixVectorArithmetic", "Use min with complex numbers", true); 136 200 137 201 … … 139 203 printNegativeTestHeader(stdout,"psMatrixVectorArithmetic", "Use max with complex numbers", 140 204 "Maximum operation not supported for complex numbers", 0); 141 psBinaryOp(image5, image5, "max", image5);142 printFooter(stdout, "ps BitSet", "Use max with complex numbers", true);205 image6 = (psImage*)psBinaryOp(image6, image5, "max", image5); 206 printFooter(stdout, "psMatrixVectorArithmetic", "Use max with complex numbers", true); 143 207 144 208 … … 146 210 printNegativeTestHeader(stdout,"psMatrixVectorArithmetic", "Invalid operation", 147 211 "Invalid operation", 0); 148 psBinaryOp(image1, image1, "yarg", image2);149 psUnaryOp(image2, image1, "yarg");150 printFooter(stdout, "ps BitSet", "Invalid operation", true);212 image6 = (psImage*)psBinaryOp(image6, image1, "yarg", image2); 213 image6 = (psImage*)psUnaryOp(image6, image1, "yarg"); 214 printFooter(stdout, "psMatrixVectorArithmetic", "Invalid operation", true); 151 215 152 216 return 0; -
trunk/psLib/test/dataManip/verified/tst_psMatrixVectorArithmetic03.stderr
r1761 r2021 1 <DATE><TIME>|<HOST>|E|psBinaryOp2 : Line <LINENO> - Null out argument3 1 <DATE><TIME>|<HOST>|E|psBinaryOp 4 2 : Line <LINENO> - Null in1 argument … … 8 6 : Line <LINENO> - Null op argument 9 7 <DATE><TIME>|<HOST>|E|psUnaryOp 10 : Line <LINENO> - Null out argument11 <DATE><TIME>|<HOST>|E|psUnaryOp12 8 : Line <LINENO> - Null in argument 13 9 <DATE><TIME>|<HOST>|E|psUnaryOp 14 10 : Line <LINENO> - Null op argument 15 11 <DATE><TIME>|<HOST>|E|psBinaryOp 16 : Line <LINENO> - Element types for arguments inconsistent: (1028, 1032, 1032)17 <DATE><TIME>|<HOST>|E|psUnaryOp18 12 : Line <LINENO> - Element types for arguments inconsistent: (1028, 1032) 19 13 <DATE><TIME>|<HOST>|E|psBinaryOp 20 : Inconsistent element count: numRows: 2 vs 3 numCols: 2 vs 321 <DATE><TIME>|<HOST>|E|psUnaryOp22 14 : Inconsistent element count: numRows: 2 vs 3 numCols: 2 vs 3 23 15 <DATE><TIME>|<HOST>|E|psBinaryOp … … 25 17 <DATE><TIME>|<HOST>|E|psBinaryOp 26 18 : Inconsistent element count: 2 vs 3 19 <DATE><TIME>|<HOST>|E|psLib.collections.psVectorRecycle 20 The input psVector must have a vector dimension type. 27 21 <DATE><TIME>|<HOST>|E|psUnaryOp 28 : Line <LINENO> - Dimensionality for arguments inconsistent: (1, 3) 29 <DATE><TIME>|<HOST>|E|psNanDiv 30 : Divide by zero 31 <DATE><TIME>|<HOST>|E|psNanDiv 32 : Divide by zero 33 <DATE><TIME>|<HOST>|E|psNanDiv 34 : Divide by zero 35 <DATE><TIME>|<HOST>|E|psNanDiv 36 : Divide by zero 37 <DATE><TIME>|<HOST>|E|psNanDiv 38 : Divide by zero 39 <DATE><TIME>|<HOST>|E|psNanDiv 40 : Divide by zero 41 <DATE><TIME>|<HOST>|E|psNanDiv 42 : Divide by zero 43 <DATE><TIME>|<HOST>|E|psNanDiv 44 : Divide by zero 45 <DATE><TIME>|<HOST>|E|psNanDiv 46 : Divide by zero 22 Couldn't create a proper output psVector. 47 23 <DATE><TIME>|<HOST>|E|psBinaryOp 48 24 : Minimum operation not supported for complex numbers -
trunk/psLib/test/dataManip/verified/tst_psMatrixVectorArithmetic03.stdout
r1150 r2021 8 8 9 9 10 ---> TESTPOINT PASSED (ps BitSet{Check for NULL arguments} | tst_psMatrixVectorArithmetic03.c)10 ---> TESTPOINT PASSED (psMatrixVectorArithmetic{Check for NULL arguments} | tst_psMatrixVectorArithmetic03.c) 11 11 12 12 /***************************** TESTPOINT ******************************************\ … … 19 19 20 20 21 ---> TESTPOINT PASSED (ps BitSet{Inconsistent element types} | tst_psMatrixVectorArithmetic03.c)21 ---> TESTPOINT PASSED (psMatrixVectorArithmetic{Inconsistent element types} | tst_psMatrixVectorArithmetic03.c) 22 22 23 23 /***************************** TESTPOINT ******************************************\ … … 30 30 31 31 32 ---> TESTPOINT PASSED (ps BitSet{Inconsistent element count} | tst_psMatrixVectorArithmetic03.c)32 ---> TESTPOINT PASSED (psMatrixVectorArithmetic{Inconsistent element count} | tst_psMatrixVectorArithmetic03.c) 33 33 34 34 /***************************** TESTPOINT ******************************************\ … … 41 41 42 42 43 ---> TESTPOINT PASSED (psBitSet{Inconsistent dimensionality} | tst_psMatrixVectorArithmetic03.c) 44 45 /***************************** TESTPOINT ******************************************\ 46 * TestFile: tst_psMatrixVectorArithmetic03.c * 47 * TestPoint: psMatrixVectorArithmetic{Divide by zero} * 48 * TestType: Negative * 49 * ExpectedErrorText: Divide by zero * 50 * ExpectedStatusValue: 0 * 51 \**********************************************************************************/ 52 53 54 ---> TESTPOINT PASSED (psBitSet{Division by zero} | tst_psMatrixVectorArithmetic03.c) 43 ---> TESTPOINT PASSED (psMatrixVectorArithmetic{Inconsistent dimensionality} | tst_psMatrixVectorArithmetic03.c) 55 44 56 45 /***************************** TESTPOINT ******************************************\ … … 63 52 64 53 65 ---> TESTPOINT PASSED (ps BitSet{Use min with complex numbers} | tst_psMatrixVectorArithmetic03.c)54 ---> TESTPOINT PASSED (psMatrixVectorArithmetic{Use min with complex numbers} | tst_psMatrixVectorArithmetic03.c) 66 55 67 56 /***************************** TESTPOINT ******************************************\ … … 74 63 75 64 76 ---> TESTPOINT PASSED (ps BitSet{Use max with complex numbers} | tst_psMatrixVectorArithmetic03.c)65 ---> TESTPOINT PASSED (psMatrixVectorArithmetic{Use max with complex numbers} | tst_psMatrixVectorArithmetic03.c) 77 66 78 67 /***************************** TESTPOINT ******************************************\ … … 85 74 86 75 87 ---> TESTPOINT PASSED (ps BitSet{Invalid operation} | tst_psMatrixVectorArithmetic03.c)76 ---> TESTPOINT PASSED (psMatrixVectorArithmetic{Invalid operation} | tst_psMatrixVectorArithmetic03.c) 88 77
Note:
See TracChangeset
for help on using the changeset viewer.
