IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

Added more unit tests

File:
1 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;
Note: See TracChangeset for help on using the changeset viewer.