1 #ifndef MPQC_MATRIX_HPP
2 #define MPQC_MATRIX_HPP
4 #include "mpqc/range.hpp"
5 #include "math/scmat/matrix.h"
7 #define EIGEN_DONT_PARALLELIZE
20 template<
typename T,
int Order = Eigen::ColMajor>
24 typedef Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, Order> EigenType;
32 matrix(
size_t m,
size_t n) : EigenType(m,n) {}
36 matrix(
const Eigen::EigenBase<A> &a) : EigenType(a) {}
40 this->resize(a.nrow(), a.ncol());
41 apply(assign(), this->rows(), this->cols(), *
this, a);
46 this->resize(a.n(), a.n());
47 apply(assign(), this->rows(), this->cols(), *
this, a);
72 using EigenType::operator();
75 template<
typename T_,
typename U_>
76 struct is_index : boost::mpl::and_<
77 boost::is_integral<T_>,
78 boost::is_integral<U_> > {};
81 template<
class Ri,
class Rj>
82 typename boost::disable_if<
84 Eigen::Block<EigenType>
92 return this->block(*ri.begin(), *rj.begin(), ri.size(), rj.size());
95 template<
class Ri,
class Rj>
96 typename boost::disable_if<
98 Eigen::Block<const EigenType>
106 return this->block(*ri.begin(), *rj.begin(), ri.size(), rj.size());
111 void reshape(
int m,
int n);
114 template<
class F,
class A,
class B>
115 static void apply(
const F &f,
size_t m,
size_t n, A &a, B &b) {
116 for (
int j = 0; j < n; ++j) {
117 for (
int i = 0; i < m; ++i) {
123 template<
class A,
class B>
149 EigenType::resize(end - begin, 1);
150 std::copy(begin, end, EigenType::data());
154 using EigenType::operator();
158 return this->block(*i.begin(), 0, i.size(), 1);
163 return this->block(*i.begin(), 0, i.size(), 1);
180 return std::max(fabs(e.maxCoeff()), fabs(e.minCoeff()));
188 MPQC_ASSERT(a.cols() == b.cols());
189 for (
size_t j = 0; j < a.cols(); ++j) {
190 q += a.col(j).dot(b.col(j));
200 Eigen::SelfAdjointEigenSolver<Matrix::EigenType> es(a);
201 if (es.info() != Eigen::Success)
202 throw std::runtime_error(
"Eigen solver failed");
double absmax(const E &e)
absolute max of an Eigen type
Definition: matrix.hpp:179
void orthonormalize(matrix< T > &d, const matrix< T > &b)
orthormalize matrix d wrt to normalized matrix b d = normalize(d - (<d|b>*b))
Definition: matrix.hpp:224
Contains new MPQC code since version 3.
Definition: integralenginepool.hpp:37
vector(size_t m=0)
Construct unititialized vector.
Definition: matrix.hpp:141
The RefSymmSCMatrix class is a smart pointer to an SCSymmSCMatrix specialization.
Definition: matrix.h:265
matrix(size_t m, size_t n)
Construct unititialized matrix.
Definition: matrix.hpp:32
The RefSCMatrix class is a smart pointer to an SCMatrix specialization.
Definition: matrix.h:135
Matrix class derived from Eigen::Matrix with additional MPQC integration.
Definition: matrix.hpp:21
range range_cast(const range &r)
Cast range to range, return argument unchanged.
Definition: range.hpp:123
matrix< double > Matrix
Convience double matrix type.
Definition: matrix.hpp:170
An interface to enable matrix assignment from other containers.
Definition: matrix.hpp:54
matrix(const sc::RefSymmSCMatrix &a)
Construct full matrix from sc::RefSCMatrix matrix.
Definition: matrix.hpp:45
T norm(const matrix< T > &a)
Matrix norm.
Definition: matrix.hpp:209
Type operator()(i, j)
Operators to access matrix element/block, see here.
vector(const T *begin, const T *end)
Construct vector from iterator range.
Definition: matrix.hpp:148
void normalize(matrix< T > &a)
Normalize matrix.
Definition: matrix.hpp:216
virtual void assign_to(matrix &m) const =0
Assign data to matrix.
Eigen::Matrix< T, Eigen::Dynamic, 1 > EigenType
Eigen base type.
Definition: matrix.hpp:136
Eigen::Block< const EigenType > operator()(range i) const
const range operator.
Definition: matrix.hpp:162
T dot(const matrix< T > &a, const matrix< T > &b)
element-wise dot product of two matrices
Definition: matrix.hpp:186
matrix(const Eigen::EigenBase< A > &a)
Construct matrix from Eigen type.
Definition: matrix.hpp:36
vector< double > Vector
Convience double vector type.
Definition: matrix.hpp:172
Vector class derived from Eigen::Matrix with additional MPQC integration.
Definition: matrix.hpp:133
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14
Eigen::Block< EigenType > operator()(range i)
range operator.
Definition: matrix.hpp:157
matrix(const Assignable &a)
Constructs matrix from an Assignable container.
Definition: matrix.hpp:61
Eigen::SelfAdjointEigenSolver< Matrix::EigenType > symmetric(const matrix< T > &a)
Computes (Eigen::SelfAdjointEigenSolver) eigensystem of a matrix.
Definition: matrix.hpp:199
vector(const Eigen::EigenBase< A > &a)
Construct vector from Eigen type.
Definition: matrix.hpp:145
matrix(sc::RefSCMatrix a)
Construct matrix from sc::RefSCMatrix matrix.
Definition: matrix.hpp:39
Generated at Sun Jan 26 2020 23:24:01 for MPQC
3.0.0-alpha using the documentation package Doxygen
1.8.16.