lapacke_dtf_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_dtf_nancheck( int matrix_order, char transr,
00038                                       char uplo, char diag,
00039                                       lapack_int n,
00040                                       const 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_dtr_nancheck( LAPACK_ROW_MAJOR, 'l', 'u',
00080                                                  n1, &a[0], n )
00081                         || LAPACKE_dge_nancheck( LAPACK_ROW_MAJOR, n2, n1,
00082                                                  &a[n1], n )
00083                         || LAPACKE_dtr_nancheck( LAPACK_ROW_MAJOR, 'u', 'u',
00084                                                  n2, &a[n], n );
00085                 } else {
00086                     return LAPACKE_dtr_nancheck( LAPACK_ROW_MAJOR, 'l', 'u',
00087                                                  n1, &a[n2], n )
00088                         || LAPACKE_dge_nancheck( LAPACK_ROW_MAJOR, n1, n2,
00089                                                  &a[0], n )
00090                         || LAPACKE_dtr_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                 if( lower ) {
00097                     return LAPACKE_dtr_nancheck( LAPACK_ROW_MAJOR, 'u', 'u',
00098                                                  n1, &a[0], n1 )
00099                         || LAPACKE_dge_nancheck( LAPACK_ROW_MAJOR, n1, n2,
00100                                                  &a[1], n1 )
00101                         || LAPACKE_dtr_nancheck( LAPACK_ROW_MAJOR, 'l', 'u',
00102                                                  n2, &a[1], n1 );
00103                 } else {
00104                     return LAPACKE_dtr_nancheck( LAPACK_ROW_MAJOR, 'u', 'u',
00105                                                  n1, &a[(size_t)n2*n2], n2 )
00106                         || LAPACKE_dge_nancheck( LAPACK_ROW_MAJOR, n2, n1,
00107                                                  &a[0], n2 )
00108                         || LAPACKE_dtr_nancheck( LAPACK_ROW_MAJOR, 'l', 'u',
00109                                                  n2, &a[(size_t)n1*n2], n2 );
00110                 }
00111             }
00112         } else {
00113             /* N is even */
00114             k = n / 2;
00115             if( ( rowmaj || ntr ) && !( rowmaj && ntr ) ) {
00116                 /* N is even and ( TRANSR = 'N' .XOR. ROWMAJOR) */
00117                 if( lower ) {
00118                     return LAPACKE_dtr_nancheck( LAPACK_ROW_MAJOR, 'l', 'u',
00119                                                  k, &a[1], n+1 )
00120                         || LAPACKE_dge_nancheck( LAPACK_ROW_MAJOR, k, k,
00121                                                  &a[k+1], n+1 )
00122                         || LAPACKE_dtr_nancheck( LAPACK_ROW_MAJOR, 'u', 'u',
00123                                                  k, &a[0], n+1 );
00124                 } else {
00125                     return LAPACKE_dtr_nancheck( LAPACK_ROW_MAJOR, 'l', 'u',
00126                                                  k, &a[k+1], n+1 )
00127                         || LAPACKE_dge_nancheck( LAPACK_ROW_MAJOR, k, k,
00128                                                  &a[0], n+1 )
00129                         || LAPACKE_dtr_nancheck( LAPACK_ROW_MAJOR, 'u', 'u',
00130                                                  k, &a[k], n+1 );
00131                 }
00132             } else {
00133                 /* N is even and
00134                    ( ( TRANSR = 'C' || TRANSR = 'T' ) .XOR. COLMAJOR ) */
00135                 if( lower ) {
00136                     return LAPACKE_dtr_nancheck( LAPACK_ROW_MAJOR, 'u', 'u',
00137                                                  k, &a[k], k )
00138                         || LAPACKE_dge_nancheck( LAPACK_ROW_MAJOR, k, k,
00139                                                  &a[(size_t)k*(k+1)], k )
00140                         || LAPACKE_dtr_nancheck( LAPACK_ROW_MAJOR, 'l', 'u',
00141                                                  k, &a[0], k );
00142                 } else {
00143                     return LAPACKE_dtr_nancheck( LAPACK_ROW_MAJOR, 'u', 'u',
00144                                                  k, &a[(size_t)k*(k+1)], k )
00145                         || LAPACKE_dge_nancheck( LAPACK_ROW_MAJOR, k, k,
00146                                                  &a[0], k )
00147                         || LAPACKE_dtr_nancheck( LAPACK_ROW_MAJOR, 'l', 'u',
00148                                                  k, &a[(size_t)k*k], k );
00149                 }
00150             }
00151         }
00152     } else {
00153         /* Non-unit case - just check whole array for NaNs. */
00154         len = n*(n+1)/2;
00155         return LAPACKE_dge_nancheck( LAPACK_COL_MAJOR, len, 1, a, len );
00156     }
00157 }


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