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_ztz_trans.c 6.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. Converts input triangular matrix from row-major(C) to column-major(Fortran)
  32. layout or vice versa. The shape of the trapezoidal matrix is determined by
  33. the arguments `direct` and `uplo`. `Direct` chooses the diagonal which shall
  34. be considered and `uplo` tells us whether we use the upper or lower part of
  35. the matrix with respect to the chosen diagonal.
  36. Diagonals 'F' (front / forward) and 'B' (back / backward):
  37. A = ( F ) A = ( F B )
  38. ( F ) ( F B )
  39. ( B F ) ( F B )
  40. ( B )
  41. ( B )
  42. direct = 'F', uplo = 'L':
  43. A = ( * ) A = ( * )
  44. ( * * ) ( * * )
  45. ( * * * ) ( * * * )
  46. ( * * * )
  47. ( * * * )
  48. direct = 'F', uplo = 'U':
  49. A = ( * * * ) A = ( * * * * * )
  50. ( * * ) ( * * * * )
  51. ( * ) ( * * * )
  52. ( )
  53. ( )
  54. direct = 'B', uplo = 'L':
  55. A = ( ) A = ( * * * )
  56. ( ) ( * * * * )
  57. ( * ) ( * * * * * )
  58. ( * * )
  59. ( * * * )
  60. direct = 'B', uplo = 'U':
  61. A = ( * * * ) A = ( * * * )
  62. ( * * * ) ( * * )
  63. ( * * * ) ( * )
  64. ( * * )
  65. ( * )
  66. *****************************************************************************/
  67. void LAPACKE_ztz_trans( int matrix_layout, char direct, char uplo,
  68. char diag, lapack_int m, lapack_int n,
  69. const lapack_complex_double *in, lapack_int ldin,
  70. lapack_complex_double *out, lapack_int ldout )
  71. {
  72. lapack_logical colmaj, front, lower, unit;
  73. if( in == NULL || out == NULL ) return ;
  74. colmaj = ( matrix_layout == LAPACK_COL_MAJOR );
  75. front = LAPACKE_lsame( direct, 'f' );
  76. lower = LAPACKE_lsame( uplo, 'l' );
  77. unit = LAPACKE_lsame( diag, 'u' );
  78. if( ( !colmaj && ( matrix_layout != LAPACK_ROW_MAJOR ) ) ||
  79. ( !front && !LAPACKE_lsame( direct, 'b' ) ) ||
  80. ( !lower && !LAPACKE_lsame( uplo, 'u' ) ) ||
  81. ( !unit && !LAPACKE_lsame( diag, 'n' ) ) ) {
  82. /* Just exit if any of input parameters are wrong */
  83. return;
  84. }
  85. /* Initial offsets and sizes of triangular and rectangular parts */
  86. lapack_int tri_in_offset = 0;
  87. lapack_int tri_out_offset = 0;
  88. lapack_int tri_n = MIN(m,n);
  89. lapack_int rect_in_offset = -1;
  90. lapack_int rect_out_offset = -1;
  91. lapack_int rect_m = ( m > n ) ? m - n : m;
  92. lapack_int rect_n = ( n > m ) ? n - m : n;
  93. /* Fix offsets depending on the shape of the matrix */
  94. if( front ) {
  95. if( lower && m > n ) {
  96. rect_in_offset = tri_n * ( !colmaj ? ldin : 1 );
  97. rect_out_offset = tri_n * ( colmaj ? ldout : 1 );
  98. } else if( !lower && n > m ) {
  99. rect_in_offset = tri_n * ( colmaj ? ldin : 1 );
  100. rect_out_offset = tri_n * ( !colmaj ? ldout : 1 );
  101. }
  102. } else {
  103. if( m > n ) {
  104. tri_in_offset = rect_m * ( !colmaj ? ldin : 1 );
  105. tri_out_offset = rect_m * ( colmaj ? ldout : 1 );
  106. if( !lower ) {
  107. rect_in_offset = 0;
  108. rect_out_offset = 0;
  109. }
  110. } else if( n > m ) {
  111. tri_in_offset = rect_n * ( colmaj ? ldin : 1 );
  112. tri_out_offset = rect_n * ( !colmaj ? ldout : 1 );
  113. if( lower ) {
  114. rect_in_offset = 0;
  115. rect_out_offset = 0;
  116. }
  117. }
  118. }
  119. /* Copy & transpose rectangular part */
  120. if( rect_in_offset >= 0 && rect_out_offset >= 0 ) {
  121. LAPACKE_zge_trans( matrix_layout, rect_m, rect_n,
  122. &in[rect_in_offset], ldin,
  123. &out[rect_out_offset], ldout );
  124. }
  125. /* Copy & transpose triangular part */
  126. LAPACKE_ztr_trans( matrix_layout, uplo, diag, tri_n,
  127. &in[tri_in_offset], ldin,
  128. &out[tri_out_offset], ldout );
  129. }