lapacke_ztf_nancheck.c
Go to the documentation of this file.
00001 /*****************************************************************************
00002   Copyright (c) 2010, Intel Corp.
00003   All rights reserved.
00004 
00005   Redistribution and use in source and binary forms, with or without
00006   modification, are permitted provided that the following conditions are met:
00007 
00008     * Redistributions of source code must retain the above copyright notice,
00009       this list of conditions and the following disclaimer.
00010     * Redistributions in binary form must reproduce the above copyright
00011       notice, this list of conditions and the following disclaimer in the
00012       documentation and/or other materials provided with the distribution.
00013     * Neither the name of Intel Corporation nor the names of its contributors
00014       may be used to endorse or promote products derived from this software
00015       without specific prior written permission.
00016 
00017   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
00027   THE POSSIBILITY OF SUCH DAMAGE.
00028 ******************************************************************************
00029 * Contents: Native C interface to LAPACK utility function
00030 * Author: Intel Corporation
00031 * Created in February, 2010
00032 *****************************************************************************/
00033 #include "lapacke_utils.h"
00034 
00035 /* Check a matrix for NaN entries. */
00036 
00037 lapack_logical LAPACKE_ztf_nancheck( int matrix_order, char transr,
00038                                       char uplo, char diag,
00039                                       lapack_int n,
00040                                       const lapack_complex_double *a )
00041 {
00042     lapack_int len;
00043     lapack_logical rowmaj, ntr, lower, unit;
00044     lapack_int n1, n2, k;
00045 
00046     if( a == NULL ) return (lapack_logical) 0;
00047 
00048     rowmaj = (matrix_order == LAPACK_ROW_MAJOR);
00049     ntr    = LAPACKE_lsame( transr, 'n' );
00050     lower  = LAPACKE_lsame( uplo,   'l' );
00051     unit   = LAPACKE_lsame( diag,   'u' );
00052 
00053     if( ( !rowmaj && ( matrix_order != LAPACK_COL_MAJOR ) ) ||
00054         ( !ntr    && !LAPACKE_lsame( transr, 't' )
00055                   && !LAPACKE_lsame( transr, 'c' ) ) ||
00056         ( !lower  && !LAPACKE_lsame( uplo,   'u' ) ) ||
00057         ( !unit   && !LAPACKE_lsame( diag,   'n' ) ) ) {
00058         /* Just exit if any of input parameters are wrong */
00059         return (lapack_logical) 0;
00060     }
00061 
00062     if( unit ) {
00063         /* Unit case, diagonal should be excluded from the check for NaN.
00064          * Decoding RFP and checking both triangulars and rectangular
00065          * for NaNs.
00066          */
00067         if( lower ) {
00068             n2 = n / 2;
00069             n1 = n - n2;
00070         } else {
00071             n1 = n / 2;
00072             n2 = n - n1;
00073         }
00074         if( n % 2 == 1 ) {
00075             /* N is odd */
00076             if( ( rowmaj || ntr ) && !( rowmaj && ntr ) ) {
00077                 /* N is odd and ( TRANSR = 'N' .XOR. ROWMAJOR) */
00078                 if( lower ) {
00079                     return LAPACKE_ztr_nancheck( LAPACK_ROW_MAJOR, 'l', 'u',
00080                                                  n1, &a[0], n )
00081                         || LAPACKE_zge_nancheck( LAPACK_ROW_MAJOR, n2, n1,
00082                                                  &a[n1], n )
00083                         || LAPACKE_ztr_nancheck( LAPACK_ROW_MAJOR, 'u', 'u',
00084                                                  n2, &a[n], n );
00085                 } else {
00086                     return LAPACKE_ztr_nancheck( LAPACK_ROW_MAJOR, 'l', 'u',
00087                                                  n1, &a[n2], n )
00088                         || LAPACKE_zge_nancheck( LAPACK_ROW_MAJOR, n1, n2,
00089                                                  &a[0], n )
00090                         || LAPACKE_ztr_nancheck( LAPACK_ROW_MAJOR, 'u', 'u',
00091                                                  n2, &a[n1], n );
00092                 }
00093             } else {
00094                 /* N is odd and
00095                  * ( ( TRANSR = 'C' || TRANSR = 'T' ) .XOR. COLMAJOR )
00096                  */
00097                 if( lower ) {
00098                     return LAPACKE_ztr_nancheck( LAPACK_ROW_MAJOR, 'u', 'u',
00099                                                  n1, &a[0], n1 )
00100                         || LAPACKE_zge_nancheck( LAPACK_ROW_MAJOR, n1, n2,
00101                                                  &a[1], n1 )
00102                         || LAPACKE_ztr_nancheck( LAPACK_ROW_MAJOR, 'l', 'u',
00103                                                  n2, &a[1], n1 );
00104                 } else {
00105                     return LAPACKE_ztr_nancheck( LAPACK_ROW_MAJOR, 'u', 'u',
00106                                                  n1, &a[(size_t)n2*n2], n2 )
00107                         || LAPACKE_zge_nancheck( LAPACK_ROW_MAJOR, n2, n1,
00108                                                  &a[0], n2 )
00109                         || LAPACKE_ztr_nancheck( LAPACK_ROW_MAJOR, 'l', 'u',
00110                                                  n2, &a[(size_t)n1*n2], n2 );
00111                 }
00112             }
00113         } else {
00114             /* N is even */
00115             k = n / 2;
00116             if( ( rowmaj || ntr ) && !( rowmaj && ntr ) ) {
00117                 /* N is even and ( TRANSR = 'N' .XOR. ROWMAJOR) */
00118                 if( lower ) {
00119                     return LAPACKE_ztr_nancheck( LAPACK_ROW_MAJOR, 'l', 'u',
00120                                                  k, &a[1], n+1 )
00121                         || LAPACKE_zge_nancheck( LAPACK_ROW_MAJOR, k, k,
00122                                                  &a[k+1], n+1 )
00123                         || LAPACKE_ztr_nancheck( LAPACK_ROW_MAJOR, 'u', 'u',
00124                                                  k, &a[0], n+1 );
00125                 } else {
00126                     return LAPACKE_ztr_nancheck( LAPACK_ROW_MAJOR, 'l', 'u',
00127                                                  k, &a[k+1], n+1 )
00128                         || LAPACKE_zge_nancheck( LAPACK_ROW_MAJOR, k, k,
00129                                                  &a[0], n+1 )
00130                         || LAPACKE_ztr_nancheck( LAPACK_ROW_MAJOR, 'u', 'u',
00131                                                  k, &a[k], n+1 );
00132                 }
00133             } else {
00134                 /* N is even and
00135                    ( ( TRANSR = 'C' || TRANSR = 'T' ) .XOR. COLMAJOR ) */
00136                 if( lower ) {
00137                     return LAPACKE_ztr_nancheck( LAPACK_ROW_MAJOR, 'u', 'u',
00138                                                  k, &a[k], k )
00139                         || LAPACKE_zge_nancheck( LAPACK_ROW_MAJOR, k, k,
00140                                                  &a[(size_t)k*(k+1)], k )
00141                         || LAPACKE_ztr_nancheck( LAPACK_ROW_MAJOR, 'l', 'u',
00142                                                  k, &a[0], k );
00143                 } else {
00144                     return LAPACKE_ztr_nancheck( LAPACK_ROW_MAJOR, 'u', 'u',
00145                                                  k, &a[(size_t)k*(k+1)], k )
00146                         || LAPACKE_zge_nancheck( LAPACK_ROW_MAJOR, k, k,
00147                                                  &a[0], k )
00148                         || LAPACKE_ztr_nancheck( LAPACK_ROW_MAJOR, 'l', 'u',
00149                                                  k, &a[(size_t)k*k], k );
00150                 }
00151             }
00152         }
00153     } else {
00154         /* Non-unit case - just check whole array for NaNs. */
00155         len = n*(n+1)/2;
00156         return LAPACKE_zge_nancheck( LAPACK_COL_MAJOR, len, 1, a, len );
00157     }
00158 }


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:56