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