lapacke_dsyevr_work.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 middle-level C interface to LAPACK function dsyevr
00030 * Author: Intel Corporation
00031 * Generated October, 2010
00032 *****************************************************************************/
00033 
00034 #include "lapacke.h"
00035 #include "lapacke_utils.h"
00036 
00037 lapack_int LAPACKE_dsyevr_work( int matrix_order, char jobz, char range,
00038                                 char uplo, lapack_int n, double* a,
00039                                 lapack_int lda, double vl, double vu,
00040                                 lapack_int il, lapack_int iu, double abstol,
00041                                 lapack_int* m, double* w, double* z,
00042                                 lapack_int ldz, lapack_int* isuppz,
00043                                 double* work, lapack_int lwork,
00044                                 lapack_int* iwork, lapack_int liwork )
00045 {
00046     lapack_int info = 0;
00047     if( matrix_order == LAPACK_COL_MAJOR ) {
00048         /* Call LAPACK function and adjust info */
00049         LAPACK_dsyevr( &jobz, &range, &uplo, &n, a, &lda, &vl, &vu, &il, &iu,
00050                        &abstol, m, w, z, &ldz, isuppz, work, &lwork, iwork,
00051                        &liwork, &info );
00052         if( info < 0 ) {
00053             info = info - 1;
00054         }
00055     } else if( matrix_order == LAPACK_ROW_MAJOR ) {
00056         lapack_int ncols_z = ( LAPACKE_lsame( range, 'a' ) ||
00057                              LAPACKE_lsame( range, 'v' ) ) ? n :
00058                              ( LAPACKE_lsame( range, 'i' ) ? (iu-il+1) : 1);
00059         lapack_int lda_t = MAX(1,n);
00060         lapack_int ldz_t = MAX(1,n);
00061         double* a_t = NULL;
00062         double* z_t = NULL;
00063         /* Check leading dimension(s) */
00064         if( lda < n ) {
00065             info = -7;
00066             LAPACKE_xerbla( "LAPACKE_dsyevr_work", info );
00067             return info;
00068         }
00069         if( ldz < ncols_z ) {
00070             info = -16;
00071             LAPACKE_xerbla( "LAPACKE_dsyevr_work", info );
00072             return info;
00073         }
00074         /* Query optimal working array(s) size if requested */
00075         if( liwork == -1 || lwork == -1 ) {
00076             LAPACK_dsyevr( &jobz, &range, &uplo, &n, a, &lda_t, &vl, &vu, &il,
00077                            &iu, &abstol, m, w, z, &ldz_t, isuppz, work, &lwork,
00078                            iwork, &liwork, &info );
00079             return (info < 0) ? (info - 1) : info;
00080         }
00081         /* Allocate memory for temporary array(s) */
00082         a_t = (double*)LAPACKE_malloc( sizeof(double) * lda_t * MAX(1,n) );
00083         if( a_t == NULL ) {
00084             info = LAPACK_TRANSPOSE_MEMORY_ERROR;
00085             goto exit_level_0;
00086         }
00087         if( LAPACKE_lsame( jobz, 'v' ) ) {
00088             z_t = (double*)
00089                 LAPACKE_malloc( sizeof(double) * ldz_t * MAX(1,ncols_z) );
00090             if( z_t == NULL ) {
00091                 info = LAPACK_TRANSPOSE_MEMORY_ERROR;
00092                 goto exit_level_1;
00093             }
00094         }
00095         /* Transpose input matrices */
00096         LAPACKE_dsy_trans( matrix_order, uplo, n, a, lda, a_t, lda_t );
00097         /* Call LAPACK function and adjust info */
00098         LAPACK_dsyevr( &jobz, &range, &uplo, &n, a_t, &lda_t, &vl, &vu, &il,
00099                        &iu, &abstol, m, w, z_t, &ldz_t, isuppz, work, &lwork,
00100                        iwork, &liwork, &info );
00101         if( info < 0 ) {
00102             info = info - 1;
00103         }
00104         /* Transpose output matrices */
00105         LAPACKE_dsy_trans( LAPACK_COL_MAJOR, uplo, n, a_t, lda_t, a, lda );
00106         if( LAPACKE_lsame( jobz, 'v' ) ) {
00107             LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, ncols_z, z_t, ldz_t, z,
00108                                ldz );
00109         }
00110         /* Release memory and exit */
00111         if( LAPACKE_lsame( jobz, 'v' ) ) {
00112             LAPACKE_free( z_t );
00113         }
00114 exit_level_1:
00115         LAPACKE_free( a_t );
00116 exit_level_0:
00117         if( info == LAPACK_TRANSPOSE_MEMORY_ERROR ) {
00118             LAPACKE_xerbla( "LAPACKE_dsyevr_work", info );
00119         }
00120     } else {
00121         info = -1;
00122         LAPACKE_xerbla( "LAPACKE_dsyevr_work", info );
00123     }
00124     return info;
00125 }


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