Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 2922fbe3 authored by hhakim's avatar hhakim
Browse files

Update GivensFGFT skeleton.

parent d9c91526
No related branches found
No related tags found
No related merge requests found
......@@ -9,20 +9,54 @@
namespace Faust {
template<typename FPP, Device DEVICE>
template<typename FPP, Device DEVICE, typename FPP2 = float>
class GivensFGFT {
vector<Faust::MatSparse<FPP,DEVICE>> facts;
Faust::MatSparse<FPP,DEVICE> D;
Faust::MatSparse<FPP,DEVICE> C;
vector<float> err;
vector<pair<int,int>> coord_choices;
Faust::MatDense<FPP, DEVICE> L;
vector<FPP2> errs;
vector<pair<faust_unsigned_int,faust_unsigned_int>> coord_choices;
Faust::MatDense<FPP, DEVICE> Lap;
faust_unsigned_int p, q;
public:
GivensFGFT(Faust::MatDense<FPP,DEVICE>& Lap, unsigned int j);
GivensFGFT(Faust::MatDense<FPP,DEVICE>& Lap, faust_unsigned_int J);
/**
* \brief Algo. main step.
*/
void next_step();
void compute_facts();
/** \brief Algo. step 2.1.
*/
void choose_pivot();
/** \brief Algo. step 2.1.1
*
*/
void sort_L_in_C();
/** \brief Algo. step 2.2.
*/
void calc_theta();
/**
* \brief Algo. step 2.3.
*/
void update_fact();
/**
* \brief ALgo. step 2.4
*/
void update_L();
/**
* \brief Algo. step 2.5.
*/
void update_D();
/**
* \brief Algo. step 2.6.
*/
void calc_err();
};
......
template<typename FPP, Device DEVICE>
void Faust::GivensFGFT<FPP,DEVICE>::next_step()
using namespace Faust;
template<typename FPP, Device DEVICE, typename FPP2>
void GivensFGFT<FPP,DEVICE,FPP2>::next_step()
{
}
template<typename FPP, Device DEVICE, typename FPP2>
void GivensFGFT<FPP,DEVICE,FPP2>::choose_pivot()
{
//Matlab ref. code:
// [~,p] = min(C_min_row);
// q = q_candidates(p);
// coord_choices(1,j) = p;
// coord_choices(2,j) = q;
}
template<typename FPP, Device DEVICE, typename FPP2>
void GivensFGFT<FPP,DEVICE,FPP2>::sort_L_in_C()
{
// Matlab ref. code:
//************** at initialization
// for r=1:n
// for s=r+1:n
// C(r,s) = -abs(L(r,s));%-2*L(r,s)^2;
// end
// end
// [C_min_row, q_candidates] = min(C,[],2);
//
/************ at end of ite.
* for r=[p,q]
* for s=r+1:n
* C(r,s) = -abs(L(r,s));%-2*L(r,s)^2;
* end
* [C_min_row(r), q_candidates(r)] = min(C(r,:));
* end
*
* for s=[p,q]
* for r=1:s-1
* C(r,s) = -abs(L(r,s));%-2*L(r,s)^2;
* if C(r,s)<C_min_row(r)
* C_min_row(r) = C(r,s);
* q_candidates(r) = s;
* elseif q_candidates(r) == s
* [C_min_row(r), q_candidates(r)] = min(C(r,:));
* end
* end
* end
*/
}
template<typename FPP, Device DEVICE, typename FPP2>
void GivensFGFT<FPP,DEVICE,FPP2>::calc_theta()
{
// Matlab ref. code:
// theta1 = atan2(L(q,q) - L(p,p),2*L(p,q))/2 ;
// err_theta1 = (L(p,q)*cos(2*theta1) + 0.5*(L(q,q) - L(p,p))*sin(2*theta1))^2;
// theta2 = atan2(L(q,q) - L(p,p),2*L(p,q))/2 + pi/4;
// err_theta2 = (L(p,q)*cos(2*theta2) + 0.5*(L(q,q) - L(p,p))*sin(2*theta2))^2;
// if err_theta1<err_theta2
// theta=theta1;
// else
// theta=theta2;
// end
}
template<typename FPP, Device DEVICE, typename FPP2>
void GivensFGFT<FPP,DEVICE,FPP2>::update_fact()
{
// Matlab ref. code:
// S = eye(n);
// S(p,p) = cos(theta); S(p,q) = -sin(theta);
// S(q,p) = sin(theta); S(q,q) = cos(theta);
// S = sparse(S);
// facts{j} = S;
//
}
template<typename FPP, Device DEVICE, typename FPP2>
void GivensFGFT<FPP,DEVICE,FPP2>::update_L()
{
// L = S'*L*S
}
template<typename FPP, Device DEVICE>
void Faust::GivensFGFT<FPP,DEVICE>::compute_facts()
template<typename FPP, Device DEVICE, typename FPP2>
void GivensFGFT<FPP,DEVICE,FPP2>::update_D()
{
// D = spdiag(diag(L))
}
template<typename FPP, Device DEVICE, typename FPP2>
void GivensFGFT<FPP,DEVICE,FPP2>::calc_err()
{
// Matlab ref. code:
// if mod(j,100)==0
// %err(j) = norm(D-L,'fro')^2/norm(L,'fro')^2;
// err(j) = norm(D-L,'fro')^2/norm(Lap,'fro')^2;
// %err(j) = norm(D-L)/norm(Lap);
// disp(['Iter ' num2str(j) ', error = ' num2str(err(j))])
// % disp(['Number of edges: ' num2str(N_edges)])
// end
//
}
template<typename FPP, Device DEVICE>
Faust::GivensFGFT<FPP,DEVICE>::GivensFGFT(Faust::MatDense<FPP,DEVICE>& Lap, unsigned int j) : L(Lap), facts(j), D(Lap.getNbRow(), Lap.getNbCol()), C(Lap.getNbRow(), Lap.getNbRow()), err(j), coord_choices(j)
template<typename FPP, Device DEVICE, typename FPP2>
void GivensFGFT<FPP,DEVICE,FPP2>::compute_facts()
{
}
template<typename FPP, Device DEVICE, typename FPP2>
GivensFGFT<FPP,DEVICE,FPP2>::GivensFGFT(Faust::MatDense<FPP,DEVICE>& Lap, faust_unsigned_int J) : Lap(Lap), facts(J), D(Lap.getNbRow(), Lap.getNbCol()), C(Lap.getNbRow(), Lap.getNbRow()), errs(J), coord_choices(J)
{
/** Matlab ref. code:
* facts = cell(1,J);
* n=size(Lap,1);
* L=Lap;
* C = 15*ones(n);
* err=zeros(1,J);
* coord_choices = zeros(2,J);
*
*/
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment