#ifndef BFM_HOUSEHOLDER_H #define BFM_HOUSEHOLDER_H #include #include #include #include #include #include #include #include #include #include "RandomMatrix.h" namespace BFM_Krylov{ /** Comparison function for finding the max element in a vector **/ template bool cf(T i, T j) { return abs(i) < abs(j); } /** Calculate a real Givens angle **/ template inline void Givens_calc(const T y, const T z, T &c, T &s){ double mz = (double)abs(z); if(mz==0.0){ c = 1; s = 0; } if(mz >= (double)abs(y)){ T t = -y/z; s = (T)1.0 / sqrt ((T)1.0 + t * t); c = s * t; } else{ T t = -z/y; c = (T)1.0 / sqrt ((T)1.0 + t * t); s = c * t; } } template inline void Givens_mult(Matrix &A, const int i, const int k, const T c, const T s, const int dir){ int q = A.dim; if(dir == 0){ for(int j=0;j inline void Householder_vector(const std::vector &input, const int k, const int j, std::vector &v, T &beta){ int N = input.size(); T m = *max_element(input.begin() + k, input.begin() + j + 1, cf ); if(abs(m) > 0.0){ T alpha = 0; for(int i=k; i 0.0){v[k] = v[k] + (v[k]/abs(v[k]))*alpha;} else{v[k] = -alpha;} } else{for(int i=k; i inline void Householder_vector(const std::vector &input, const int k, const int j, const int dir, std::vector &v, T &beta){ int N = input.size(); T m = *max_element(input.begin() + k, input.begin() + j + 1, cf); if(abs(m) > 0.0){ T alpha = 0; for(int i=k; i 0.0){ v[dir] = v[dir] + (v[dir]/abs(v[dir]))*alpha; } else{v[dir] = -alpha;} } else{for(int i=k; i inline void Householder_mult(Matrix &A , const std::vector &v, const T beta, const int l, const int k, const int j, const int trans) { int N = A.dim; if(abs(beta) > 0.0){ for(int p=l; p inline void Householder_mult_tri(Matrix &A , const std::vector &v, const T beta, const int l, const int M, const int k, const int j, const int trans){ if(abs(beta) > 0.0){ int N = A.dim; Matrix tmp(N,0); T s; for(int p=l; p