IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 10, 2004, 9:11:23 AM (22 years ago)
Author:
harman
Message:

Added support for psF32 types

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/dataManip/tst_psMatrix03.c

    r2392 r2683  
    1414 *  @author  Ross Harman, MHPCC
    1515 *
    16  *  @version $Revision: 1.10 $  $Name: not supported by cvs2svn $
    17  *  @date  $Date: 2004-11-22 21:00:21 $
     16 *  @version $Revision: 1.11 $  $Name: not supported by cvs2svn $
     17 *  @date  $Date: 2004-12-10 19:11:23 $
    1818 *
    1919 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2424#include "psTest.h"
    2525
    26 #define PRINT_MATRIX(IMAGE)                     \
    27 for(psS32 i=IMAGE->numRows-1; i>-1; i--) {        \
    28     for(psS32 j=0; j<IMAGE->numCols; j++) {       \
    29         printf("%f ", IMAGE->data.F64[i][j]);   \
    30     }                                           \
    31     printf("\n");                               \
     26#define TOLERANCE 0.000001
     27
     28#define CHECK_MATRIX(IMAGE)                                                                                  \
     29for(psU32 i=0; i<IMAGE->numRows; i++) {                                                                  \
     30    for(psU32 j=0; j<IMAGE->numCols; j++) {                                                              \
     31        if(IMAGE->type.type == PS_TYPE_F64) {                                                            \
     32            if(fabs(IMAGE->data.F64[i][j]-truthMatrix[i][j]) > TOLERANCE) {                              \
     33                printf("Matrix values at element %d, %d don't agree %lf vs %lf\n", i, j,                 \
     34                       IMAGE->data.F64[i][j], truthMatrix[i][j]);                                        \
     35            }                                                                                            \
     36        } else if(IMAGE->type.type == PS_TYPE_F32){                                                      \
     37            if(fabs(IMAGE->data.F32[i][j]-truthMatrix[i][j]) > TOLERANCE) {                              \
     38                printf("%lf\n", fabs(IMAGE->data.F32[i][j]-truthMatrix[i][j])),                              \
     39                printf("Matrix values at element %d, %d don't agree %f vs %lf\n", i, j,                  \
     40                       IMAGE->data.F32[i][j], truthMatrix[i][j]);                                        \
     41            }                                                                                            \
     42        }                                                                                                \
     43    }                                                                                                    \
    3244}
    33 \
    34 #define PRINT_VECTOR(VECTOR)                    \
    35 for(psS32 i=0; i<VECTOR->n; i++) {                \
    36     printf("%f\n", VECTOR->data.F64[i]);        \
     45
     46#define CHECK_VECTOR(VECTOR)                                                                                 \
     47for(psU32 i=0; i<VECTOR->n; i++) {                                                                       \
     48    if(VECTOR->type.type == PS_TYPE_F64) {                                                               \
     49        if(fabs(VECTOR->data.F64[i]-truthVector[i]) > TOLERANCE) {                                       \
     50            printf("Vector values at element %d don't agree %lf vs %lf\n", i,                            \
     51                   VECTOR->data.F64[i], truthVector[i]);                                                 \
     52        }                                                                                                \
     53    } else if(VECTOR->type.type == PS_TYPE_F32){                                                         \
     54        if(fabs(VECTOR->data.F32[i]-truthVector[i]) > TOLERANCE) {                                       \
     55            printf("Vector values at element %d don't agree %f vs %lf\n", i,                             \
     56                   VECTOR->data.F32[i], truthVector[i]);                                                 \
     57        }                                                                                                \
     58    }                                                                                                    \
    3759}
    3860
    3961
    40 psS32 main(psS32 argc,
    41            char* argv[])
     62psS32 main(psS32 argc, char* argv[])
    4263{
    4364    psImage *luImage = NULL;
     
    4869    psVector *outVector = NULL;
    4970    psVector *inVector = NULL;
     71    psImage *luImage32 = NULL;
     72    psImage *inImage32 = NULL;
     73    psImage *tempImage32 = NULL;
     74    psVector *tempVector32 = NULL;
     75    psVector *perm32 = NULL;
     76    psVector *outVector32 = NULL;
     77    psVector *inVector32 = NULL;
     78
     79    double truthVector[3] = {
     80                                4.000000,
     81                                -2.000000,
     82                                3.000000
     83                            };
     84
     85    double truthMatrix[3][3] = {{4.000000,  5.000000,  6.000000},
     86                                {0.750000, -2.750000, -6.500000},
     87                                {0.500000, -0.545455, -0.545455}};
    5088
    5189
     
    70108    inVector->data.F64[2] =  4.0;
    71109    inVector->n = 3;
    72     PRINT_MATRIX(inImage);
    73     printf("\n");
    74     PRINT_VECTOR(inVector);
     110    luImage32 = (psImage*)psImageAlloc(3, 3, PS_TYPE_F32);
     111    perm32 = (psVector*)psVectorAlloc(3, PS_TYPE_F32);
     112    outVector32 = (psVector*)psVectorAlloc(3, PS_TYPE_F32);
     113    inVector32 = (psVector*)psVectorAlloc(3, PS_TYPE_F32);
     114    inImage32 = (psImage*)psImageAlloc(3, 3, PS_TYPE_F32);
     115    inImage32->data.F32[0][0] =  2;
     116    inImage32->data.F32[0][1] =  4;
     117    inImage32->data.F32[0][2] =  6;
     118    inImage32->data.F32[1][0] =  4;
     119    inImage32->data.F32[1][1] =  5;
     120    inImage32->data.F32[1][2] =  6;
     121    inImage32->data.F32[2][0] =  3;
     122    inImage32->data.F32[2][1] =  1;
     123    inImage32->data.F32[2][2] = -2;
     124    inVector32->data.F32[0] = 18.0;
     125    inVector32->data.F32[1] = 24.0;
     126    inVector32->data.F32[2] =  4.0;
     127    inVector32->n = 3;
    75128    printFooter(stdout, "psMatrix", "Create input and output images and vectors", true);
    76129
     
    80133    tempImage = luImage;
    81134    luImage = psMatrixLUD(luImage, perm, inImage);
    82     PRINT_MATRIX(luImage);
     135    CHECK_MATRIX(luImage);
    83136    if(luImage->type.dimen != PS_DIMEN_IMAGE) {
    84137        printf("Error: Resulting image is not PS_DIMEN_IMAGE\n");
    85     } else
    86         if(luImage != tempImage) {
    87             printf("Error: Return pointer not equal to output argument pointer\n");
    88         }
     138    } else if(luImage != tempImage) {
     139        printf("Error: Return pointer not equal to output argument pointer\n");
     140    }
     141
     142    tempImage32 = luImage32;
     143    luImage32 = psMatrixLUD(luImage32, perm32, inImage32);
     144    CHECK_MATRIX(luImage32);
     145    if(luImage32->type.dimen != PS_DIMEN_IMAGE) {
     146        printf("Error: Resulting image is not PS_DIMEN_IMAGE\n");
     147    } else if(luImage32 != tempImage32) {
     148        printf("Error: Return pointer not equal to output argument pointer\n");
     149    }
    89150    printFooter(stdout, "psMatrix", "Calculate LU matrix", true);
    90151
     
    94155    tempVector = outVector;
    95156    outVector = psMatrixLUSolve(outVector, luImage, inVector, perm);
    96     PRINT_VECTOR(outVector);
     157    CHECK_VECTOR(outVector);
    97158    if(outVector->type.dimen != PS_DIMEN_VECTOR) {
    98159        printf("Error: Resulting image is not PS_DIMEN_VECTOR\n");
    99     } else
    100         if(outVector != tempVector) {
    101             printf("Error: Return pointer not equal to output argument pointer\n");
    102         }
     160    } else if(outVector != tempVector) {
     161        printf("Error: Return pointer not equal to output argument pointer\n");
     162    }
     163
     164    tempVector32 = outVector32;
     165    outVector32 = psMatrixLUSolve(outVector32, luImage32, inVector32, perm32);
     166    CHECK_VECTOR(outVector32);
     167    if(outVector32->type.dimen != PS_DIMEN_VECTOR) {
     168        printf("Error: Resulting image is not PS_DIMEN_VECTOR\n");
     169    } else if(outVector32 != tempVector32) {
     170        printf("Error: Return pointer not equal to output argument pointer\n");
     171    }
    103172    printFooter(stdout, "psMatrix", "Determine solution to matrix equation", true);
    104173
     
    111180    psFree(outVector);
    112181    psFree(inVector);
     182    psFree(inImage32);
     183    psFree(luImage32);
     184    psFree(perm32);
     185    psFree(outVector32);
     186    psFree(inVector32);
    113187    if( psMemCheckLeaks(0, NULL, stdout, false) ) {
    114188        psError(PS_ERR_UNKNOWN,true,"Memory leaks detected");
Note: See TracChangeset for help on using the changeset viewer.