forked from Froskekongen/KRYLSTAT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eigen_pow.h
65 lines (48 loc) · 1.23 KB
/
eigen_pow.h
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef EIGEN_POW_H
#define EIGEN_POW_H
#include <Eigen/Eigen>
#include <Eigen/Sparse>
//#include <unsupported/Eigen/SparseExtra>
#include <iostream>
using namespace Eigen;
template <class Derived,class Int_Type>
void eigen_power(const MatrixBase<Derived> &A, Int_Type p, MatrixBase<Derived> &B);
template <class Derived1, class Derived2, class Int_Type>
void eigen_power_sparse(const SparseMatrixBase<Derived1> &A, Int_Type &p, SparseMatrixBase<Derived2> &B);
template <class Derived,class Int_Type>
void eigen_power(const MatrixBase<Derived> &A, Int_Type p, MatrixBase<Derived> &B)
{
if (p > 0)
{
//Int_Type p = k;
while (--p > 1)
{
B *= A;
}
}
else
{
assert(false && "Not yet implemented");
//return pow(Inverse(matrix), -power);
}
}
template <class Derived1, class Derived2, class Int_Type>
void eigen_power_sparse(const SparseMatrixBase<Derived1> &A, const Int_Type &p,SparseMatrixBase<Derived2> &B)
{
// B=A;
if (p > 0)
{
for (Int_Type k = p;k>1;k=k-1)
{
B = A*B;
// B.print();
// std::cout << "Nonzeros: " << B.nonZeros() << "\n\n";
}
}
else
{
assert(false && "Not yet implemented");
//return pow(Inverse(matrix), -power);
}
}
#endif