testing_zlange.c 8.98 KB
Newer Older
1 2 3 4 5 6
/**
 *
 * @copyright (c) 2009-2014 The University of Tennessee and The University
 *                          of Tennessee Research Foundation.
 *                          All rights reserved.
 * @copyright (c) 2012-2014 Inria. All rights reserved.
7
 * @copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
 *
 **/

/**
 *
 * @file testing_zlange.c
 *
 *  MORSE testing routines
 *  MORSE is a software package provided by Inria Bordeaux - Sud-Ouest, LaBRI,
 *  University of Bordeaux, Bordeaux INP
 *
 * @version 2.6.0
 * @comment This file has been automatically generated
 *          from Plasma 2.6.0 for MORSE 1.0.0
 * @author Emmanuel Agullo
 * @author Mathieu Faverge
 * @date 2010-11-15
 * @precisions normal z -> c d s
 *
 **/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

#include <morse.h>
34 35 36
#include <coreblas/cblas.h>
#include <coreblas/lapacke.h>
#include <coreblas.h>
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#include "testing_zauxiliary.h"

#undef REAL
#define COMPLEX

int testing_zlange(int argc, char **argv)
{
    int hres = 0;
    /* Check for number of arguments*/
    if ( argc < 3) {
        USAGE("LANGE", "M N LDA",
              "   - M      : number of rows of matrices A and C\n"
              "   - N      : number of columns of matrices B and C\n"
              "   - LDA    : leading dimension of matrix A\n");
        return -1;
    }
    int M = atoi(argv[0]);
    int N = atoi(argv[1]);
    int LDA = atoi(argv[2]);
    int LDAxN = LDA*N;
    int n, u;
    double eps;

    /* Allocate Data */
    MORSE_Complex64_t *A    = (MORSE_Complex64_t *)malloc(LDAxN*sizeof(MORSE_Complex64_t));
    double            *work = (double*) malloc(max(M,N)*sizeof(double));
Mathieu Faverge's avatar
Mathieu Faverge committed
63
    double normmorse, normlapack, result;
64 65 66 67

    eps = LAPACKE_dlamch_work('e');

    printf("\n");
68
    printf("------ TESTS FOR CHAMELEON ZLANGE ROUTINE -------  \n");
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
    printf("            Size of the Matrix %d by %d\n", M, N);
    printf("\n");
    printf(" The matrix A is randomly generated for each test.\n");
    printf("============\n");
    printf(" The relative machine precision (eps) is to be %e \n",eps);
    printf(" Computational tests pass if scaled residuals are less than 10.\n");

    /*----------------------------------------------------------
     *  TESTING ZLANGE
     */

    /* Initialize A, B, C */
    MORSE_zplrnt( M, N, A, LDA, 3436 );

    /* MORSE ZLANGE */
    for(n=0; n<4; n++) {
        normmorse  = MORSE_zlange(norm[n], M, N, A, LDA);
86
        normlapack = LAPACKE_zlange_work(LAPACK_COL_MAJOR, morse_lapack_const(norm[n]), M, N, A, LDA, work);
87
        printf("LAPACK %e, CHAMELEON %e\n", normlapack, normmorse);
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
        result = fabs(normmorse - normlapack) / (normlapack * eps);

        switch(norm[n]) {
        case MorseMaxNorm:
            /* result should be perfectly equal */
            break;
        case MorseInfNorm:
            /* Sum order on the line can differ */
            result = result / (double)N;
            break;
        case MorseOneNorm:
            /* Sum order on the column can differ */
            result = result / (double)M;
            break;
        case MorseFrobeniusNorm:
            /* Sum order on every element can differ */
            result = result / ((double)M * (double)N);
            break;
        }

        printf("***************************************************\n");
        if ( result < 1. ) {
            printf(" ---- TESTING ZLANGE (%s)............... PASSED !\n", normstr[n]);
        }
        else {
            printf(" - TESTING ZLANGE (%s)... FAILED !\n", normstr[n]);    hres++;
        }
        printf("***************************************************\n");

    }

    #ifdef COMPLEX
        /* MORSE ZLANTR */
        for(n=1; n<3; n++) {
            for(u=0; u<2; u++) {
                int d;
                for(d=0; d<2; d++) {
                    normmorse = MORSE_zlantr(norm[n], uplo[u], diag[d], M, N, A, LDA);
126 127
                    normlapack = LAPACKE_zlantr_work(LAPACK_COL_MAJOR, morse_lapack_const(norm[n]), morse_lapack_const(uplo[u]),
                                                     morse_lapack_const(diag[d]), M, N, A, LDA, work);
128
                    printf("LAPACK %e, CHAMELEON %e\n", normlapack, normmorse);
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167

                    result = fabs(normmorse - normlapack) / (normlapack * eps);
                    switch(norm[n]) {
                    case MorseMaxNorm:
                        /* result should be perfectly equal */
                        break;
                    case MorseInfNorm:
                        /* Sum order on the line can differ */
                        result = result / (double)N;
                        break;
                    case MorseOneNorm:
                        /* Sum order on the column can differ */
                        result = result / (double)M;
                        break;
                    case MorseFrobeniusNorm:
                        /* Sum oreder on every element can differ */
                        result = result / ((double)M * (double)N);
                        break;
                    }

                    printf("***************************************************\n");
                    if ( result < 1. ) {
                        printf(" ---- TESTING ZLANTR (%s, %s, %s)......... PASSED !\n",
                               normstr[n], uplostr[u], diagstr[d]);
                    }
                    else {
                        printf(" - TESTING ZLANTR (%s, %s, %s)... FAILED !\n",
                               normstr[n], uplostr[u], diagstr[d]);
                    }
                    printf("***************************************************\n");
                }
            }
        }
    #endif

    /* MORSE ZLANSY */
    for(n=0; n<4; n++) {
        for(u=0; u<2; u++) {
            normmorse = MORSE_zlansy(norm[n], uplo[u], min(M,N), A, LDA);
168
            normlapack = LAPACKE_zlansy_work(LAPACK_COL_MAJOR, morse_lapack_const(norm[n]), morse_lapack_const(uplo[u]), min(M,N), A, LDA, work);
169
            printf("LAPACK %e, CHAMELEON %e\n", normlapack, normmorse);
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212

            result = fabs(normmorse - normlapack) / (normlapack * eps);
            switch(norm[n]) {
            case MorseMaxNorm:
                /* result should be perfectly equal */
                break;
            case MorseInfNorm:
                /* Sum order on the line can differ */
                result = result / (double)N;
                break;
            case MorseOneNorm:
                /* Sum order on the column can differ */
                result = result / (double)M;
                break;
            case MorseFrobeniusNorm:
                /* Sum oreder on every element can differ */
                result = result / ((double)M * (double)N);
                break;
            }

            printf("***************************************************\n");
            if ( result < 1. ) {
                printf(" ---- TESTING ZLANSY (%s, %s)......... PASSED !\n", normstr[n], uplostr[u]);
            }
            else {
                printf(" - TESTING ZLANSY (%s, %s)... FAILED !\n", normstr[n], uplostr[u]);
            }
            printf("***************************************************\n");
        }
    }

    #ifdef COMPLEX
        /* MORSE ZLANHE */
        {
          int j;
          for (j=0; j<min(M,N); j++) {
            A[j*LDA+j] -= I*cimag(A[j*LDA+j]);
          }
        }

        for(n=0; n<4; n++) {
            for(u=0; u<2; u++) {
                normmorse = MORSE_zlanhe(norm[n], uplo[u], min(M,N), A, LDA);
213
                normlapack = LAPACKE_zlanhe_work(LAPACK_COL_MAJOR, morse_lapack_const(norm[n]), morse_lapack_const(uplo[u]), min(M,N), A, LDA, work);
214
                printf("LAPACK %e, CHAMELEON %e\n", normlapack, normmorse);
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248

                result = fabs(normmorse - normlapack) / (normlapack * eps);
                switch(norm[n]) {
                case MorseMaxNorm:
                    /* result should be perfectly equal */
                    break;
                case MorseInfNorm:
                    /* Sum order on the line can differ */
                    result = result / (double)N;
                    break;
                case MorseOneNorm:
                    /* Sum order on the column can differ */
                    result = result / (double)M;
                    break;
                case MorseFrobeniusNorm:
                    /* Sum oreder on every element can differ */
                    result = result / ((double)M * (double)N);
                    break;
                }

                printf("***************************************************\n");
                if ( result < 1. ) {
                    printf(" ---- TESTING ZLANHE (%s, %s)......... PASSED !\n", normstr[n], uplostr[u]);
                }
                else {
                    printf(" - TESTING ZLANHE (%s, %s)... FAILED !\n", normstr[n], uplostr[u]);
                }
                printf("***************************************************\n");
            }
        }
    #endif

    free(A);
    free(work);
249
    return 0 /*hres*/;
250
}