00001 #include "skeleton.hpp"
00002
00003 Skeleton::Skeleton(unsigned r)
00004 : rank(r)
00005 { }
00006
00007 unsigned Skeleton::GetRank() const
00008 {
00009 return rank;
00010 }
00011
00012 Skeleton::~Skeleton() { }
00013
00014
00015
00016 void Skeleton::MatvecF(double alpha, const double *vec,
00017 double *res, double *calc, mv_mode mode) const
00018 {
00019 unsigned i, k, num_cols, num_rows;
00020 const Matrix& U = mode == normal ? GetU() : GetV();
00021 const Matrix& V = mode == normal ? GetV() : GetU();
00022 num_cols = GetNumCols();
00023 num_rows = GetNumRows();
00024
00025 for(k = 0; k < rank; ++k) {
00026 calc[k] = 0;
00027 for(i = 0; i < num_cols; ++i) {
00028 calc[k] += V.elem(i, k) * vec[i];
00029 }
00030 calc[k] *= alpha;
00031 }
00032
00033 for(i = 0; i < num_rows; ++i) {
00034 res[i] = 0;
00035 for(k = 0; k < rank; ++k) {
00036 res[i] += U.elem(i, k) * calc[k];
00037 }
00038 }
00039 }
00040
00041 void Skeleton::MatvecUT(double alpha, const double *vec,
00042 double *res, mv_mode mode) const
00043 {
00044 unsigned i, k, num_cols, num_rows;
00045 double tmp;
00046 const Matrix& U = mode == normal ? GetU() : GetV();
00047 const Matrix& V = mode == normal ? GetV() : GetU();
00048 num_cols = GetNumCols();
00049 num_rows = GetNumRows();
00050 for(i = 0; i < num_rows; ++i) {
00051 res[i] = 0.0;
00052 }
00053 for(k = 0; k < rank; ++k) {
00054 tmp = 0.0;
00055 for(i = 0; i < num_rows; ++i) {
00056 if(i < num_cols) {
00057 tmp += V.elem(num_rows - 1 - i, k) * vec[num_rows - 1 - i];
00058 }
00059 res[num_rows - 1 - i] += tmp * U.elem(num_rows - 1 - i, k);
00060 }
00061 }
00062 for(i = 0; i < num_rows; ++i) {
00063 res[i] *= alpha;
00064 }
00065 }
00066
00067 void Skeleton::MatvecLT(double alpha, const double *vec,
00068 double *res, mv_mode mode) const
00069 {
00070 unsigned i, k, num_cols, num_rows;
00071 double tmp;
00072 const Matrix& U = mode == normal ? GetU() : GetV();
00073 const Matrix& V = mode == normal ? GetV() : GetU();
00074 num_cols = GetNumCols();
00075 num_rows = GetNumRows();
00076 for(i = 0; i < num_rows; ++i) {
00077 res[i] = 0.0;
00078 }
00079 for(k = 0; k < rank; ++k) {
00080 tmp = 0.0;
00081 for(i = 0; i < num_rows; ++i) {
00082 if(i < num_cols) {
00083 tmp += V.elem(i, k) * vec[i];
00084 }
00085 res[i] += tmp * U.elem(i, k);
00086 }
00087 }
00088 for(i = 0; i < num_rows; ++i) {
00089 res[i] *= alpha;
00090 }
00091 }