Skip to content

Commit

Permalink
Develop (#12)
Browse files Browse the repository at this point in the history
* print the system platform

* print out the platform

* changed darwin to Darwin

* remove extra_link_args for mac

* Test the robustness of result (#11)

* Fixed the bug with omp

* fixed rescaling

* typo

* removed a print

* Removed a print from setup.py
  • Loading branch information
LeilyR authored Mar 20, 2019
1 parent 3dcd84b commit 355d495
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def get_include(): # TODO

def __extra_compile_args():
extra_compile_args = []
print("Platform is "+ platform.system())

if platform.system() == 'Darwin':
extra_compile_args = ["-std=c++11"]
Expand Down
22 changes: 16 additions & 6 deletions src/krbalancing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ kr_balancing::kr_balancing(const SparseMatrixCol & input){
I.setIdentity();
I = I*0.00001;
A = A + I;
rescaled = false;
}


Expand Down Expand Up @@ -130,12 +131,15 @@ void kr_balancing::inner_loop(){

void kr_balancing::compute_normalised_matrix(bool & rescale){
assert(A.rows() == A.cols());
A = SparseMatrixCol(A.triangularView<Eigen::Upper>());
if(rescale ==true){
if(rescale ==true && rescaled == false){
rescale_norm_vector();
rescaled = true;
}else{
A = SparseMatrixCol(A.triangularView<Eigen::Upper>());
}
#pragma omp parallel for num_threads(num_threads) schedule(dynamic)
for (int k=0; k<A.outerSize(); ++k){
#pragma omp critical
for(SparseMatrixCol::InnerIterator it(A,k); it; ++it){
it.valueRef() = it.value()*x.coeff(it.row(),0)*x.coeff(it.col(),0);
}
Expand All @@ -145,10 +149,14 @@ void kr_balancing::compute_normalised_matrix(bool & rescale){

//Rescaling the normalisation factor (x)
void kr_balancing::rescale_norm_vector(){
double original_sum = 0;
double norm_vector_sum = 0;
#pragma omp parallel for num_threads(num_threads) schedule(dynamic)
double original_sum = 0.0;
double norm_vector_sum = 0.0;
assert(A.rows() == A.cols());
A = SparseMatrixCol(A.triangularView<Eigen::Upper>());

#pragma omp parallel for num_threads(num_threads)
for (int k=0; k<A.outerSize(); ++k){
#pragma omp critical
for(SparseMatrixCol::InnerIterator it(A,k); it; ++it){
if(it.row()==it.col()){
original_sum += it.value();
Expand All @@ -159,6 +167,7 @@ void kr_balancing::rescale_norm_vector(){
}
}
}

std::cout << "normalisation factor is "<< std::sqrt(norm_vector_sum/original_sum) <<std::endl;
x /= std::sqrt(norm_vector_sum/original_sum);

Expand All @@ -172,8 +181,9 @@ const SparseMatrixCol* kr_balancing::get_normalised_matrix(bool & rescale){


const SparseMatrixCol* kr_balancing::get_normalisation_vector(bool & rescale){
if(rescale ==true){
if(rescale ==true && rescaled == false){
rescale_norm_vector();
rescaled = true;
}
return &x;
}
Expand Down
1 change: 1 addition & 0 deletions src/krbalancing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class kr_balancing{
SparseMatrixCol x;
Eigen::SparseVector<double> rk;
SparseMatrixCol output;
bool rescaled;
};

#endif

0 comments on commit 355d495

Please sign in to comment.