-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheigen_interface.h
More file actions
47 lines (36 loc) · 863 Bytes
/
eigen_interface.h
File metadata and controls
47 lines (36 loc) · 863 Bytes
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
//
// Copyright Chong Peng 2017
//
#ifndef CODE_EXAMPLE_EIGEN_INTERFACE_H_
#define CODE_EXAMPLE_EIGEN_INTERFACE_H_
#include "type_def.h"
namespace code_example {
/**
* Interface of Eigen Matrix to use DavidsonDiag classes
*
* \@tparam T the element type in Eigen Matrix
*
*/
template <typename T>
RowMatrix<T> copy_and_zero(const RowMatrix<T>& a){
return RowMatrix<T>::Zero(a.rows(), a.cols());
}
template <typename T>
void scale(RowMatrix<T>& y, T a) {
y = a * y;
}
template <typename T>
void axpy(RowMatrix<T>& y, T a, const RowMatrix<T>& x){
y = y + a*x;
}
template <typename T>
T dot_product(const RowMatrix<T>& x, const RowMatrix<T>& y){
T dot = x.cwiseProduct(y).sum();
return dot;
}
template <typename T>
T norm2(const RowMatrix<T>& a){
return a.norm();
}
} // namespace code_example
#endif // CODE_EXAMPLE_EIGEN_INTERFACE_H_