MPQC 3.0.0-alpha
Loading...
Searching...
No Matches
blas.hpp
1#ifndef MPQC_MATH_BLAS_HPP
2#define MPQC_MATH_BLAS_HPP
3
4#ifdef HAVE_CONFIG_H
5#include "mpqc_config.h"
6#endif
7
8#ifndef MPQCMATH_USE_BLAS
9# define MPQCMATH_USE_BLAS 1
10#endif
11
12#if MPQCMATH_USE_BLAS
13
14#if (F77_INTEGER_WIDTH == 8)
15#define BIND_FORTRAN_INTEGER_8 // or not
16#endif
17#include <boost/numeric/bindings/blas.hpp>
18
19#include "mpqc/math/matrix.hpp"
20#include <Eigen/Core>
21#include <boost/numeric/bindings/eigen/matrix.hpp>
22
23namespace boost {
24namespace numeric {
25namespace bindings {
26namespace detail {
27
29template< class Matrix, typename Id, typename Enable>
30struct adaptor< Eigen::Map< Matrix >, Id, Enable >
31 : adaptor<Matrix, Id, Enable> {};
32
33template< typename T, int Rows, int Options,
34 typename Id, typename Enable >
35struct 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;
38 typedef mpl::map<
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 >
44 > property_map;
45 static std::ptrdiff_t size1( const Id& id ) {
46 return id.size();
47 }
48 static value_type* begin_value( Id& id ) {
49 return id.data();
50 }
51 static value_type* end_value( Id& id ) {
52 return id.data()+id.size();
53 }
54};
55
57template< typename T, int Options, typename Id, typename Enable>
58struct adaptor< mpqc::matrix<T, Options>, Id, Enable >
59 : adaptor< typename mpqc::matrix<T, Options>::EigenType, Id, Enable> {};
60
61} // namespace detail
62} // namespace bindings
63} // namespace numeric
64} // namespace boost
65
66#endif // MPQCMATH_USE_BLAS
67
68namespace mpqc {
69namespace blas {
70
73
74 template<typename T>
75 void clear(size_t n, T *x) {
76 std::fill_n(x, n, 0);
77 }
78
79 template<class A, class B>
80 typename A::Scalar dot(const Eigen::MatrixBase<A> &a,
81 const Eigen::MatrixBase<B> &b) {
82#if MPQCMATH_USE_BLAS
83 return boost::numeric::bindings::blas::dot(a.derived(), b.derived());
84#else
85 return a.dot(b);
86#endif // MPQCMATH_USE_BLAS
87 }
88
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) {
93#if MPQCMATH_USE_BLAS
94 boost::numeric::bindings::blas::axpy(alpha, a.derived(), b.derived());
95#else
96 b = alpha*a + b;
97#endif // MPQCMATH_USE_BLAS
98 }
99
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,
104 const Beta &beta,
105 Eigen::MatrixBase<C> &c) {
106#if MPQCMATH_USE_BLAS
107 boost::numeric::bindings::blas::gemm(alpha, a.derived(), b.derived(),
108 beta, c.derived());
109#else
110 // N.B. fill (rather than scale) by zero to clear NaN/Inf
111 if (beta == Beta(0)) c.fill(Beta(0));
112 c = alpha*a*b + beta*c;
113#endif // MPQCMATH_USE_BLAS
114 }
115
117
118}
119}
120
121#endif /* MPQC_MATH_BLAS_HPP */
matrix< double > Matrix
Convience double matrix type.
Definition matrix.hpp:170
Contains new MPQC code since version 3.
Definition integralenginepool.hpp:37
void axpy(const Ref< DistArray4 > &X, double a, const Ref< DistArray4 > &Y, double scale=1.0)
axpy followed by scaling: Y += a*X; Y *= scale.

Generated at Wed Sep 25 2024 02:45:30 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.12.0.