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
#include <flens/lapack/interface/include/config.h>


namespace flens { namespace lapack {

extern "C" {

//-- dgeev ---------------------------------------------------------------------
void
LAPACK_DECL(dgeev)(const char           *JOBVL,
                   const char           *JOBVR,
                   const INTEGER        *N,
                   DOUBLE               *A,
                   const INTEGER        *LDA,
                   DOUBLE               *WR,
                   DOUBLE               *WI,
                   DOUBLE               *VL,
                   const INTEGER        *LDVL,
                   DOUBLE               *VR,
                   const INTEGER        *LDVR,
                   DOUBLE               *WORK,
                   const INTEGER        *LWORK,
                   INTEGER              *INFO)
{
    std::cerr << "dgeev: N = " << *N << std::endl;

    using std::max;
    using std::min;
//
//  Test the input parameters so that we pass LAPACK error checks
//
    *INFO0;
    bool lQuery = (*LWORK==-1);
    bool wantVL = (*JOBVL=='V');
    bool wantVR = (*JOBVR=='V');

    if ((!wantVL) && (*JOBVL!='N')) {
        *INFO1;
    } else if ((!wantVR) && (*JOBVR!='N')) {
        *INFO2;
    } else if (*N<0) {
        *INFO3;
    } else if (*LDA<max(INTEGER(1),*N)) {
        *INFO5;
    } else if (*LDVL<1 || (wantVL && *LDVL<*N)) {
        *INFO9;
    } else if (*LDVR<1 || (wantVR && *LDVR<*N)) {
        *INFO11;
    }

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

//
//  Setup FLENS matrix/vector types
//
    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);
    DDenseVectorView    _WORK   = DArrayView(*LWORK, WORK1);

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

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

    if (*INFO!=0) {
        LAPACK_ERROR("DGEEV", INFO);
        *INFO = -(*INFO);
        return;
    }
//
//  Call FLENS implementation
//
    ev(wantVL, wantVR, _A, _WR, _WI, _VL, _VR, _WORK);
}

//-- zgeev ---------------------------------------------------------------------
void
LAPACK_DECL(zgeev)(const char           *JOBVL,
                   const char           *JOBVR,
                   const INTEGER        *N,
                   DOUBLE_COMPLEX       *A,
                   const INTEGER        *LDA,
                   DOUBLE_COMPLEX       *W,
                   DOUBLE_COMPLEX       *VL,
                   const INTEGER        *LDVL,
                   DOUBLE_COMPLEX       *VR,
                   const INTEGER        *LDVR,
                   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;
    bool lQuery = (*LWORK==-1);
    bool wantVL = (*JOBVL=='V');
    bool wantVR = (*JOBVR=='V');

    if ((!wantVL) && (*JOBVL!='N')) {
        *INFO1;
    } else if ((!wantVR) && (*JOBVR!='N')) {
        *INFO2;
    } else if (*N<0) {
        *INFO3;
    } else if (*LDA<max(INTEGER(1),*N)) {
        *INFO5;
    } else if (*LDVL<1 || (wantVL && *LDVL<*N)) {
        *INFO8;
    } else if (*LDVR<1 || (wantVR && *LDVR<*N)) {
        *INFO10;
    }

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

//
//  Setup FLENS matrix/vector types
//
    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);
    ZDenseVectorView    _WORK   = ZArrayView(*LWORK, zWORK1);
    DDenseVectorView    _RWORK  = DArrayView(2*(*N), RWORK1);

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

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

    if (*INFO!=0) {
        LAPACK_ERROR("ZGEEV", INFO);
        *INFO = -(*INFO);
        return;
    }
//
//  Call FLENS implementation
//
    ev(wantVL, wantVR, _A, _W, _VL, _VR, _WORK, _RWORK);
}

// extern "C"

} } // namespace lapack, flens