You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

lapacke_dtz_nancheck.c 5.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*****************************************************************************
  2. Copyright (c) 2022, Intel Corp.
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright notice,
  7. this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. * Neither the name of Intel Corporation nor the names of its contributors
  12. may be used to endorse or promote products derived from this software
  13. without specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  15. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  18. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  19. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  20. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  21. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  22. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  23. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  24. THE POSSIBILITY OF SUCH DAMAGE.
  25. ******************************************************************************
  26. * Contents: Native C interface to LAPACK utility function
  27. * Author: Simon Märtens
  28. *****************************************************************************/
  29. #include "lapacke_utils.h"
  30. /*****************************************************************************
  31. Check a trapezoidal matrix for NaN entries. The shape of the trapezoidal
  32. matrix is determined by the arguments `direct` and `uplo`. `Direct` chooses
  33. the diagonal which shall be considered and `uplo` tells us whether we use the
  34. upper or lower part of the matrix with respect to the chosen diagonal.
  35. Diagonals 'F' (front / forward) and 'B' (back / backward):
  36. A = ( F ) A = ( F B )
  37. ( F ) ( F B )
  38. ( B F ) ( F B )
  39. ( B )
  40. ( B )
  41. direct = 'F', uplo = 'L':
  42. A = ( * ) A = ( * )
  43. ( * * ) ( * * )
  44. ( * * * ) ( * * * )
  45. ( * * * )
  46. ( * * * )
  47. direct = 'F', uplo = 'U':
  48. A = ( * * * ) A = ( * * * * * )
  49. ( * * ) ( * * * * )
  50. ( * ) ( * * * )
  51. ( )
  52. ( )
  53. direct = 'B', uplo = 'L':
  54. A = ( ) A = ( * * * )
  55. ( ) ( * * * * )
  56. ( * ) ( * * * * * )
  57. ( * * )
  58. ( * * * )
  59. direct = 'B', uplo = 'U':
  60. A = ( * * * ) A = ( * * * )
  61. ( * * * ) ( * * )
  62. ( * * * ) ( * )
  63. ( * * )
  64. ( * )
  65. *****************************************************************************/
  66. lapack_logical LAPACKE_dtz_nancheck( int matrix_layout, char direct, char uplo,
  67. char diag, lapack_int m, lapack_int n,
  68. const double *a, lapack_int lda )
  69. {
  70. lapack_logical colmaj, front, lower, unit;
  71. if( a == NULL ) return (lapack_logical) 0;
  72. colmaj = ( matrix_layout == LAPACK_COL_MAJOR );
  73. front = LAPACKE_lsame( direct, 'f' );
  74. lower = LAPACKE_lsame( uplo, 'l' );
  75. unit = LAPACKE_lsame( diag, 'u' );
  76. if( ( !colmaj && ( matrix_layout != LAPACK_ROW_MAJOR ) ) ||
  77. ( !front && !LAPACKE_lsame( direct, 'b' ) ) ||
  78. ( !lower && !LAPACKE_lsame( uplo, 'u' ) ) ||
  79. ( !unit && !LAPACKE_lsame( diag, 'n' ) ) ) {
  80. /* Just exit if any of input parameters are wrong */
  81. return (lapack_logical) 0;
  82. }
  83. /* Initial offsets and sizes of triangular and rectangular parts */
  84. lapack_int tri_offset = 0;
  85. lapack_int tri_n = MIN(m,n);
  86. lapack_int rect_offset = -1;
  87. lapack_int rect_m = ( m > n ) ? m - n : m;
  88. lapack_int rect_n = ( n > m ) ? n - m : n;
  89. /* Fix offsets depending on the shape of the matrix */
  90. if( front ) {
  91. if( lower && m > n ) {
  92. rect_offset = tri_n * ( !colmaj ? lda : 1 );
  93. } else if( !lower && n > m ) {
  94. rect_offset = tri_n * ( colmaj ? lda : 1 );
  95. }
  96. } else {
  97. if( m > n ) {
  98. tri_offset = rect_m * ( !colmaj ? lda : 1 );
  99. if( !lower ) {
  100. rect_offset = 0;
  101. }
  102. } else if( n > m ) {
  103. tri_offset = rect_n * ( colmaj ? lda : 1 );
  104. if( lower ) {
  105. rect_offset = 0;
  106. }
  107. }
  108. }
  109. /* Check rectangular part */
  110. if( rect_offset >= 0 ) {
  111. if( LAPACKE_dge_nancheck( matrix_layout, rect_m, rect_n,
  112. &a[rect_offset], lda ) ) {
  113. return (lapack_logical) 1;
  114. }
  115. }
  116. /* Check triangular part */
  117. return LAPACKE_dtr_nancheck( matrix_layout, uplo, diag, tri_n,
  118. &a[tri_offset], lda );
  119. }