1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      71
      72
      73
      74
      75
      76
      77
      78
      79
      80
      81
      82
      83
      84
      85
      86
      87
      88
      89
      90
      91
      92
      93
      94
      95
      96
      97
      98
      99
     100
     101
     102
     103
     104
     105
     106
     107
     108
     109
     110
     111
     112
     113
     114
     115
     116
     117
     118
     119
     120
     121
     122
     123
     124
     125
     126
     127
     128
     129
     130
     131
     132
     133
     134
     135
     136
     137
     138
     139
     140
     141
     142
     143
     144
     145
     146
     147
     148
     149
     150
     151
     152
     153
     154
     155
     156
     157
     158
     159
     160
     161
     162
     163
     164
     165
     166
     167
     168
     169
     170
     171
     172
     173
     174
     175
     176
     177
     178
     179
     180
     181
     182
     183
     184
     185
     186
     187
     188
     189
     190
     191
     192
     193
     194
     195
     196
     197
     198
     199
     200
     201
     202
     203
     204
     205
     206
     207
     208
     209
     210
     211
     212
     213
     214
     215
     216
     217
     218
     219
     220
     221
     222
     223
     224
     225
     226
     227
     228
     229
     230
     231
     232
     233
     234
     235
     236
     237
     238
     239
     240
     241
     242
     243
     244
     245
     246
     247
     248
     249
     250
     251
     252
     253
     254
#include <flens/lapack/interface/include/config.h>


namespace flens { namespace lapack {

extern "C" {

//-- dgeevx --------------------------------------------------------------------
void
LAPACK_DECL(dgeevx)(const char       *BALANC,
                    const char       *JOBVL,
                    const char       *JOBVR,
                    const char       *_SENSE,
                    const INTEGER    *N,
                    DOUBLE           *A,
                    const INTEGER    *LDA,
                    DOUBLE           *WR,
                    DOUBLE           *WI,
                    DOUBLE           *VL,
                    const INTEGER    *LDVL,
                    DOUBLE           *VR,
                    const INTEGER    *LDVR,
                    INTEGER          *ILO,
                    INTEGER          *IHI,
                    DOUBLE           *SCALE,
                    DOUBLE           *ABNRM,
                    DOUBLE           *RCONDE,
                    DOUBLE           *RCONDV,
                    DOUBLE           *WORK,
                    const INTEGER    *LWORK,
                    INTEGER          *IWORK,
                    INTEGER          *INFO)
{
    std::cerr << "dgeevx: N = " << *N << std::endl;

    using std::max;
    using std::min;
//
//  Test the input parameters so that we pass LAPACK error checks
//
    *INFO0;
    const bool lQuery = (*LWORK==-1);
    const bool wantVL = (*JOBVL=='V');
    const bool wantVR = (*JOBVR=='V');
    const bool wantSNN = (*_SENSE=='N');
    const bool wantSNE = (*_SENSE=='E');
    const bool wantSNV = (*_SENSE=='V');
    const bool wantSNB = (*_SENSE=='B');

    if (*BALANC!='N' && *BALANC!='S' && *BALANC!='P' && *BALANC!='B') {
        *INFO1;
    } else if ((!wantVL) && (*JOBVL!='N')) {
        *INFO2;
    } else if ((!wantVR) && (*JOBVR!='N')) {
        *INFO3;
    } else if (!(wantSNN || wantSNE || wantSNB || wantSNV)
            || ((wantSNE || wantSNB ) && !(wantVL && wantVR)))
    {
        *INFO4;
    } else if (*N<0) {
        *INFO5;
    } else if (*LDA<max(INTEGER(1),*N)) {
        *INFO7;
    } else if (*LDVL<1 || (wantVL && *LDVL<*N)) {
        *INFO11;
    } else if (*LDVR<1 || (wantVR && *LDVR<*N)) {
        *INFO13;
    }

    if (*INFO!=0) {
        LAPACK_ERROR("DGEEVX", INFO);
        *INFO = -(*INFO);
        return;
    }

//
//  Setup FLENS matrix/vector types
//
    BALANCE::Balance  balance = BALANCE::Balance(*BALANC);
    SENSE::Sense      sense   = SENSE::Sense(*_SENSE);

    ASSERT(char(balance)==*BALANC);
    ASSERT(char(sense)==*_SENSE);

    typedef typename DGeMatrixView::IndexType   IndexType;

    DGeMatrixView       _A      = DFSView(*N, *N, A, *LDA);
    DDenseVectorView    _WR     = DArrayView(*N, WR1);
    DDenseVectorView    _WI     = DArrayView(*N, WI1);
    DGeMatrixView       _VL     = DFSView(*N, *N, VL, *LDVL);
    DGeMatrixView       _VR     = DFSView(*N, *N, VR, *LDVR);
    IndexType           _ILO    = *ILO;
    IndexType           _IHI    = *IHI;
    DDenseVectorView    _SCALE  = DArrayView(*N, SCALE1);
    DDenseVectorView    _RCONDE = DArrayView(*N, RCONDE1);
    DDenseVectorView    _RCONDV = DArrayView(*N, RCONDV1);
    DDenseVectorView    _WORK   = DArrayView(*LWORK, WORK1);

    IDenseVector        _IWORK(*N2 - 2);
    for (int i=1; i<=_IWORK.length(); ++i) {
        _IWORK(i) = IWORK[i-1];
    }

//
//  Test if work has at least minimal worksize
//
    auto ws = evx_wsq(wantVL, wantVR, sense, _A);

    if (*LWORK<ws.first && !lQuery) {
        *INFO21;
    }

    if (*INFO!=0) {
        LAPACK_ERROR("DGEEVX", INFO);
        *INFO = -(*INFO);
        return;
    }
//
//  Call FLENS implementation
//

    evx(balance, wantVL, wantVR, sense, _A, _WR, _WI, _VL, _VR, _ILO, _IHI,
        _SCALE, *ABNRM, _RCONDE, _RCONDV, _WORK, _IWORK);

    for (int i=1; i<=_IWORK.length(); ++i) {
        IWORK[i-1] = _IWORK(i);
    }

    *ILO = _ILO;
    *IHI = _IHI;
}

//-- zgeevx --------------------------------------------------------------------
void
LAPACK_DECL(zgeevx)(const char       *BALANC,
                    const char       *JOBVL,
                    const char       *JOBVR,
                    const char       *_SENSE,
                    const INTEGER    *N,
                    DOUBLE_COMPLEX   *A,
                    const INTEGER    *LDA,
                    DOUBLE_COMPLEX   *W,
                    DOUBLE_COMPLEX   *VL,
                    const INTEGER    *LDVL,
                    DOUBLE_COMPLEX   *VR,
                    const INTEGER    *LDVR,
                    INTEGER          *ILO,
                    INTEGER          *IHI,
                    DOUBLE           *SCALE,
                    DOUBLE           *ABNRM,
                    DOUBLE           *RCONDE,
                    DOUBLE           *RCONDV,
                    DOUBLE_COMPLEX   *WORK,
                    const INTEGER    *LWORK,
                    DOUBLE           *RWORK,
                    INTEGER          *INFO)
{
    using std::max;
    using std::min;
//
//  Test the input parameters so that we pass LAPACK error checks
//
    *INFO0;
    const bool lQuery = (*LWORK==-1);
    const bool wantVL = (*JOBVL=='V');
    const bool wantVR = (*JOBVR=='V');
    const bool wantSNN = (*_SENSE=='N');
    const bool wantSNE = (*_SENSE=='E');
    const bool wantSNV = (*_SENSE=='V');
    const bool wantSNB = (*_SENSE=='B');

    if (*BALANC!='N' && *BALANC!='S' && *BALANC!='P' && *BALANC!='B') {
        *INFO1;
    } else if ((!wantVL) && (*JOBVL!='N')) {
        *INFO2;
    } else if ((!wantVR) && (*JOBVR!='N')) {
        *INFO3;
    } else if (!(wantSNN || wantSNE || wantSNB || wantSNV)
            || ((wantSNE || wantSNB ) && !(wantVL && wantVR)))
    {
        *INFO4;
    } else if (*N<0) {
        *INFO5;
    } else if (*LDA<max(INTEGER(1),*N)) {
        *INFO7;
    } else if (*LDVL<1 || (wantVL && *LDVL<*N)) {
        *INFO10;
    } else if (*LDVR<1 || (wantVR && *LDVR<*N)) {
        *INFO12;
    }

    if (*INFO!=0) {
        LAPACK_ERROR("ZGEEVX", INFO);
        *INFO = -(*INFO);
        return;
    }

//
//  Setup FLENS matrix/vector types
//
    BALANCE::Balance  balance = BALANCE::Balance(*BALANC);
    SENSE::Sense      sense   = SENSE::Sense(*_SENSE);

    ASSERT(char(balance)==*BALANC);
    ASSERT(char(sense)==*_SENSE);

    typedef typename DGeMatrixView::IndexType   IndexType;

    auto zA     = reinterpret_cast<CXX_DOUBLE_COMPLEX *>(A);
    auto zW     = reinterpret_cast<CXX_DOUBLE_COMPLEX *>(W);
    auto zVL    = reinterpret_cast<CXX_DOUBLE_COMPLEX *>(VL);
    auto zVR    = reinterpret_cast<CXX_DOUBLE_COMPLEX *>(VR);
    auto zWORK  = reinterpret_cast<CXX_DOUBLE_COMPLEX *>(WORK);

    ZGeMatrixView       _A      = ZFSView(*N, *N, zA, *LDA);
    ZDenseVectorView    _W      = ZArrayView(*N, zW1);
    ZGeMatrixView       _VL     = ZFSView(*N, *N, zVL, *LDVL);
    ZGeMatrixView       _VR     = ZFSView(*N, *N, zVR, *LDVR);
    IndexType           _ILO    = *ILO;
    IndexType           _IHI    = *IHI;
    DDenseVectorView    _SCALE  = DArrayView(*N, SCALE1);
    DDenseVectorView    _RCONDE = DArrayView(*N, RCONDE1);
    DDenseVectorView    _RCONDV = DArrayView(*N, RCONDV1);
    ZDenseVectorView    _WORK   = ZArrayView(*LWORK, zWORK1);
    DDenseVectorView    _RWORK  = DArrayView(2*(*N), RWORK1);

//
//  Test if work has at least minimal worksize
//
    auto ws = evx_wsq(wantVL, wantVR, sense, _A);

    if (*LWORK<ws.first && !lQuery) {
        *INFO20;
    }

    if (*INFO!=0) {
        LAPACK_ERROR("ZGEEVX", INFO);
        *INFO = -(*INFO);
        return;
    }
//
//  Call FLENS implementation
//

    evx(balance, wantVL, wantVR, sense, _A, _W, _VL, _VR, _ILO, _IHI,
        _SCALE, *ABNRM, _RCONDE, _RCONDV, _WORK, _RWORK);

    *ILO = _ILO;
    *IHI = _IHI;
}

// extern "C"

} } // namespace lapack, flens