/* CVM Class Library */
/* Copyright (C), Sergei Nikolaev, 1992-2005, http://cvmlib.com */

#include "StdAfx.h"
#include "cvm.h"
#include "blas.h"

#if defined (_MSC_VER)
#   pragma warning(disable:4786)
#endif

CVM_NAMESPACE_BEG

template<>
CVM_API void
__gemm<float, basic_rmatrix<float> >
    (const basic_rmatrix<float>& ml, bool bTrans1,
     const basic_rmatrix<float>& mr, bool bTrans2,
     float dAlpha,
     basic_rmatrix<float>& mRes,
     float dBeta)
{
#if defined (_MSC_VER)
    SGEMM (bTrans1 ? gC<float>().pT() : gC<float>().pN(), 1, bTrans2 ? gC<float>().pT() : gC<float>().pN(), 1,
#else
    SGEMM (bTrans1 ? gC<float>().pT() : gC<float>().pN(),    bTrans2 ? gC<float>().pT() : gC<float>().pN(),
#endif
           bTrans1 ? ml._pn() : ml._pm(),
           bTrans2 ? mr._pm() : mr._pn(),
           bTrans1 ? ml._pm() : ml._pn(),
           &dAlpha,
           ml._pd(), ml._pldm(),
           mr._pd(), mr._pldm(), 
           &dBeta,
           mRes, mRes._pld());
}

template<>
CVM_API void
__gemm<double, basic_rmatrix<double> >
    (const basic_rmatrix<double>& ml, bool bTrans1,
     const basic_rmatrix<double>& mr, bool bTrans2,
     double dAlpha,
     basic_rmatrix<double>& mRes,
     double dBeta)
{
#if defined (_MSC_VER)
    DGEMM (bTrans1 ? gC<double>().pT() : gC<double>().pN(), 1, bTrans2 ? gC<double>().pT() : gC<double>().pN(), 1,
#else
    DGEMM (bTrans1 ? gC<double>().pT() : gC<double>().pN(),    bTrans2 ? gC<double>().pT() : gC<double>().pN(),
#endif
           bTrans1 ? ml._pn() : ml._pm(),
           bTrans2 ? mr._pm() : mr._pn(),
           bTrans1 ? ml._pm() : ml._pn(),
           &dAlpha, 
           ml._pd(), ml._pldm(),
           mr._pd(), mr._pldm(),
           &dBeta,
           mRes, mRes._pld());
}

template<>
CVM_API void
__symm<float, basic_srsmatrix<float>, basic_rmatrix<float> >
    (bool bLeft,
     const basic_srsmatrix<float>& ml,
     const basic_rmatrix<float>& mr, 
     float dAlpha,
     basic_rmatrix<float>& mRes,
     float dBeta)
{
    SSYMM (bLeft ? gC<float>().pL() : gC<float>().pR(),
#if defined (_MSC_VER)
           1,
#endif
           gC<float>().pU(),
#if defined (_MSC_VER)
           1,
#endif
           mRes._pm(), mRes._pn(),
           &dAlpha,
           ml._pd(), ml._pld(),
           mr._pd(), mr._pld(),
           &dBeta,
           mRes, mRes._pld());
}

template<>
CVM_API void
__symm<double, basic_srsmatrix<double>, basic_rmatrix<double>  >
    (bool bLeft,
     const basic_srsmatrix<double>& ml,
     const basic_rmatrix<double>& mr, 
     double dAlpha,
     basic_rmatrix<double>& mRes,
     double dBeta)
{
    DSYMM (bLeft ? gC<double>().pL() : gC<double>().pR(),
#if defined (_MSC_VER)
           1,
#endif
           gC<double>().pU(),
#if defined (_MSC_VER)
           1,
#endif
           mRes._pm(), mRes._pn(),
           &dAlpha,
           ml._pd(), ml._pld(),
           mr._pd(), mr._pld(),
           &dBeta,
           mRes, mRes._pld());
}

template <>
CVM_API void
__syrk<float, basic_srsmatrix<float> >
    (bool bTransp, 
    float alpha, int k,
    const float* pA, int ldA,
    float beta, basic_srsmatrix<float>& m)
{
    SSYRK (gC<float>().pU(),
#if defined (_MSC_VER)
           1,
#endif
           bTransp ? gC<float>().pT() : gC<float>().pN(),
#if defined (_MSC_VER)
           1,
#endif
           m._pm(), &k, &alpha, pA, &ldA, &beta, m, m._pld());
}

template <>
CVM_API void
__syrk<double, basic_srsmatrix<double> >
    (bool bTransp, 
    double alpha, int k,
    const double* pA, int ldA,
    double beta, basic_srsmatrix<double>& m)
{
    DSYRK (gC<double>().pU(),
#if defined (_MSC_VER)
           1,
#endif
           bTransp ? gC<double>().pT() : gC<double>().pN(),
#if defined (_MSC_VER)
           1,
#endif
           m._pm(), &k, &alpha, pA, &ldA, &beta, m, m._pld());
}

template <>
CVM_API void
__syr2k<float, basic_srsmatrix<float> >
    (bool bTransp, 
    float alpha, int k,
    const float* pA, int ldA,
    const float* pB, int ldB,
    float beta, basic_srsmatrix<float>& m)
{
    SSYR2K (gC<float>().pU(),
#if defined (_MSC_VER)
           1,
#endif
           bTransp ? gC<float>().pT() : gC<float>().pN(),
#if defined (_MSC_VER)
           1,
#endif
           m._pm(), &k, &alpha, pA, &ldA, pB, &ldB, &beta, m, m._pld());
}

template <>
CVM_API void
__syr2k<double, basic_srsmatrix<double> >
    (bool bTransp, 
    double alpha, int k,
    const double* pA, int ldA,
    const double* pB, int ldB,
    double beta, basic_srsmatrix<double>& m)
{
    DSYR2K (gC<double>().pU(),
#if defined (_MSC_VER)
           1,
#endif
           bTransp ? gC<double>().pT() : gC<double>().pN(),
#if defined (_MSC_VER)
           1,
#endif
           m._pm(), &k, &alpha, pA, &ldA, pB, &ldB, &beta, m, m._pld());
}

CVM_NAMESPACE_END
