1 #ifndef MPQC_MATH_BLAS_HPP
2 #define MPQC_MATH_BLAS_HPP
5 #include "mpqc_config.h"
8 #ifndef MPQCMATH_USE_BLAS
9 # define MPQCMATH_USE_BLAS 1
14 #if (F77_INTEGER_WIDTH == 8)
15 #define BIND_FORTRAN_INTEGER_8 // or not
17 #include <boost/numeric/bindings/blas.hpp>
19 #include "mpqc/math/matrix.hpp"
21 #include <boost/numeric/bindings/eigen/matrix.hpp>
29 template<
class Matrix,
typename Id,
typename Enable>
30 struct adaptor< Eigen::Map< Matrix >, Id, Enable >
31 : adaptor<Matrix, Id, Enable> {};
33 template<
typename T,
int Rows,
int Options,
34 typename Id,
typename Enable >
35 struct adaptor< Eigen::
Matrix< T, Rows, 1, Options >, Id, Enable > {
36 typedef typename copy_const< Id, T >::type value_type;
37 typedef typename eigen_size_type< Rows >::type size_type1;
39 mpl::pair< tag::value_type, value_type >,
40 mpl::pair< tag::entity, tag::vector >,
41 mpl::pair< tag::size_type<1>, size_type1 >,
42 mpl::pair< tag::data_structure, tag::linear_array >,
43 mpl::pair< tag::stride_type<1>, tag::contiguous >
45 static std::ptrdiff_t size1(
const Id&
id ) {
48 static value_type* begin_value( Id&
id ) {
51 static value_type* end_value( Id&
id ) {
52 return id.data()+
id.size();
57 template<
typename T,
int Options,
typename Id,
typename Enable>
58 struct adaptor<
mpqc::matrix<T, Options>, Id, Enable >
59 : adaptor< typename mpqc::matrix<T, Options>::EigenType, Id, Enable> {};
66 #endif // MPQCMATH_USE_BLAS
75 void clear(
size_t n, T *x) {
79 template<
class A,
class B>
80 typename A::Scalar
dot(
const Eigen::MatrixBase<A> &a,
81 const Eigen::MatrixBase<B> &b) {
83 return boost::numeric::bindings::blas::dot(a.derived(), b.derived());
86 #endif // MPQCMATH_USE_BLAS
89 template<
typename Alpha,
class A,
class B>
90 void axpy(
const Alpha &alpha,
91 const Eigen::MatrixBase<A> &a,
92 Eigen::MatrixBase<B> &b) {
94 boost::numeric::bindings::blas::axpy(alpha, a.derived(), b.derived());
97 #endif // MPQCMATH_USE_BLAS
100 template<
typename Alpha,
class A,
class B,
typename Beta,
class C>
101 void gemm(
const Alpha &alpha,
102 const Eigen::MatrixBase<A> &a,
103 const Eigen::MatrixBase<B> &b,
105 Eigen::MatrixBase<C> &c) {
106 #if MPQCMATH_USE_BLAS
107 boost::numeric::bindings::blas::gemm(alpha, a.derived(), b.derived(),
111 if (beta == Beta(0)) c.fill(Beta(0));
112 c = alpha*a*b + beta*c;
113 #endif // MPQCMATH_USE_BLAS