IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 28, 2004, 3:36:26 PM (22 years ago)
Author:
harman
Message:

More tests

File:
1 edited

Legend:

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

    r1083 r1112  
    11/** @file  tst_psMatrix_01.c
    22 *
    3  *  @brief Test driver for psMatrix transpose function
    4  *
    5  *  This test driver contains the following tests for psMatrix test point 1:
    6  *     A)  Create input and output images
    7  *     B)  Transpose input image into output image
    8  *     C)  Transpose input image into auto allocated NULL output image
    9  *     D)  Free images and check for leaks
     3 *  @brief Test driver for psMatrixVector arithmetic functions
     4 *
     5 *  This test driver tests combinations of matrix, vector, and scalar binary operations including:
     6 *     Matrix-matrix with +,-,*,/ with S32, F32, F64, C32
     7 *     Matrix-vector with +,-,*,/ with S32, F32, F64, C32
     8 *     Matrix-scalar with +,-,*,/ with S32, F32, F64, C32
    109 *
    1110 *  @author  Ross Harman, MHPCC
    1211 *
    13  *  @version $Revision: 1.1 $  $Name: not supported by cvs2svn $
    14  *  @date  $Date: 2004-06-24 18:59:57 $
     12 *  @version $Revision: 1.2 $  $Name: not supported by cvs2svn $
     13 *  @date  $Date: 2004-06-29 01:36:26 $
    1514 *
    1615 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2120#include "psTest.h"
    2221
    23 #define PRINT_MATRIX(IMAGE)                         \
    24 for(int i=IMAGE->numRows-1; i>-1; i--) {            \
    25     for(int j=0; j<IMAGE->numCols; j++) {           \
    26         printf("%f ", IMAGE->data.F64[i][j]);       \
    27     }                                               \
    28     printf("\n");                                   \
    29 }                                                   \
     22#define PRINT_SCALAR(SCALAR,TYPE)                                                                            \
     23if(PS_IS_PSELEMTYPE_COMPLEX(SCALAR->type.type)) {                                                        \
     24    printf("%f+%fi ", creal(SCALAR->data.TYPE), cimag(SCALAR->data.TYPE));                               \
     25} else if(PS_IS_PSELEMTYPE_INT(SCALAR->type.type)) {                                                     \
     26    printf("%d ", (int)SCALAR->data.TYPE);                                                               \
     27} else {                                                                                                 \
     28    printf("%f ", (double)SCALAR->data.TYPE);                                                            \
     29}                                                                                                        \
     30printf("\n\n");
     31
     32#define PRINT_VECTOR(VECTOR,TYPE)                                                                            \
     33for(int i=0; i<VECTOR->n; i++) {                                                                         \
     34    if(PS_IS_PSELEMTYPE_COMPLEX(VECTOR->type.type)) {                                                    \
     35        printf("%f+%fi ", creal(VECTOR->data.TYPE[i]), cimag(VECTOR->data.TYPE[i]));                     \
     36    } else if(PS_IS_PSELEMTYPE_INT(VECTOR->type.type)) {                                                 \
     37        printf("%d ", (int)VECTOR->data.TYPE[i]);                                                        \
     38    } else {                                                                                             \
     39        printf("%f ", (double)VECTOR->data.TYPE[i]);                                                     \
     40    }                                                                                                    \
     41}                                                                                                        \
     42printf("\n\n");
     43
     44
     45#define PRINT_MATRIX(IMAGE,TYPE)                                                                             \
     46for(int i=IMAGE->numRows-1; i>-1; i--) {                                                                 \
     47    for(int j=0; j<IMAGE->numCols; j++) {                                                                \
     48        if(PS_IS_PSELEMTYPE_COMPLEX(IMAGE->type.type)) {                                                 \
     49            printf("%f+%fi ", creal(IMAGE->data.TYPE[i][j]), cimag(IMAGE->data.TYPE[i][j]));             \
     50        } else if(PS_IS_PSELEMTYPE_INT(IMAGE->type.type)) {                                              \
     51            printf("%d ", (int)IMAGE->data.TYPE[i][j]);                                                  \
     52        } else {                                                                                         \
     53            printf("%f ", (double)IMAGE->data.TYPE[i][j]);                                               \
     54        }                                                                                                \
     55    }                                                                                                    \
     56    printf("\n");                                                                                        \
     57}                                                                                                        \
    3058printf("\n");
    3159
    32 int main(int argc,
    33          char* argv[])
     60
     61#define CREATE_AND_SET_VECTOR(NAME,TYPE,VALUE,SIZE)                                                          \
     62psVector *NAME = (psVector*)psVectorAlloc(SIZE, PS_TYPE_##TYPE);                                         \
     63for(int i=0; i<SIZE; i++) {                                                                              \
     64    NAME->data.TYPE[i] = VALUE;                                                                          \
     65}                                                                                                        \
     66NAME->n = SIZE;
     67
     68
     69#define CREATE_AND_SET_IMAGE(NAME,TYPE,VALUE,NROWS,NCOLS)                                                    \
     70psImage *NAME = (psImage*)psImageAlloc(NCOLS,NROWS,PS_TYPE_##TYPE);                                      \
     71for(int i=0; i<NAME->numRows; i++) {                                                                     \
     72    for(int j=0; j<NAME->numCols; j++) {                                                                 \
     73        NAME->data.TYPE[i][j] = VALUE;                                                                   \
     74    }                                                                                                    \
     75}
     76
     77
     78#define CHECK_MEMORY                                                                                         \
     79psMemCheckLeaks(0, NULL, stdout);                                                                        \
     80int nBad = psMemCheckCorruption(0);                                                                      \
     81if(nBad) {                                                                                               \
     82    printf("ERROR: Found %d bad memory blocks\n", nBad);                                                 \
     83}
     84
     85
     86int main(int argc, char* argv[])
    3487{
    35     psVector *psVec1 = psVectorAlloc(5, PS_TYPE_S32);
    36     psVector *psVec2 = psVectorAlloc(5, PS_TYPE_S32);
    37 
    38     for(int i = 0; i < 5; i++) {
    39         psVec1->data.S32[i] = i*10;
    40         psVec1->n++;
    41         psVec2->data.S32[i] = i*10;
    42         psVec2->n++;
     88
     89    // Test matrix-matrix binary operations
     90    #define testBinaryOpMM(OP,TYPE,VALUE1,VALUE2,NROWS,NCOLS)                                                \
     91    {                                                                                                        \
     92        printPositiveTestHeader(stdout, "psMatrixVectorArithmetic", "Test matrix-matrix psBinaryOp");        \
     93        printf("Operation: %s\n", #OP);                                                                      \
     94        CREATE_AND_SET_IMAGE(inImage,TYPE,VALUE1,NROWS,NCOLS);                                               \
     95        CREATE_AND_SET_IMAGE(outImage,TYPE,VALUE2,NROWS,NCOLS);                                              \
     96        printf("Input:\n");                                                                                  \
     97        PRINT_MATRIX(inImage,TYPE);                                                                          \
     98        PRINT_MATRIX(outImage,TYPE);                                                                         \
     99        outImage = (psImage*)psBinaryOp(outImage, inImage, #OP, outImage);                                   \
     100        printf("Output:\n");                                                                                 \
     101        PRINT_MATRIX(outImage,TYPE);                                                                         \
     102        psFree(inImage);                                                                                     \
     103        psFree(outImage);                                                                                    \
     104        CHECK_MEMORY;                                                                                        \
     105        printFooter(stdout, "psMatrixVectorArithmetic", "Test matrix-matrix psBinaryOp", true);              \
    43106    }
    44     psVec1 =(psVector*)psBinaryOp(psVec1, psVec1, "+", psVec2);
    45     for(int i = 0; i < 5; i++) {
    46         printf("%d\n", psVec1->data.S32[i]);
     107
     108    testBinaryOpMM(+,S32,10,10,3,2);
     109    testBinaryOpMM(+,F32,10.0,10.0,3,2);
     110    testBinaryOpMM(+,F64,10.0,10.0,3,2);
     111    testBinaryOpMM(+,C32,10.0+10.0i,10.0+10.0i,3,2);
     112    testBinaryOpMM(-,S32,20,10,3,2);
     113    testBinaryOpMM(-,F32,20.0,10.0,3,2);
     114    testBinaryOpMM(-,F64,20.0,10.0,3,2);
     115    testBinaryOpMM(*,C32,20.0+20.0i,10.0+10.0i,3,2);
     116    testBinaryOpMM(*,S32,20,10,3,2);
     117    testBinaryOpMM(*,F32,20.0,10.0,3,2);
     118    testBinaryOpMM(*,F64,20.0,10.0,3,2);
     119    testBinaryOpMM(*,C32,20.0+20.0i,10.0+10.0i,3,2);
     120    testBinaryOpMM(/,C32,20.0+20.0i,10.0+10.0i,3,2);
     121    testBinaryOpMM(/,S32,20,10,3,2);
     122    testBinaryOpMM(/,F32,20.0,10.0,3,2);
     123    testBinaryOpMM(/,F64,20.0,10.0,3,2);
     124    testBinaryOpMM(/,C32,20.0+20.0i,10.0+10.0i,3,2);
     125
     126    // Test Matrix-Vector binary operations
     127    #define testBinaryOpMV(OP,TYPE,VALUE1,VALUE2,NROWS,NCOLS)                                                \
     128    {                                                                                                        \
     129        printPositiveTestHeader(stdout, "psMatrixVectorArithmetic", "Test matrix-vector psBinaryOp");        \
     130        printf("Operation: %s\n", #OP);                                                                      \
     131        CREATE_AND_SET_IMAGE(outImage,TYPE,VALUE1,NROWS,NCOLS);                                              \
     132        CREATE_AND_SET_VECTOR(inVector,TYPE,VALUE2,NROWS);                                                   \
     133        printf("Input:\n");                                                                                  \
     134        PRINT_MATRIX(outImage,TYPE);                                                                         \
     135        PRINT_VECTOR(inVector,TYPE);                                                                         \
     136        outImage = (psImage*)psBinaryOp(outImage, outImage, #OP, inVector);                                  \
     137        printf("Output:\n");                                                                                 \
     138        PRINT_MATRIX(outImage,TYPE);                                                                         \
     139        psFree(inVector);                                                                                    \
     140        psFree(outImage);                                                                                    \
     141        CHECK_MEMORY;                                                                                        \
     142        printFooter(stdout, "psMatrixVectorArithmetic", "Test matrix-vector psBinaryOp", true);              \
    47143    }
    48144
    49     psImage *inImage = (psImage*)psImageAlloc(5, 5, PS_TYPE_F64);
    50     psImage *outImage = (psImage*)psImageAlloc(5, 5, PS_TYPE_F64);
    51     for(int i = 0; i < 5; i++) {
    52         for(int j = 0; j < 5; j++) {
    53             inImage->data.F64[i][j] = i*10;
    54             outImage->data.F64[i][j] = i*10;
    55         }
     145    testBinaryOpMV(+,S32,10,5,3,2);
     146    testBinaryOpMV(+,F32,10.0,5.0,3,2);
     147    testBinaryOpMV(+,F64,10.0,5.0,3,2);
     148    testBinaryOpMV(+,C32,10.0+10.0i,5.0+5.0i,3,2);
     149    testBinaryOpMV(-,S32,20,5,3,2);
     150    testBinaryOpMV(-,F32,20.0,5.0,3,2);
     151    testBinaryOpMV(-,F64,20.0,5.0,3,2);
     152    testBinaryOpMV(*,C32,20.0+20.0i,5.0+5.0i,3,2);
     153    testBinaryOpMV(*,S32,20,5,3,2);
     154    testBinaryOpMV(*,F32,20.0,5.0,3,2);
     155    testBinaryOpMV(*,F64,20.0,5.0,3,2);
     156    testBinaryOpMV(*,C32,20.0+20.0i,5.0+5.0i,3,2);
     157    testBinaryOpMV(/,C32,20.0+20.0i,5.0+5.0i,3,2);
     158    testBinaryOpMV(/,S32,20,5,3,2);
     159    testBinaryOpMV(/,F32,20.0,5.0,3,2);
     160    testBinaryOpMV(/,F64,20.0,5.0,3,2);
     161    testBinaryOpMV(/,C32,20.0+20.0i,5.0+5.0i,3,2);
     162
     163    // Test Matrix-Scalar binary operations
     164    #define testBinaryOpMS(OP,TYPE,VALUE1,VALUE2,NROWS,NCOLS)                                                \
     165    {                                                                                                        \
     166        printPositiveTestHeader(stdout, "psMatrixVectorArithmetic", "Test matrix-scalar psBinaryOp");        \
     167        printf("Operation: %s\n", #OP);                                                                      \
     168        CREATE_AND_SET_IMAGE(outImage,TYPE,VALUE1,NROWS,NCOLS);                                              \
     169        psScalar *inScalar = (psScalar*)psScalarAlloc(VALUE2,PS_TYPE_##TYPE);                                \
     170        printf("Input:\n");                                                                                  \
     171        PRINT_MATRIX(outImage,TYPE);                                                                         \
     172        PRINT_SCALAR(inScalar,TYPE);                                                                         \
     173        outImage = (psImage*)psBinaryOp(outImage, outImage, #OP, inScalar);                                  \
     174        printf("Output:\n");                                                                                 \
     175        PRINT_MATRIX(outImage,TYPE);                                                                         \
     176        psFree(inScalar);                                                                                    \
     177        psFree(outImage);                                                                                    \
     178        CHECK_MEMORY;                                                                                        \
     179        printFooter(stdout, "psMatrixVectorArithmetic", "Test matrix-scalar psBinaryOp", true);              \
    56180    }
    57     outImage =(psImage*)psBinaryOp(outImage, outImage, "+", inImage);
    58     PRINT_MATRIX(outImage);
    59 
    60 
    61     psImage *outImage2 = (psImage*)psImageAlloc(5, 5, PS_TYPE_F64);
    62     for(int i = 0; i < 5; i++) {
    63         for(int j = 0; j < 5; j++) {
    64             outImage2->data.F64[i][j] = i*10;
    65         }
    66     }
    67     outImage2 =(psImage*)psBinaryOp(outImage2, outImage, "+", psScalarAlloc(2, PS_TYPE_F64));
    68     PRINT_MATRIX(outImage);
    69 
    70 
    71     psVector *psVec3 = psVectorAlloc(4, PS_TYPE_F64);
    72     for(int i = 0; i < 4; i++) {
    73         psVec3->data.F64[i] = i;
    74         psVec3->n++;
    75     }
    76     psImage *inImage3 = (psImage*)psImageAlloc(3, 4, PS_TYPE_F64);
    77     psImage *outImage3 = (psImage*)psImageAlloc(3, 4, PS_TYPE_F64);
    78     for(int i = 0; i < 4; i++) {
    79         for(int j = 0; j < 3; j++) {
    80             inImage3->data.F64[i][j] = 10.0;
    81             outImage3->data.F64[i][j] = 0.0;
    82         }
    83     }
    84     outImage3 =(psImage*)psBinaryOp(outImage3, psVec3, "+", inImage3);
    85     PRINT_MATRIX(outImage3);
    86 
    87 
    88     psVector *psVec4 = psVectorAlloc(4, PS_TYPE_F64);
    89     psVec4->type.dimen = PS_DIMEN_TRANSV;
    90     for(int i = 0; i < 4; i++) {
    91         psVec4->data.F64[i] = i;
    92         psVec4->n++;
    93     }
    94     psImage *inImage4 = (psImage*)psImageAlloc(4, 3, PS_TYPE_F64);
    95     psImage *outImage4 = (psImage*)psImageAlloc(4, 3, PS_TYPE_F64);
    96     for(int i = 0; i < 3; i++) {
    97         for(int j = 0; j < 4; j++) {
    98             inImage4->data.F64[i][j] = 10.0;
    99             outImage4->data.F64[i][j] = 0.0;
    100         }
    101     }
    102     outImage4 =(psImage*)psBinaryOp(outImage4, inImage4, "+", psVec4);
    103     PRINT_MATRIX(outImage4);
     181
     182    testBinaryOpMS(+,S32,10,5,3,2);
     183    testBinaryOpMS(+,F32,10.0,5.0,3,2);
     184    testBinaryOpMS(+,F64,10.0,5.0,3,2);
     185    testBinaryOpMS(+,C32,10.0+10.0i,5.0+5.0i,3,2);
     186    testBinaryOpMS(-,S32,20,5,3,2);
     187    testBinaryOpMS(-,F32,20.0,5.0,3,2);
     188    testBinaryOpMS(-,F64,20.0,5.0,3,2);
     189    testBinaryOpMS(*,C32,20.0+20.0i,5.0+5.0i,3,2);
     190    testBinaryOpMS(*,S32,20,5,3,2);
     191    testBinaryOpMS(*,F32,20.0,5.0,3,2);
     192    testBinaryOpMS(*,F64,20.0,5.0,3,2);
     193    testBinaryOpMS(*,C32,20.0+20.0i,5.0+5.0i,3,2);
     194    testBinaryOpMS(/,C32,20.0+20.0i,5.0+5.0i,3,2);
     195    testBinaryOpMS(/,S32,20,5,3,2);
     196    testBinaryOpMS(/,F32,20.0,5.0,3,2);
     197    testBinaryOpMS(/,F64,20.0,5.0,3,2);
     198    testBinaryOpMS(/,C32,20.0+20.0i,5.0+5.0i,3,2);
    104199
    105200    return 0;
    106201}
     202
Note: See TracChangeset for help on using the changeset viewer.