LAPACK 3.11.0
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
lapacke_dtf_nancheck.c
Go to the documentation of this file.
1/*****************************************************************************
2 Copyright (c) 2014, Intel Corp.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
8 * Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 * Neither the name of Intel Corporation nor the names of its contributors
14 may be used to endorse or promote products derived from this software
15 without specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 THE POSSIBILITY OF SUCH DAMAGE.
28******************************************************************************
29* Contents: Native C interface to LAPACK utility function
30* Author: Intel Corporation
31*****************************************************************************/
32#include "lapacke_utils.h"
33
34/* Check a matrix for NaN entries. */
35
36lapack_logical LAPACKE_dtf_nancheck( int matrix_layout, char transr,
37 char uplo, char diag,
38 lapack_int n,
39 const double *a )
40{
41 lapack_int len;
42 lapack_logical rowmaj, ntr, lower, unit;
43 lapack_int n1, n2, k;
44
45 if( a == NULL ) return (lapack_logical) 0;
46
47 rowmaj = (matrix_layout == LAPACK_ROW_MAJOR);
48 ntr = LAPACKE_lsame( transr, 'n' );
49 lower = LAPACKE_lsame( uplo, 'l' );
50 unit = LAPACKE_lsame( diag, 'u' );
51
52 if( ( !rowmaj && ( matrix_layout != LAPACK_COL_MAJOR ) ) ||
53 ( !ntr && !LAPACKE_lsame( transr, 't' )
54 && !LAPACKE_lsame( transr, 'c' ) ) ||
55 ( !lower && !LAPACKE_lsame( uplo, 'u' ) ) ||
56 ( !unit && !LAPACKE_lsame( diag, 'n' ) ) ) {
57 /* Just exit if any of input parameters are wrong */
58 return (lapack_logical) 0;
59 }
60
61 if( unit ) {
62 /* Unit case, diagonal should be excluded from the check for NaN.
63 * Decoding RFP and checking both triangulars and rectangular
64 * for NaNs.
65 */
66 if( lower ) {
67 n2 = n / 2;
68 n1 = n - n2;
69 } else {
70 n1 = n / 2;
71 n2 = n - n1;
72 }
73 if( n % 2 == 1 ) {
74 /* N is odd */
75 if( ( rowmaj || ntr ) && !( rowmaj && ntr ) ) {
76 /* N is odd and ( TRANSR = 'N' .XOR. ROWMAJOR) */
77 if( lower ) {
78 return LAPACKE_dtr_nancheck( LAPACK_ROW_MAJOR, 'l', 'u',
79 n1, &a[0], n )
81 &a[n1], n )
83 n2, &a[n], n );
84 } else {
85 return LAPACKE_dtr_nancheck( LAPACK_ROW_MAJOR, 'l', 'u',
86 n1, &a[n2], n )
88 &a[0], n )
90 n2, &a[n1], n );
91 }
92 } else {
93 /* N is odd and
94 ( ( TRANSR = 'C' || TRANSR = 'T' ) .XOR. COLMAJOR ) */
95 if( lower ) {
96 return LAPACKE_dtr_nancheck( LAPACK_ROW_MAJOR, 'u', 'u',
97 n1, &a[0], n1 )
99 &a[1], n1 )
101 n2, &a[1], n1 );
102 } else {
103 return LAPACKE_dtr_nancheck( LAPACK_ROW_MAJOR, 'u', 'u',
104 n1, &a[(size_t)n2*n2], n2 )
106 &a[0], n2 )
108 n2, &a[(size_t)n1*n2], n2 );
109 }
110 }
111 } else {
112 /* N is even */
113 k = n / 2;
114 if( ( rowmaj || ntr ) && !( rowmaj && ntr ) ) {
115 /* N is even and ( TRANSR = 'N' .XOR. ROWMAJOR) */
116 if( lower ) {
117 return LAPACKE_dtr_nancheck( LAPACK_ROW_MAJOR, 'l', 'u',
118 k, &a[1], n+1 )
120 &a[k+1], n+1 )
122 k, &a[0], n+1 );
123 } else {
124 return LAPACKE_dtr_nancheck( LAPACK_ROW_MAJOR, 'l', 'u',
125 k, &a[k+1], n+1 )
127 &a[0], n+1 )
129 k, &a[k], n+1 );
130 }
131 } else {
132 /* N is even and
133 ( ( TRANSR = 'C' || TRANSR = 'T' ) .XOR. COLMAJOR ) */
134 if( lower ) {
135 return LAPACKE_dtr_nancheck( LAPACK_ROW_MAJOR, 'u', 'u',
136 k, &a[k], k )
138 &a[(size_t)k*(k+1)], k )
140 k, &a[0], k );
141 } else {
142 return LAPACKE_dtr_nancheck( LAPACK_ROW_MAJOR, 'u', 'u',
143 k, &a[(size_t)k*(k+1)], k )
145 &a[0], k )
147 k, &a[(size_t)k*k], k );
148 }
149 }
150 }
151 } else {
152 /* Non-unit case - just check whole array for NaNs. */
153 len = n*(n+1)/2;
154 return LAPACKE_dge_nancheck( LAPACK_COL_MAJOR, len, 1, a, len );
155 }
156}
#define lapack_int
Definition: lapack.h:87
#define lapack_logical
Definition: lapack.h:103
#define LAPACK_COL_MAJOR
Definition: lapacke.h:53
#define LAPACK_ROW_MAJOR
Definition: lapacke.h:52
lapack_logical LAPACKE_dtf_nancheck(int matrix_layout, char transr, char uplo, char diag, lapack_int n, const double *a)
lapack_logical LAPACKE_lsame(char ca, char cb)
Definition: lapacke_lsame.c:35
lapack_logical LAPACKE_dtr_nancheck(int matrix_layout, char uplo, char diag, lapack_int n, const double *a, lapack_int lda)
lapack_logical LAPACKE_dge_nancheck(int matrix_layout, lapack_int m, lapack_int n, const double *a, lapack_int lda)