|
| 1 | +/***************************************************************************** |
| 2 | + Copyright (c) 2014, Intel Corp. |
| 3 | + Copyright (c) 2026, Ruiyi Zhan and Shaoshuai Zhang. |
| 4 | + All rights reserved. |
| 5 | +
|
| 6 | + Redistribution and use in source and binary forms, with or without |
| 7 | + modification, are permitted provided that the following conditions are met: |
| 8 | +
|
| 9 | + * Redistributions of source code must retain the above copyright notice, |
| 10 | + this list of conditions and the following disclaimer. |
| 11 | + * Redistributions in binary form must reproduce the above copyright |
| 12 | + notice, this list of conditions and the following disclaimer in the |
| 13 | + documentation and/or other materials provided with the distribution. |
| 14 | + * Neither the name of Intel Corporation nor the names of its contributors |
| 15 | + may be used to endorse or promote products derived from this software |
| 16 | + without specific prior written permission. |
| 17 | +
|
| 18 | + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 22 | + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 28 | + THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | +***************************************************************************** |
| 30 | +* Contents: Native high-level C interface to LAPACK function dstebr |
| 31 | +* Author: Ruiyi Zhan and Shaoshuai Zhang |
| 32 | +*****************************************************************************/ |
| 33 | + |
| 34 | +#include "lapacke_utils.h" |
| 35 | + |
| 36 | +lapack_int API_SUFFIX(LAPACKE_dstebr)( lapack_int n, double* d, double* e ) |
| 37 | +{ |
| 38 | + lapack_int info = 0; |
| 39 | + lapack_int liwork = -1; |
| 40 | + lapack_int lwork = -1; |
| 41 | + lapack_int* iwork = NULL; |
| 42 | + double* work = NULL; |
| 43 | + lapack_int iwork_query; |
| 44 | + double work_query; |
| 45 | +#ifndef LAPACK_DISABLE_NAN_CHECK |
| 46 | + if( LAPACKE_get_nancheck() ) { |
| 47 | + /* Optionally check input matrices for NaNs */ |
| 48 | + if( API_SUFFIX(LAPACKE_d_nancheck)( n, d, 1 ) ) { |
| 49 | + return -2; |
| 50 | + } |
| 51 | + if( API_SUFFIX(LAPACKE_d_nancheck)( n-1, e, 1 ) ) { |
| 52 | + return -3; |
| 53 | + } |
| 54 | + } |
| 55 | +#endif |
| 56 | + /* Query optimal working array(s) size */ |
| 57 | + info = API_SUFFIX(LAPACKE_dstebr_work)( n, d, e, &work_query, lwork, |
| 58 | + &iwork_query, liwork ); |
| 59 | + if( info != 0 ) { |
| 60 | + goto exit_level_0; |
| 61 | + } |
| 62 | + liwork = iwork_query; |
| 63 | + lwork = (lapack_int)work_query; |
| 64 | + /* Allocate memory for work arrays */ |
| 65 | + iwork = (lapack_int*)LAPACKE_malloc( sizeof(lapack_int) * liwork ); |
| 66 | + if( iwork == NULL ) { |
| 67 | + info = LAPACK_WORK_MEMORY_ERROR; |
| 68 | + goto exit_level_0; |
| 69 | + } |
| 70 | + work = (double*)LAPACKE_malloc( sizeof(double) * lwork ); |
| 71 | + if( work == NULL ) { |
| 72 | + info = LAPACK_WORK_MEMORY_ERROR; |
| 73 | + goto exit_level_1; |
| 74 | + } |
| 75 | + /* Call middle-level interface */ |
| 76 | + info = API_SUFFIX(LAPACKE_dstebr_work)( n, d, e, work, lwork, iwork, |
| 77 | + liwork ); |
| 78 | + /* Release memory and exit */ |
| 79 | + LAPACKE_free( work ); |
| 80 | +exit_level_1: |
| 81 | + LAPACKE_free( iwork ); |
| 82 | +exit_level_0: |
| 83 | + if( info == LAPACK_WORK_MEMORY_ERROR ) { |
| 84 | + API_SUFFIX(LAPACKE_xerbla)( "LAPACKE_dstebr", info ); |
| 85 | + } |
| 86 | + return info; |
| 87 | +} |
0 commit comments