/* ** error: Error formula to compare two ** matrix multiplies. ** norm(C1-C2)/(macheps*norm(A)*norm(B)), ** Ci=float(A*B) ** macheps=2^(-24) in single prec. ** =2^(-53) in double prec. */ double error(double *mat1,double *mat2,int rows,int cols) { const double macheps = 1.110223024625157e-16; /* = 2^(-53) */ return l1_norm_diff(mat1,mat2,rows,cols)/ (macheps*l1_norm(mat1,rows,cols)*l1_norm(mat2,rows,cols)); }
vec2d_int mindex(const int& degree) const { int j = 0; int norm = 0; std::vector<int> temp(i_dim, 0); vec2d_int mindex_degree; while(true) { norm = l1_norm(temp); if(norm == degree) { mindex_degree.push_back(temp); } for(j = i_dim - 1 ; j >= 0 ; --j) { if(++temp[j] <= degree) break; else temp[j] = 0; } if( j < 0) break; } return mindex_degree; }
void Utility::l1_normalize(std::vector<float>& v){ float norm = l1_norm(v); if(norm == 0.f){ std::cerr << "0 norm" << std::endl; exit(1); } std::for_each(v.begin(), v.end(), [&](float& v){v /= norm;}); }
unsigned long long int min_lattice_vector(long long int * a, long long int * b) { unsigned long long int a_norm, b_norm, temp, a_minus_b, a_plus_b; long long int k = 0; long long int * t; a_norm = l1_norm(a); b_norm = l1_norm(b); //ensure a has greater norm if (a_norm < b_norm) { SWAP(a_norm,b_norm,temp) SWAP(a,b,t) } a_minus_b = lin_comb_mag(a,b,1,-1); // = |a-b| a_plus_b = lin_comb_mag(a,b,1,1); // = |a+b| if (a_minus_b < b_norm) { lin_comb(b,a,b,1,-1); // b = a - b SWAP(a_minus_b,b_norm,temp) }