IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 3, 2004, 3:05:00 PM (22 years ago)
Author:
desonia
Message:

changed the psError signature to match SDRS. Also made misc. cleanups as
I was combing the files.

File:
1 edited

Legend:

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

    r2214 r2273  
    2020 *  @author Ross Harman, MHPCC
    2121 *   
    22  *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
    23  *  @date $Date: 2004-10-27 20:20:11 $
     22 *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
     23 *  @date $Date: 2004-11-04 01:04:59 $
    2424 *
    2525 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4040#include "psVector.h"
    4141#include "psMatrix.h"
    42 
    43 /** Preprocessor macro to generate error a NULL image */
    44 #define PS_VECTOR_CHECK_NULL(NAME, RETURN)                                                          \
    45 if (NAME == NULL || NAME->data.V == NULL) {                                                         \
    46     psError(__func__,"Invalid operation: %s or its data is NULL.", #NAME);                          \
    47     return RETURN;                                                                                  \
    48 }
    49 
    50 /** Preprocessor macro to create vector based on another */
    51 #define PS_CHECK_ALLOC_VECTOR(NAME, SIZE, PS_TYPE)                                                  \
    52 if(NAME == NULL) {                                                                                  \
    53     NAME = psVectorAlloc(SIZE, PS_TYPE);                                                            \
    54 }
    55 
    56 /** Preprocessor macro to generate error for zero length vector */
    57 #define PS_CHECK_SIZE_VECTOR(NAME, RETURN)                                                          \
    58 if (NAME->n < 1) {                                                                                  \
    59     psError(__func__,"Invalid operation: %s has zero n value.", #NAME);                             \
    60     return RETURN;                                                                                  \
    61 }
    62 
    63 /** Preprocessor macro to generate error a NULL image */
    64 #define PS_IMAGE_CHECK_NULL(NAME, RETURN)                                                           \
    65 if (NAME == NULL || NAME->data.V == NULL) {                                                         \
    66     psError(__func__,"Invalid operation: %s or its data is NULL.", #NAME);                          \
    67     return RETURN;                                                                                  \
    68 }
    69 
    70 /** Preprocessor macro to create image based on another */
    71 #define PS_CHECK_ALLOC_IMAGE(NAME, NCOLS, NROWS, PS_TYPE)                                           \
    72 if(NAME == NULL) {                                                                                  \
    73     NAME = psImageAlloc(NCOLS, NROWS, PS_TYPE);                                                     \
    74 }
    75 
    76 /** Preprocessor macro to generate error for zero length rows or columns */
    77 #define PS_CHECK_SIZE_IMAGE(NAME, RETURN)                                                           \
    78 if (NAME->numCols < 1 || NAME->numRows < 1) {                                                       \
    79     psError(__func__,"Invalid operation: %s has zero rows or columns (%dx%d).", #NAME,              \
    80             NAME->numCols, NAME->numRows);                                                          \
    81     return RETURN;                                                                                  \
    82 }
     42#include "psConstants.h"
     43
     44
    8345
    8446/** Preprocessor macro to generate error for image dimensionality not set to PS_DIMEN_IMAGE */
    8547#define PS_CHECK_DIMEN_AND_TYPE(NAME, PS_DIMEN, RETURN)                                             \
    8648if (NAME->type.dimen != PS_DIMEN) {                                                                 \
    87     psError(__func__,"Invalid operation: %s incorrect dimensionality %d.", #NAME, PS_DIMEN);        \
     49    psError(PS_ERR_BAD_PARAMETER_TYPE, true,                                                        \
     50            "Invalid operation. %s has incorrect dimensionality %d.", #NAME, PS_DIMEN);             \
    8851    return RETURN;                                                                                  \
    8952} else if(NAME->type.type != PS_TYPE_F64) {                                                         \
    90     psError(__func__, "Invalid operation: %s not PS_TYPE_F64.", #NAME);                             \
     53    psError(PS_ERR_BAD_PARAMETER_TYPE, true,                                                        \
     54            "Invalid operation. %s not PS_TYPE_F64.", #NAME);                                       \
    9155    return RETURN;                                                                                  \
    9256}
     
    9559#define PS_CHECK_POINTERS(NAME1, NAME2, RETURN)                                                     \
    9660if (NAME1 == NAME2) {                                                                               \
    97     psError(__func__,"Invalid operation: Pointer to %s is same as %s.", #NAME1, #NAME2);            \
     61    psError(PS_ERR_BAD_PARAMETER_VALUE, true,                                                       \
     62            "Invalid operation: Pointer to %s is same as %s.", #NAME1, #NAME2);                     \
    9863    return RETURN;                                                                                  \
    9964}
     
    10267#define PS_CHECK_SQUARE(NAME, RETURN)                                                               \
    10368if (NAME->numCols != NAME->numRows) {                                                               \
    104     psError(__func__,"Invalid operation: %s not square array.", #NAME);                             \
     69    psError(PS_ERR_BAD_PARAMETER_SIZE, true,                                                       \
     70            "Invalid operation: %s not square array.", #NAME);                             \
    10571    return RETURN;                                                                                  \
    10672}
     
    12692    gsl_permutation perm;
    12793
     94    #define psMatrixLUD_EXIT { \
     95                               psFree(outImage); \
     96                               return NULL; \
     97                             }
     98
    12899    // Error checks
    129100    PS_CHECK_POINTERS(inImage, outImage, outImage);
    130     PS_IMAGE_CHECK_NULL(inImage, outImage);
    131101    PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outImage);
    132     PS_CHECK_SIZE_IMAGE(inImage, outImage);
    133     PS_CHECK_ALLOC_IMAGE(outImage, inImage->numCols, inImage->numRows, inImage->type.type);
    134     PS_CHECK_DIMEN_AND_TYPE(outImage, PS_DIMEN_IMAGE, outImage);
    135     PS_CHECK_SIZE_IMAGE(outImage, outImage);
    136     PS_CHECK_ALLOC_VECTOR(outPerm, inImage->numRows, inImage->type.type);
    137     PS_VECTOR_CHECK_NULL(outPerm, outImage);
     102
     103    PS_IMAGE_CHECK_NULL_GENERAL(inImage, psMatrixLUD_EXIT);
     104    PS_VECTOR_CHECK_NULL_GENERAL(outPerm, psMatrixLUD_EXIT);
     105
    138106    PS_CHECK_DIMEN_AND_TYPE(outPerm, PS_DIMEN_VECTOR, outImage);
     107
     108    psImageRecycle(outImage, inImage->numCols, inImage->numRows, inImage->type.type);
     109    psVectorRecycle(outPerm, inImage->numRows, inImage->type.type);
    139110
    140111    // Initialize data
     
    179150    PS_IMAGE_CHECK_NULL(inImage, outVector);
    180151    PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outVector);
    181     PS_CHECK_SIZE_IMAGE(inImage, outVector);
    182     PS_CHECK_ALLOC_VECTOR(outVector, inImage->numRows, inImage->type.type);
     152    PS_IMAGE_CHECK_EMPTY(inImage, outVector);
    183153    PS_VECTOR_CHECK_NULL(outVector, outVector);
    184154    PS_CHECK_DIMEN_AND_TYPE(outVector, PS_DIMEN_VECTOR, outVector);
     
    188158    PS_CHECK_DIMEN_AND_TYPE(inPerm, PS_DIMEN_VECTOR, outVector);
    189159
     160    psVectorRecycle(outVector, inImage->numRows, inImage->type.type);
     161
     162
    190163    // Initialize data
    191164    numRows = inImage->numRows;
     
    226199
    227200    // Error checks
    228     if (det == NULL) {
    229         psError(__func__, "Invalid operation: determinant argument is NULL.");
    230         return outImage;
    231     }
     201    PS_PTR_CHECK_NULL(det, outImage);
    232202    PS_CHECK_POINTERS(inImage, outImage, outImage);
    233203    PS_IMAGE_CHECK_NULL(inImage, outImage);
    234204    PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outImage);
    235     PS_CHECK_SIZE_IMAGE(inImage, outImage);
    236     PS_CHECK_ALLOC_IMAGE(outImage, inImage->numCols, inImage->numRows, inImage->type.type);
    237     PS_CHECK_DIMEN_AND_TYPE(outImage, PS_DIMEN_IMAGE, outImage);
    238     PS_CHECK_SIZE_IMAGE(outImage, outImage);
     205    PS_IMAGE_CHECK_EMPTY(inImage, outImage);
     206
     207    psImageRecycle(outImage, inImage->numCols, inImage->numRows, inImage->type.type);
    239208
    240209    // Initialize data
     
    282251    PS_IMAGE_CHECK_NULL(inImage, NULL);
    283252    PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, NULL);
    284     PS_CHECK_SIZE_IMAGE(inImage, NULL);
     253    PS_IMAGE_CHECK_EMPTY(inImage, NULL);
    285254
    286255    // Initialize data
     
    325294    PS_IMAGE_CHECK_NULL(inImage1, outImage);
    326295    PS_CHECK_DIMEN_AND_TYPE(inImage1, PS_DIMEN_IMAGE, outImage);
    327     PS_CHECK_SIZE_IMAGE(inImage1, outImage);
     296    PS_IMAGE_CHECK_EMPTY(inImage1, outImage);
    328297    PS_IMAGE_CHECK_NULL(inImage2, outImage);
    329298    PS_CHECK_DIMEN_AND_TYPE(inImage2, PS_DIMEN_IMAGE, outImage);
    330     PS_CHECK_SIZE_IMAGE(inImage2, outImage);
    331     PS_CHECK_ALLOC_IMAGE(outImage, inImage2->numCols, inImage2->numRows, inImage2->type.type);
     299    PS_IMAGE_CHECK_EMPTY(inImage2, outImage);
    332300    PS_CHECK_DIMEN_AND_TYPE(inImage1, PS_DIMEN_IMAGE, outImage);
    333     PS_CHECK_SIZE_IMAGE(outImage, outImage);
     301
     302    psImageRecycle(outImage, inImage2->numCols, inImage2->numRows, inImage2->type.type);
    334303
    335304    // Initialize data
     
    364333    PS_IMAGE_CHECK_NULL(inImage, outImage);
    365334    PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outImage);
    366     PS_CHECK_SIZE_IMAGE(inImage, outImage);
    367     PS_CHECK_ALLOC_IMAGE(outImage, inImage->numCols, inImage->numRows, inImage->type.type);
    368     PS_CHECK_DIMEN_AND_TYPE(outImage, PS_DIMEN_IMAGE, outImage);
    369     PS_CHECK_SIZE_IMAGE(outImage, outImage);
     335    PS_IMAGE_CHECK_EMPTY(inImage, outImage);
     336
     337    psImageRecycle(outImage, inImage->numCols, inImage->numRows, inImage->type.type);
    370338
    371339    // Initialize data
     
    403371    PS_IMAGE_CHECK_NULL(inImage, outImage);
    404372    PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outImage);
    405     PS_CHECK_SIZE_IMAGE(inImage, outImage);
    406     PS_CHECK_ALLOC_IMAGE(outImage, inImage->numCols, inImage->numRows, inImage->type.type);
    407     PS_CHECK_DIMEN_AND_TYPE(outImage, PS_DIMEN_IMAGE, outImage);
    408     PS_CHECK_SIZE_IMAGE(outImage, outImage);
     373    PS_IMAGE_CHECK_EMPTY(inImage, outImage);
     374
     375    psImageRecycle(outImage, inImage->numCols, inImage->numRows, inImage->type.type);
    409376
    410377    // Initialize data
     
    438405    psS32 size = 0;
    439406
    440     // Error checks
    441     PS_IMAGE_CHECK_NULL(inImage, outVector);
     407    #define psMatrixToVector_EXIT { \
     408                                    psFree(outVector); \
     409                                    return NULL; \
     410                                  }
     411
     412    // Error checks
     413    PS_IMAGE_CHECK_NULL_GENERAL(inImage, psMatrixToVector_EXIT);
    442414    PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outVector);
    443     PS_CHECK_SIZE_IMAGE(inImage, outVector);
     415    PS_IMAGE_CHECK_EMPTY_GENERAL(inImage, psMatrixToVector_EXIT);
    444416
    445417    if (inImage->numRows == 1) {
    446418        // Create transposed row vector
    447         PS_CHECK_ALLOC_VECTOR(outVector, inImage->numCols, inImage->type.type);
     419        psVectorRecycle(outVector, inImage->numCols, inImage->type.type);
    448420        outVector->type.dimen = PS_DIMEN_TRANSV;
    449421    } else if (inImage->numCols == 1) {
    450422        // Create non-transposed column vector
    451         PS_CHECK_ALLOC_VECTOR(outVector, inImage->numRows, inImage->type.type);
     423        psVectorRecycle(outVector, inImage->numRows, inImage->type.type);
    452424    } else {
    453         psError(__func__, "Image does not have dim with 1 col or 1 row: (%d x %d).", inImage->numRows,
    454                 inImage->numCols);
     425        psError(PS_ERR_BAD_PARAMETER_SIZE, true,
     426                "Image does not have dim with 1 col or 1 row: (%d x %d).",
     427                inImage->numRows, inImage->numCols);
    455428        return outVector;
    456429    }
     
    467440
    468441        if (outVector->n != inImage->numRows) {
    469             psError(__func__, "Image and vector sizes differ: (%d vs %d).", inImage->numRows, outVector->n);
     442            psError(PS_ERR_BAD_PARAMETER_SIZE, true,
     443                    "Image and vector sizes differ: (%d vs %d).",
     444                    inImage->numRows, outVector->n);
    470445            return outVector;
    471446        }
     
    481456
    482457        if (outVector->n != inImage->numCols) {
    483             psError(__func__, "Image and vector sizes differ: (%d vs %d).", inImage->numCols, outVector->n);
     458            psError(PS_ERR_BAD_PARAMETER_SIZE, true,
     459                    "Image and vector sizes differ: (%d vs %d).",
     460                    inImage->numCols, outVector->n);
    484461            return outVector;
    485462        }
     
    502479    if (inVector->type.dimen == PS_DIMEN_VECTOR) {
    503480        PS_CHECK_DIMEN_AND_TYPE(inVector, PS_DIMEN_VECTOR, outImage);
    504         PS_CHECK_SIZE_VECTOR(inVector, outImage);
    505         PS_CHECK_ALLOC_IMAGE(outImage, 1, inVector->n, PS_TYPE_F64)
     481        PS_VECTOR_CHECK_EMPTY(inVector, outImage);
     482        psImageRecycle(outImage, 1, inVector->n, PS_TYPE_F64);
    506483        // More checks for PS_DIMEN_VECTOR
    507484        if (outImage->numCols > 1) {
    508             psError(__func__, "Image has more than 1 column: numCols = %d.", outImage->numCols);
     485            psError(PS_ERR_BAD_PARAMETER_SIZE, true,
     486                    "Image has more than 1 column: numCols = %d.",
     487                    outImage->numCols);
    509488            return outImage;
    510489        } else if (outImage->numRows != inVector->n) {
    511             psError(__func__, "Image and vector sizes differ: (%d vs %d).", outImage->numRows, inVector->n);
     490            psError(PS_ERR_BAD_PARAMETER_SIZE, true,
     491                    "Image and vector sizes differ: (%d vs %d).",
     492                    outImage->numRows, inVector->n);
    512493            return outImage;
    513494        }
     
    517498    } else if (inVector->type.dimen == PS_DIMEN_TRANSV) {
    518499        PS_CHECK_DIMEN_AND_TYPE(inVector, PS_DIMEN_TRANSV, outImage);
    519         PS_CHECK_SIZE_VECTOR(inVector, outImage);
    520         PS_CHECK_ALLOC_IMAGE(outImage, inVector->n, 1, PS_TYPE_F64)
     500        PS_VECTOR_CHECK_EMPTY(inVector, outImage);
     501        psImageRecycle(outImage, inVector->n, 1, PS_TYPE_F64);
    521502        // More checks for PS_DIMEN_TRANSV
    522503        if (outImage->numRows > 1) {
    523             psError(__func__, "Image has more than 1 row: numRows = %d.", outImage->numRows);
     504            psError(PS_ERR_BAD_PARAMETER_SIZE, true,
     505                    "Image has more than 1 row: numRows = %d.",
     506                    outImage->numRows);
    524507            return outImage;
    525508        } else if (outImage->numCols != inVector->n) {
    526             psError(__func__, "Image and vector sizes differ: (%d vs %d).", outImage->numCols, inVector->n);
     509            psError(PS_ERR_BAD_PARAMETER_SIZE, true,
     510                    "Image and vector sizes differ: (%d vs %d).",
     511                    outImage->numCols, inVector->n);
    527512            return outImage;
    528513        }
Note: See TracChangeset for help on using the changeset viewer.