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
///
/// Define `USE_CXXLAPACK` before you include the FLENS headers
///
#ifndef USE_CXXLAPACK
#define USE_CXXLAPACK
#endif
#include <flens/flens.cxx>

using namespace flens;

namespace mylapack {

///
/// The trait is of form `RestrictTo<Cond,B>::Type`.  If `Cond` is
/// true then `RestrictTo<Cond,B>::Type` equals `B`.  This will be the return
/// type.  If `Cond` is false then the trait can not be instantiated.  In this
/// case the function can not be instantiated either and the whole thing gets
/// ignored.
///
/// Note that we also need the `RemoveRef` trait (yeah, C++ brain fuck!).  If
/// `MA` is of type `T &` then `RemoveRef<T>::Type` is of type `T`.
///
template <typename MA, typename VPIV>
typename RestrictTo<IsGeMatrix<MA>::value
                 && IsIntegerDenseVector<VPIV>::value,
         typename RemoveRef<MA>::Type::IndexType>::Type
trf(MA &&A, VPIV &&piv)
{
    typedef typename RemoveRef<MA>::Type::IndexType  IndexType;
    return cxxlapack::getrf<IndexType>(A.numRows(),
                                       A.numCols(),
                                       A.data(),
                                       A.leadingDimension(),
                                       piv.data());
}

///
/// For `trs` things are like above.  But now the return type is simpler and
/// for traits-newbies it might be easier to read.
///
template <typename MA, typename VPIV, typename VB>
typename RestrictTo<IsGeMatrix<MA>::value
                 && IsIntegerDenseVector<VPIV>::value
                 && IsDenseVector<VB>::value,
         void>::Type
trs(Transpose trans, const MA &A, const VPIV &piv, VB &&b)
{
    typedef typename MA::IndexType IndexType;
    cxxlapack::getrs<IndexType>(lapack::getF77Char(trans),
                                A.numRows(),
                                1,
                                A.data(),
                                A.leadingDimension(),
                                piv.data(),
                                b.data(),
                                b.length());
}

// namespace mylapack