IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 908


Ignore:
Timestamp:
Jun 7, 2004, 3:58:03 PM (22 years ago)
Author:
harman
Message:

Added more unit tests

Location:
trunk/psLib
Files:
1 added
6 edited

Legend:

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

    r878 r908  
    2020 *  @author Ross Harman, MHPCC
    2121 *   
    22  *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    23  *  @date $Date: 2004-06-04 23:49:59 $
     22 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     23 *  @date $Date: 2004-06-08 01:57:52 $
    2424 *
    2525 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3535#include <gsl/gsl_eigen.h>
    3636
     37#include "psMemory.h"
    3738#include "psError.h"
    3839#include "psImage.h"
     
    253254
    254255    // Error checks
     256    if(det == NULL) {
     257        psError(__func__, "Invalid operation: determinant argument is NULL.");
     258        return outImage;
     259    }
    255260    PS_CHECK_POINTERS(inImage, outImage, outImage);
    256261    PS_CHECK_NULL_IMAGE(inImage, outImage);
     
    292297}
    293298
    294 float psMatrixDeterminant(const psImage *restrict inImage)
     299float* psMatrixDeterminant(const psImage *restrict inImage)
    295300{
    296301    int signum = 0;
     
    298303    int numRows = 0;
    299304    int numCols = 0;
    300     float det = 0.0f;
     305    float *det = NULL;
    301306    gsl_matrix *lu = NULL;
    302307    gsl_permutation *perm = NULL;
    303308
    304309    // Error checks
    305     PS_CHECK_NULL_IMAGE(inImage, 0);
    306     PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, 0);
    307     PS_CHECK_SIZE_IMAGE(inImage, 0);
     310    PS_CHECK_NULL_IMAGE(inImage, NULL);
     311    PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, NULL);
     312    PS_CHECK_SIZE_IMAGE(inImage, NULL);
    308313
    309314    // Initialize data
     
    323328
    324329    // Calculate determinant
     330    det = (float*)psAlloc(sizeof(float));
    325331    gsl_linalg_LU_decomp(lu, perm, &signum);
    326     det = (float)gsl_linalg_LU_det(lu, signum);
     332    *det = (float)gsl_linalg_LU_det(lu, signum);
    327333
    328334    // Free GSL structs
     
    458464psVector *psMatrixToVector(psVector *outVector, psImage *inImage)
    459465{
    460     int colSize = 0;
     466    int size = 0;
    461467
    462468    // Error checks
     
    464470    PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outVector);
    465471    PS_CHECK_SIZE_IMAGE(inImage, outVector);
    466     PS_CHECK_ALLOC_VECTOR(outVector, inImage->numRows, inImage->type.type);
    467     PS_CHECK_NULL_VECTOR(outVector, outVector);
    468     PS_CHECK_DIMEN_AND_TYPE(outVector, PS_DIMEN_VECTOR, outVector);
    469 
    470     // Set n if allocated, but empty
    471     if(outVector->n == 0) {
    472         outVector->n = inImage->numRows;
    473     }
    474 
    475     // More checks
    476     if(inImage->numCols > 1) {
    477         psError(__func__, "Image has more than 1 column: numCols = %d.", inImage->numCols);
    478         return outVector;
    479     } else if(outVector->n != inImage->numRows) {
    480         psError(__func__, "Image and vector sizes differ: (%d vs %d).", inImage->numRows, outVector->n);
     472
     473    if(inImage->numRows == 1) {
     474        // Create transposed row vector
     475        PS_CHECK_ALLOC_VECTOR(outVector, inImage->numCols, inImage->type.type);
     476        outVector->type.dimen = PS_DIMEN_TRANSV;
     477    } else if(inImage->numCols == 1) {
     478        // Create non-transposed column vector
     479        PS_CHECK_ALLOC_VECTOR(outVector, inImage->numRows, inImage->type.type);
     480    } else {
     481        psError(__func__, "Image does not have dim with 1 col or 1 row: (%d x %d).", inImage->numRows,
     482                inImage->numCols);
    481483        return outVector;
    482484    }
    483485
    484     colSize = PSELEMTYPE_SIZEOF(inImage->type.type)*inImage->numRows;
    485     memcpy(outVector->data.V, inImage->data.V[0], colSize);
     486    PS_CHECK_NULL_VECTOR(outVector, outVector);
     487
     488
     489    // More checks
     490    if(outVector->type.dimen == PS_DIMEN_VECTOR) {
     491        PS_CHECK_DIMEN_AND_TYPE(outVector, PS_DIMEN_VECTOR, outVector);
     492
     493        if(outVector->n == 0) {
     494            outVector->n = inImage->numRows;
     495        }
     496
     497        if(outVector->n != inImage->numRows) {
     498            psError(__func__, "Image and vector sizes differ: (%d vs %d).", inImage->numRows, outVector->n);
     499            return outVector;
     500        }
     501
     502        size = PSELEMTYPE_SIZEOF(inImage->type.type)*inImage->numRows;
     503
     504    } else if(outVector->type.dimen == PS_DIMEN_TRANSV) {
     505        PS_CHECK_DIMEN_AND_TYPE(outVector, PS_DIMEN_TRANSV, outVector);
     506
     507        if(outVector->n == 0) {
     508            outVector->n = inImage->numCols;
     509        }
     510
     511        if(outVector->n != inImage->numCols) {
     512            psError(__func__, "Image and vector sizes differ: (%d vs %d).", inImage->numCols, outVector->n);
     513            return outVector;
     514        }
     515
     516        size = PSELEMTYPE_SIZEOF(inImage->type.type)*inImage->numCols;
     517    }
     518
     519    memcpy(outVector->data.V, inImage->data.V[0], size);
    486520
    487521    return outVector;
     
    490524psImage *psVectorToMatrix(psImage *outImage, psVector *inVector)
    491525{
    492     int colSize = 0;
     526    int size = 0;
    493527
    494528    // Error checks
    495529    PS_CHECK_NULL_VECTOR(inVector, outImage);
    496     PS_CHECK_DIMEN_AND_TYPE(inVector, PS_DIMEN_VECTOR, outImage);
    497     PS_CHECK_SIZE_VECTOR(inVector, outImage);
    498     PS_CHECK_ALLOC_IMAGE(outImage, 1, inVector->n, PS_TYPE_F32)
     530
     531    if(inVector->type.dimen == PS_DIMEN_VECTOR) {
     532        PS_CHECK_DIMEN_AND_TYPE(inVector, PS_DIMEN_VECTOR, outImage);
     533        PS_CHECK_SIZE_VECTOR(inVector, outImage);
     534        PS_CHECK_ALLOC_IMAGE(outImage, 1, inVector->n, PS_TYPE_F64)
     535
     536        // More checks for PS_DIMEN_VECTOR
     537        if(outImage->numCols > 1) {
     538            psError(__func__, "Image has more than 1 column: numCols = %d.", outImage->numCols);
     539            return outImage;
     540        } else if(outImage->numRows != inVector->n) {
     541            psError(__func__, "Image and vector sizes differ: (%d vs %d).", outImage->numRows, inVector->n);
     542            return outImage;
     543        }
     544
     545        size = PSELEMTYPE_SIZEOF(outImage->type.type)*outImage->numRows;
     546
     547    } else if(inVector->type.dimen == PS_DIMEN_TRANSV) {
     548        PS_CHECK_DIMEN_AND_TYPE(inVector, PS_DIMEN_TRANSV, outImage);
     549        PS_CHECK_SIZE_VECTOR(inVector, outImage);
     550        PS_CHECK_ALLOC_IMAGE(outImage, inVector->n, 1, PS_TYPE_F64)
     551
     552        // More checks for PS_DIMEN_TRANSV
     553        if(outImage->numRows > 1) {
     554            psError(__func__, "Image has more than 1 row: numRows = %d.", outImage->numRows);
     555            return outImage;
     556        } else if(outImage->numCols != inVector->n) {
     557            psError(__func__, "Image and vector sizes differ: (%d vs %d).", outImage->numCols, inVector->n);
     558            return outImage;
     559        }
     560
     561        size = PSELEMTYPE_SIZEOF(outImage->type.type)*outImage->numCols;
     562    }
     563
    499564    PS_CHECK_NULL_IMAGE(outImage, outImage);
    500565    PS_CHECK_DIMEN_AND_TYPE(outImage, PS_DIMEN_IMAGE, outImage);
    501566
    502     // More checks
    503     if(outImage->numCols > 1) {
    504         psError(__func__, "Image has more than 1 column: numCols = %d.", outImage->numCols);
    505         return outImage;
    506     } else if(outImage->numRows != inVector->n) {
    507         psError(__func__, "Image and vector sizes differ: (%d vs %d).", outImage->numRows, inVector->n);
    508         return outImage;
    509     }
    510 
    511     colSize = PSELEMTYPE_SIZEOF(outImage->type.type)*outImage->numRows;
    512     memcpy(outImage->data.V[0], inVector->data.V, colSize);
     567    memcpy(outImage->data.V[0], inVector->data.V, size);
    513568
    514569    return outImage;
  • trunk/psLib/src/dataManip/psMatrix.h

    r807 r908  
    99 *      Matrix inversion
    1010 *      Calculate determinant
    11  *      Matrix addition
    12  *      Matrix subtraction
    1311 *      Matrix multiplication
    1412 *      Calculate Eigenvectors
     
    1715 *
    1816 *  These functions treat psImages as if they were matrices, therefore there is no psMatrix. These functions
    19  *  operate only with psF32 and psF64 data types.
     17 *  operate only with the psF64 data type.
    2018 *
    2119 *  @author Ross Harman, MHPCC
    2220 *   
    23  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    24  *  @date $Date: 2004-05-28 20:52:41 $
     21 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     22 *  @date $Date: 2004-06-08 01:58:03 $
    2523 *
    2624 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    10098 *  @return  float: Determinant from psImage.
    10199 */
    102 float psMatrixDeterminant(
     100float* psMatrixDeterminant(
    103101    const psImage *restrict inMatrix    ///< Image used to calculate determinant.
    104102);
     
    149147 *
    150148 *  Converts a 1-d psImage matrix into a vector. If the user specifies NULL as the outVector argument, then it
    151  *  will automatically be created. The input matrix must be a 1-d column matrix. This function operates only
    152  *  with the psF64 data type.
     149 *  will automatically be created based on the input image (PS_DIMEN_VECTOR for an input image with 1 col or
     150 *  PS_DIMENT_TRANSV for an input image with 1 row). Either the number of rows or the number of colums of the
     151 *  input matrix must be 1. This function operates only  with the psF64 data type.
    153152 *
    154153 *  @return  psVector*: Pointer to psVector.
     
    161160/** Convert vector to matrix.
    162161 *
    163  *  Converts a vector into a 1-d column psImage matrix. If the user specifies NULL as the outImage argument,
    164  *  then it will automatically be created. This function operates only with the psF64 data type. 
     162 *  Converts a vector into a psImage matrix. If the dimensionality of the vector is PS_DIMEN_VECTOR, then the
     163 *  resulting psImage is a 1d column. If the dimensionality of the vector is PS_DIMEN_TRANSV, then the
     164 *  resulting psImage is a 1d row. If the user specifies NULL as the outImage argument,  then it will
     165 *  automatically be created. This function operates only with the psF64 data type. 
    165166 *
    166167 *  @return  psVector*: Pointer to psIamge.
  • trunk/psLib/src/math/psMatrix.c

    r878 r908  
    2020 *  @author Ross Harman, MHPCC
    2121 *   
    22  *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    23  *  @date $Date: 2004-06-04 23:49:59 $
     22 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     23 *  @date $Date: 2004-06-08 01:57:52 $
    2424 *
    2525 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3535#include <gsl/gsl_eigen.h>
    3636
     37#include "psMemory.h"
    3738#include "psError.h"
    3839#include "psImage.h"
     
    253254
    254255    // Error checks
     256    if(det == NULL) {
     257        psError(__func__, "Invalid operation: determinant argument is NULL.");
     258        return outImage;
     259    }
    255260    PS_CHECK_POINTERS(inImage, outImage, outImage);
    256261    PS_CHECK_NULL_IMAGE(inImage, outImage);
     
    292297}
    293298
    294 float psMatrixDeterminant(const psImage *restrict inImage)
     299float* psMatrixDeterminant(const psImage *restrict inImage)
    295300{
    296301    int signum = 0;
     
    298303    int numRows = 0;
    299304    int numCols = 0;
    300     float det = 0.0f;
     305    float *det = NULL;
    301306    gsl_matrix *lu = NULL;
    302307    gsl_permutation *perm = NULL;
    303308
    304309    // Error checks
    305     PS_CHECK_NULL_IMAGE(inImage, 0);
    306     PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, 0);
    307     PS_CHECK_SIZE_IMAGE(inImage, 0);
     310    PS_CHECK_NULL_IMAGE(inImage, NULL);
     311    PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, NULL);
     312    PS_CHECK_SIZE_IMAGE(inImage, NULL);
    308313
    309314    // Initialize data
     
    323328
    324329    // Calculate determinant
     330    det = (float*)psAlloc(sizeof(float));
    325331    gsl_linalg_LU_decomp(lu, perm, &signum);
    326     det = (float)gsl_linalg_LU_det(lu, signum);
     332    *det = (float)gsl_linalg_LU_det(lu, signum);
    327333
    328334    // Free GSL structs
     
    458464psVector *psMatrixToVector(psVector *outVector, psImage *inImage)
    459465{
    460     int colSize = 0;
     466    int size = 0;
    461467
    462468    // Error checks
     
    464470    PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outVector);
    465471    PS_CHECK_SIZE_IMAGE(inImage, outVector);
    466     PS_CHECK_ALLOC_VECTOR(outVector, inImage->numRows, inImage->type.type);
    467     PS_CHECK_NULL_VECTOR(outVector, outVector);
    468     PS_CHECK_DIMEN_AND_TYPE(outVector, PS_DIMEN_VECTOR, outVector);
    469 
    470     // Set n if allocated, but empty
    471     if(outVector->n == 0) {
    472         outVector->n = inImage->numRows;
    473     }
    474 
    475     // More checks
    476     if(inImage->numCols > 1) {
    477         psError(__func__, "Image has more than 1 column: numCols = %d.", inImage->numCols);
    478         return outVector;
    479     } else if(outVector->n != inImage->numRows) {
    480         psError(__func__, "Image and vector sizes differ: (%d vs %d).", inImage->numRows, outVector->n);
     472
     473    if(inImage->numRows == 1) {
     474        // Create transposed row vector
     475        PS_CHECK_ALLOC_VECTOR(outVector, inImage->numCols, inImage->type.type);
     476        outVector->type.dimen = PS_DIMEN_TRANSV;
     477    } else if(inImage->numCols == 1) {
     478        // Create non-transposed column vector
     479        PS_CHECK_ALLOC_VECTOR(outVector, inImage->numRows, inImage->type.type);
     480    } else {
     481        psError(__func__, "Image does not have dim with 1 col or 1 row: (%d x %d).", inImage->numRows,
     482                inImage->numCols);
    481483        return outVector;
    482484    }
    483485
    484     colSize = PSELEMTYPE_SIZEOF(inImage->type.type)*inImage->numRows;
    485     memcpy(outVector->data.V, inImage->data.V[0], colSize);
     486    PS_CHECK_NULL_VECTOR(outVector, outVector);
     487
     488
     489    // More checks
     490    if(outVector->type.dimen == PS_DIMEN_VECTOR) {
     491        PS_CHECK_DIMEN_AND_TYPE(outVector, PS_DIMEN_VECTOR, outVector);
     492
     493        if(outVector->n == 0) {
     494            outVector->n = inImage->numRows;
     495        }
     496
     497        if(outVector->n != inImage->numRows) {
     498            psError(__func__, "Image and vector sizes differ: (%d vs %d).", inImage->numRows, outVector->n);
     499            return outVector;
     500        }
     501
     502        size = PSELEMTYPE_SIZEOF(inImage->type.type)*inImage->numRows;
     503
     504    } else if(outVector->type.dimen == PS_DIMEN_TRANSV) {
     505        PS_CHECK_DIMEN_AND_TYPE(outVector, PS_DIMEN_TRANSV, outVector);
     506
     507        if(outVector->n == 0) {
     508            outVector->n = inImage->numCols;
     509        }
     510
     511        if(outVector->n != inImage->numCols) {
     512            psError(__func__, "Image and vector sizes differ: (%d vs %d).", inImage->numCols, outVector->n);
     513            return outVector;
     514        }
     515
     516        size = PSELEMTYPE_SIZEOF(inImage->type.type)*inImage->numCols;
     517    }
     518
     519    memcpy(outVector->data.V, inImage->data.V[0], size);
    486520
    487521    return outVector;
     
    490524psImage *psVectorToMatrix(psImage *outImage, psVector *inVector)
    491525{
    492     int colSize = 0;
     526    int size = 0;
    493527
    494528    // Error checks
    495529    PS_CHECK_NULL_VECTOR(inVector, outImage);
    496     PS_CHECK_DIMEN_AND_TYPE(inVector, PS_DIMEN_VECTOR, outImage);
    497     PS_CHECK_SIZE_VECTOR(inVector, outImage);
    498     PS_CHECK_ALLOC_IMAGE(outImage, 1, inVector->n, PS_TYPE_F32)
     530
     531    if(inVector->type.dimen == PS_DIMEN_VECTOR) {
     532        PS_CHECK_DIMEN_AND_TYPE(inVector, PS_DIMEN_VECTOR, outImage);
     533        PS_CHECK_SIZE_VECTOR(inVector, outImage);
     534        PS_CHECK_ALLOC_IMAGE(outImage, 1, inVector->n, PS_TYPE_F64)
     535
     536        // More checks for PS_DIMEN_VECTOR
     537        if(outImage->numCols > 1) {
     538            psError(__func__, "Image has more than 1 column: numCols = %d.", outImage->numCols);
     539            return outImage;
     540        } else if(outImage->numRows != inVector->n) {
     541            psError(__func__, "Image and vector sizes differ: (%d vs %d).", outImage->numRows, inVector->n);
     542            return outImage;
     543        }
     544
     545        size = PSELEMTYPE_SIZEOF(outImage->type.type)*outImage->numRows;
     546
     547    } else if(inVector->type.dimen == PS_DIMEN_TRANSV) {
     548        PS_CHECK_DIMEN_AND_TYPE(inVector, PS_DIMEN_TRANSV, outImage);
     549        PS_CHECK_SIZE_VECTOR(inVector, outImage);
     550        PS_CHECK_ALLOC_IMAGE(outImage, inVector->n, 1, PS_TYPE_F64)
     551
     552        // More checks for PS_DIMEN_TRANSV
     553        if(outImage->numRows > 1) {
     554            psError(__func__, "Image has more than 1 row: numRows = %d.", outImage->numRows);
     555            return outImage;
     556        } else if(outImage->numCols != inVector->n) {
     557            psError(__func__, "Image and vector sizes differ: (%d vs %d).", outImage->numCols, inVector->n);
     558            return outImage;
     559        }
     560
     561        size = PSELEMTYPE_SIZEOF(outImage->type.type)*outImage->numCols;
     562    }
     563
    499564    PS_CHECK_NULL_IMAGE(outImage, outImage);
    500565    PS_CHECK_DIMEN_AND_TYPE(outImage, PS_DIMEN_IMAGE, outImage);
    501566
    502     // More checks
    503     if(outImage->numCols > 1) {
    504         psError(__func__, "Image has more than 1 column: numCols = %d.", outImage->numCols);
    505         return outImage;
    506     } else if(outImage->numRows != inVector->n) {
    507         psError(__func__, "Image and vector sizes differ: (%d vs %d).", outImage->numRows, inVector->n);
    508         return outImage;
    509     }
    510 
    511     colSize = PSELEMTYPE_SIZEOF(outImage->type.type)*outImage->numRows;
    512     memcpy(outImage->data.V[0], inVector->data.V, colSize);
     567    memcpy(outImage->data.V[0], inVector->data.V, size);
    513568
    514569    return outImage;
  • trunk/psLib/src/math/psMatrix.h

    r807 r908  
    99 *      Matrix inversion
    1010 *      Calculate determinant
    11  *      Matrix addition
    12  *      Matrix subtraction
    1311 *      Matrix multiplication
    1412 *      Calculate Eigenvectors
     
    1715 *
    1816 *  These functions treat psImages as if they were matrices, therefore there is no psMatrix. These functions
    19  *  operate only with psF32 and psF64 data types.
     17 *  operate only with the psF64 data type.
    2018 *
    2119 *  @author Ross Harman, MHPCC
    2220 *   
    23  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    24  *  @date $Date: 2004-05-28 20:52:41 $
     21 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     22 *  @date $Date: 2004-06-08 01:58:03 $
    2523 *
    2624 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    10098 *  @return  float: Determinant from psImage.
    10199 */
    102 float psMatrixDeterminant(
     100float* psMatrixDeterminant(
    103101    const psImage *restrict inMatrix    ///< Image used to calculate determinant.
    104102);
     
    149147 *
    150148 *  Converts a 1-d psImage matrix into a vector. If the user specifies NULL as the outVector argument, then it
    151  *  will automatically be created. The input matrix must be a 1-d column matrix. This function operates only
    152  *  with the psF64 data type.
     149 *  will automatically be created based on the input image (PS_DIMEN_VECTOR for an input image with 1 col or
     150 *  PS_DIMENT_TRANSV for an input image with 1 row). Either the number of rows or the number of colums of the
     151 *  input matrix must be 1. This function operates only  with the psF64 data type.
    153152 *
    154153 *  @return  psVector*: Pointer to psVector.
     
    161160/** Convert vector to matrix.
    162161 *
    163  *  Converts a vector into a 1-d column psImage matrix. If the user specifies NULL as the outImage argument,
    164  *  then it will automatically be created. This function operates only with the psF64 data type. 
     162 *  Converts a vector into a psImage matrix. If the dimensionality of the vector is PS_DIMEN_VECTOR, then the
     163 *  resulting psImage is a 1d column. If the dimensionality of the vector is PS_DIMEN_TRANSV, then the
     164 *  resulting psImage is a 1d row. If the user specifies NULL as the outImage argument,  then it will
     165 *  automatically be created. This function operates only with the psF64 data type. 
    165166 *
    166167 *  @return  psVector*: Pointer to psIamge.
  • trunk/psLib/test/dataManip/tst_psMatrix07.c

    r831 r908  
    55 *  This test driver contains the following tests for psMatrix test point 7:
    66 *     A)  Create input and output images and vectors
    7  *     B)  Convert matrix to vector
    8  *     C)  Convert vector to matrix
    9  *     D)  Free input and output images and vectors
     7 *     B)  Convert matrix to PS_DIMEN_VECTOR vector
     8 *     C)  Attempt to use null image input argument
     9 *     D)  Convert matrix to PS_DIMEN_TRANSV vector
     10 *     E)  Improper image size
     11 *     F)  Convert PS_DIMEN_VECTOR vector to matrix
     12 *     G)  Attempt to use null input vector argument
     13 *     H)  Convert PS_DIMEN_TRANSV vector to matrix
     14 *     I)  Free input and output images and vectors
    1015 *
    1116 *  @author  Ross Harman, MHPCC
    1217 *
    13  *  @version $Revision: 1.2 $  $Name: not supported by cvs2svn $
    14  *  @date  $Date: 2004-06-02 23:29:39 $
     18 *  @version $Revision: 1.3 $  $Name: not supported by cvs2svn $
     19 *  @date  $Date: 2004-06-08 01:56:35 $
    1520 *
    1621 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2227
    2328#define PRINT_MATRIX(IMAGE)                         \
    24 for(int i=0; i<IMAGE->numRows; i++) {           \
    25     for(int j=0; j<IMAGE->numCols; j++) {       \
    26         printf("%f ", IMAGE->data.F64[i][j]);   \
    27     }                                          \
    28     printf("\n");                              \
     29for(int i=0; i<IMAGE->numRows; i++) {               \
     30    for(int j=0; j<IMAGE->numCols; j++) {           \
     31        printf("%f ", IMAGE->data.F64[i][j]);       \
     32    }                                               \
     33    printf("\n");                                   \
    2934}
    3035
    3136#define PRINT_VECTOR(VECTOR)                        \
    32 for(int i=0; i<VECTOR->n; i++) {               \
    33     printf("%f\n", VECTOR->data.F64[i]);          \
     37for(int i=0; i<VECTOR->n; i++) {                    \
     38    printf("%f\n", VECTOR->data.F64[i]);            \
    3439}
    3540
     
    3944{
    4045    psVector *v1 = NULL;
     46    psVector *tempVector = NULL;
     47    psImage *tempImage = NULL;
    4148    psImage *m1 = NULL;
    4249    psVector *v2 = NULL;
    4350    psImage *m2 = NULL;
     51    psImage *m3 = NULL;
     52    psImage *m4 = NULL;
     53    psImage *badImage = NULL;
    4454
    4555
     
    5060    v2 = (psVector*)psVectorAlloc(3, PS_TYPE_F64);
    5161    m2 = (psImage*)psImageAlloc(1, 3, PS_TYPE_F64);
     62    m3 = (psImage*)psImageAlloc(3, 1, PS_TYPE_F64);
     63    m4 = (psImage*)psImageAlloc(3, 1, PS_TYPE_F64);
     64    badImage = (psImage*)psImageAlloc(2, 2, PS_TYPE_F64);
    5265    m1->data.F64[0][0] = 0.0;
    5366    m1->data.F64[1][0] = 1.0;
     
    5770    v2->data.F64[2] = 2.0;
    5871    v2->n = 3;
     72    m4->data.F64[0][0] = 0.0;
     73    m4->data.F64[0][1] = 1.0;
     74    m4->data.F64[0][2] = 2.0;
    5975    PRINT_MATRIX(m1);
     76    printf("\n");
     77    PRINT_MATRIX(m4);
    6078    printf("\n");
    6179    PRINT_VECTOR(v2);
     
    6381
    6482
    65     // Test B - Convert matrix to vector
    66     printPositiveTestHeader(stdout, "psMatrix", "Convert matrix to vector");
    67     psMatrixToVector(v1, m1);
     83    // Test B - Convert matrix to PS_DIMEN_VECTOR vector
     84    printPositiveTestHeader(stdout, "psMatrix", "Convert matrix to PS_DIMEN_VECTOR vector");
     85    tempVector = v1;
     86    v1 = psMatrixToVector(v1, m1);
    6887    PRINT_VECTOR(v1);
    69     printFooter(stdout, "psMatrix", "Calculate Eigenvectors", true);
     88    if(v1->type.dimen != PS_DIMEN_VECTOR) {
     89        printf("Error: Resulting image is not PS_DIMEN_VECTOR\n");
     90    } else if(v1 != tempVector) {
     91        printf("Error: Return pointer not equal to output argument pointer\n");
     92    }
     93    printFooter(stdout, "psMatrix", "Convert matrix to PS_DIMEN_VECTOR vector", true);
    7094
    7195
    72     // Test C - Convert vector to matrix
    73     printPositiveTestHeader(stdout, "psMatrix", "Convert vector to matrix");
    74     psVectorToMatrix(m2, v2);
    75     PRINT_MATRIX(m2);
    76     printFooter(stdout, "psMatrix", "Convert vector to matrix", true);
     96    // Test C - Attempt to use null image input argument
     97    printNegativeTestHeader(stdout,"psMatrix", "Attempt to use null image input argument",
     98                            "Invalid operation: inImage or its data is NULL.", 0);
     99    v1 = psMatrixToVector(v1, NULL);
     100    printFooter(stdout, "psMatrix", "Attempt to use null image input argument", true);
    77101
    78102
    79     // Test D - Free input and output images
     103    // Test D - Convert matrix to PS_DIMEN_TRANSV vector
     104    printPositiveTestHeader(stdout, "psMatrix", "Convert matrix to PS_DIMEN_TRANSV vector");
     105    v1->type.dimen = PS_DIMEN_TRANSV;
     106    psMatrixToVector(v1, m4);
     107    PRINT_VECTOR(v1);
     108    if(v1->type.dimen != PS_DIMEN_TRANSV) {
     109        printf("Error: Resulting image is not PS_DIMEN_TRANSV\n");
     110    } else if(v1 != tempVector) {
     111        printf("Error: Return pointer not equal to output argument pointer\n");
     112    }
     113    printFooter(stdout, "psMatrix", "Convert matrix to PS_DIMEN_TRANSV vector", true);
     114
     115
     116    // Test E - Improper image size
     117    printNegativeTestHeader(stdout,"psMatrix", "Improper image size",
     118                            "Image does not have dim with 1 col or 1 row: (2 x 2).", 0);
     119    psMatrixToVector(v1, badImage);
     120    printFooter(stdout, "psMatrix", "Improper image size", true);
     121
     122
     123    // Test F - Convert PS_DIMEN_VECTOR vector to matrix
     124    printPositiveTestHeader(stdout, "psMatrix", "Convert PS_DIMEN_VECTOR vector to matrix");
     125    tempImage = m2;
     126    m2 = psVectorToMatrix(m2, v2);
     127    PRINT_MATRIX(m2);
     128    if(m2->type.dimen != PS_DIMEN_IMAGE) {
     129        printf("Error: Resulting image is not PS_DIMEN_IMAGE\n");
     130    } else if(m2 != tempImage) {
     131        printf("Error: Return pointer not equal to output argument pointer\n");
     132    }
     133    printFooter(stdout, "psMatrix", "Convert PS_DIMEN_VECTOR vector to matrix", true);
     134
     135
     136    // Test G - Attempt to use null input vector argument
     137    printNegativeTestHeader(stdout,"psMatrix", "Attempt to use null input vector argument",
     138                            "Invalid operation: inVector or its data is NULL.", 0);
     139    psVectorToMatrix(m2, NULL);
     140    printFooter(stdout, "psMatrix", "Attempt to use null input vector argument", true);
     141
     142
     143    // Test H - Convert PS_DIMEN_TRANSV vector to matrix
     144    printPositiveTestHeader(stdout, "psMatrix", "Convert PS_DIMEN_TRANSV vector to matrix");
     145    v2->type.dimen = PS_DIMEN_TRANSV;
     146    tempImage = m3;
     147    psVectorToMatrix(m3, v2);
     148    PRINT_MATRIX(m3);
     149    if(m3->type.dimen != PS_DIMEN_IMAGE) {
     150        printf("Error: Resulting image is not PS_DIMEN_IMAGE\n");
     151    } else if(m3 != tempImage) {
     152        printf("Error: Return pointer not equal to output argument pointer\n");
     153    }
     154    printFooter(stdout, "psMatrix", "Convert PS_DIMEN_TRANSV vector to matrix", true);
     155
     156
     157    // Test I - Free input and output images
    80158    printPositiveTestHeader(stdout, "psMatrix", "Free input and output images and vectors");
    81159    psImageFree(m1);
     
    83161    psImageFree(m2);
    84162    psVectorFree(v2);
     163    psImageFree(m3);
     164    psImageFree(m4);
     165    psImageFree(badImage);
    85166    psMemCheckLeaks(0, NULL, stdout);
    86167    int nBad = psMemCheckCorruption(0);
  • trunk/psLib/test/dataManip/verified/tst_psMatrix07.stdout

    r804 r908  
    992.000000
    1010
     110.000000 1.000000 2.000000
     12
    11130.000000
    12141.000000
     
    1719/----------------------------- TESTPOINT ------------------------------------------\
    1820|             TestFile: tst_psMatrix07.c                                           |
    19 |            TestPoint: psMatrix{Convert matrix to vector}                         |
     21|            TestPoint: psMatrix{Convert matrix to PS_DIMEN_VECTOR vector}         |
    2022|             TestType: Positive                                                   |
    2123\----------------------------------------------------------------------------------/
     
    25272.000000
    2628
    27 ---> TESTPOINT PASSED (psMatrix{Calculate Eigenvectors} | tst_psMatrix07.c)
     29---> TESTPOINT PASSED (psMatrix{Convert matrix to PS_DIMEN_VECTOR vector} | tst_psMatrix07.c)
    2830
    2931/----------------------------- TESTPOINT ------------------------------------------\
    3032|             TestFile: tst_psMatrix07.c                                           |
    31 |            TestPoint: psMatrix{Convert vector to matrix}                         |
     33|            TestPoint: psMatrix{Attempt to use null image input argument}         |
     34|             TestType: Negative                                                   |
     35|    ExpectedErrorText: Invalid operation: inImage or its data is NULL.            |
     36|  ExpectedStatusValue: 0                                                          |
     37\----------------------------------------------------------------------------------/
     38
     39
     40---> TESTPOINT PASSED (psMatrix{Attempt to use null image input argument} | tst_psMatrix07.c)
     41
     42/----------------------------- TESTPOINT ------------------------------------------\
     43|             TestFile: tst_psMatrix07.c                                           |
     44|            TestPoint: psMatrix{Convert matrix to PS_DIMEN_TRANSV vector}         |
     45|             TestType: Positive                                                   |
     46\----------------------------------------------------------------------------------/
     47
     480.000000
     491.000000
     502.000000
     51
     52---> TESTPOINT PASSED (psMatrix{Convert matrix to PS_DIMEN_TRANSV vector} | tst_psMatrix07.c)
     53
     54/----------------------------- TESTPOINT ------------------------------------------\
     55|             TestFile: tst_psMatrix07.c                                           |
     56|            TestPoint: psMatrix{Improper image size}                              |
     57|             TestType: Negative                                                   |
     58|    ExpectedErrorText: Image does not have dim with 1 col or 1 row: (2 x 2).      |
     59|  ExpectedStatusValue: 0                                                          |
     60\----------------------------------------------------------------------------------/
     61
     62
     63---> TESTPOINT PASSED (psMatrix{Improper image size} | tst_psMatrix07.c)
     64
     65/----------------------------- TESTPOINT ------------------------------------------\
     66|             TestFile: tst_psMatrix07.c                                           |
     67|            TestPoint: psMatrix{Convert PS_DIMEN_VECTOR vector to matrix}         |
    3268|             TestType: Positive                                                   |
    3369\----------------------------------------------------------------------------------/
     
    37732.000000
    3874
    39 ---> TESTPOINT PASSED (psMatrix{Convert vector to matrix} | tst_psMatrix07.c)
     75---> TESTPOINT PASSED (psMatrix{Convert PS_DIMEN_VECTOR vector to matrix} | tst_psMatrix07.c)
     76
     77/----------------------------- TESTPOINT ------------------------------------------\
     78|             TestFile: tst_psMatrix07.c                                           |
     79|            TestPoint: psMatrix{Attempt to use null input vector argument}        |
     80|             TestType: Negative                                                   |
     81|    ExpectedErrorText: Invalid operation: inVector or its data is NULL.           |
     82|  ExpectedStatusValue: 0                                                          |
     83\----------------------------------------------------------------------------------/
     84
     85
     86---> TESTPOINT PASSED (psMatrix{Attempt to use null input vector argument} | tst_psMatrix07.c)
     87
     88/----------------------------- TESTPOINT ------------------------------------------\
     89|             TestFile: tst_psMatrix07.c                                           |
     90|            TestPoint: psMatrix{Convert PS_DIMEN_TRANSV vector to matrix}         |
     91|             TestType: Positive                                                   |
     92\----------------------------------------------------------------------------------/
     93
     940.000000 1.000000 2.000000
     95
     96---> TESTPOINT PASSED (psMatrix{Convert PS_DIMEN_TRANSV vector to matrix} | tst_psMatrix07.c)
    4097
    4198/----------------------------- TESTPOINT ------------------------------------------\
Note: See TracChangeset for help on using the changeset viewer.