int solver_gauss(void *A, void *B) { void *X; if(dim1(A) != dim1(B)) return 0; { static int **Y; if(-1 == dim2(B)){ ary2(Y,2,1); if(NULL == Y) return 0; cp(B,Y[1]); cp(Y,X); }else cp(B,X); } if(siz(A) == sizeof(float) && siz(B) == sizeof(float)){ float **a,*api,s,**x,*b,bpi; #include "solver/fb.c" }else if(siz(A) == sizeof(float) && siz(B) == sizeof(double)){ float **a,*api;double s,**x,*b,bpi; #include "solver/fb.c" }else if(siz(A) == sizeof(double) && siz(B) == sizeof(float)){ double **a,*api,s;float **x,*b,bpi; #include "solver/fb.c" }else if(siz(A) == sizeof(double) && siz(B) == sizeof(double)){ double **a,*api,s,**x,*b,bpi; #include "solver/fb.c" }else{ fprintf(stderr,"solver_gauss: not supported\n"); exit(1);} return 0; }
inline TR TrX(const T1& rho1, arma::uvec sys, arma::uword dim = 2) { const auto& p = as_Mat(rho1); #ifndef QICLIB_NO_DEBUG bool checkV = true; if (p.n_cols == 1) checkV = false; if (p.n_elem == 0) throw Exception("qic::TrX", Exception::type::ZERO_SIZE); if (checkV) if (p.n_rows != p.n_cols) throw Exception("qic::TrX", Exception::type::MATRIX_NOT_SQUARE_OR_CVECTOR); if (dim == 0) throw Exception("qic::TrX", Exception::type::INVALID_DIMS); #endif arma::uword n = static_cast<arma::uword>(std::llround(std::log(p.n_rows) / std::log(dim))); arma::uvec dim2(n); dim2.fill(dim); return TrX(p, std::move(sys), std::move(dim2)); }
int matprop_halfbw(void *A) { if(dim2(A) != dim1(A)||dim2(A) < 1||dim1(A) < 1||siz(A) < 1) return 0; if(siz(A) == sizeof(float)){ static float **a; a = (float **)A; #include "matprop/halfbw.c" } if(siz(A) == sizeof(double)){ static double **a; a = (double **)A; #include "matprop/halfbw.c" } return 0; }
template<class T> std::string Data::Matrix<T>::print( const std::string & label , const int nrow , const int ncol) const { int arow = nrow == 0 || nrow > dim1() ? dim1() : nrow ; int acol = ncol == 0 || ncol > dim2() ? dim2() : ncol ; std::stringstream ss; if ( label != "" ) ss << label << "\n"; for (int r=0;r<arow;r++) { ss << " [" ; for (int c=0;c<acol;c++) ss << " " << (*this)(r,c) ; ss << " ]\n"; } return ss.str(); }
static int *LU(void *A) { if(dim2(A) == dim1(A)) if(siz(A) == sizeof(float)){ float nrm,**a,aik,*apk,*ai,apkk; #include "solver/LU.c" }else if(siz(A) == sizeof(double)){ double nrm,**a,aik,*apk,*ai,apkk; #include "solver/LU.c" } return NULL; }
int solver_inv(void *A) { if(dim2(A) == dim1(A)) if(siz(A) == sizeof(float)){ static float **a,**e; #include "solver/inv.c" }else if(siz(A) == sizeof(double)){ static double **a,**e; #include "solver/inv.c" }else{ fprintf(stderr,"solver_inv: not supported\n"); exit(1);} return 0; }
void femlib_ary2(void** v, long m_1, long n_1, size_t o) { if(*v == NULL){ new_ary2(v,m_1,n_1,o); return;} if(m_1==dim2(*v)+1 && n_1==dim1(*v)+1) return; del_ary2(v); if(m_1!=0 && n_1!=0) new_ary2(v,m_1,n_1,o); }
static void del_ary2(void** v) { dim* r; char** a; long i, m; a = *v; m = dim2(a); for(i=0;i<=m;i++) free(a[i]); r = *v; r--; free(r); *v = NULL; }
// out_map was initialized to 0 already int segment1(image *in_image, image *out_map, int min_dist_th) { int n_bands = in_image->num_of_bands; int n_lines = in_image->num_of_lines; int n_cols = in_image->num_of_samples; int n_seg = 0; // number of segments, first segment is named 1, second 2, and so on float pel_dist, min_dist; // measurement of the distance between two pixels imgpel **map = (imgpel **) dim2 (n_lines, n_cols, sizeof(imgpel)); for(int y=0; y<n_lines; y++) { for(int x=0; x<n_cols; x++) { if(map[y][x] == 0) // non-segmented pixel, check its eight neighbors for a potential merge; if no merge, start a new segment { min_dist = (float) LARGE_FLOAT; for(int j=y-1; j<=y+1; j++) { for(int i=x-1; i<=x+1; i++) { if(j>=0 && j<n_lines && i>=0 && i<n_cols && (j!=y || i!=x) && (map[j][i]>0)) { pel_dist = 0; for(int k=0; k<n_bands; k++) pel_dist += ((in_image->IMG[k][y][x] - in_image->IMG[k][j][i]) * (in_image->IMG[k][y][x] - in_image->IMG[k][j][i])); if(pel_dist < min_dist) { min_dist = pel_dist; map[y][x] = map[j][i]; } } } } if (min_dist > min_dist_th * n_bands) { n_seg += 1; map[y][x] = (imgpel) n_seg; } } } } for(int y=0; y<n_lines; y++) { for(int x=0; x<n_cols; x++) { int boundary_flag = 0; for(int j=y-1; j<=y+1; j++) { for(int i=x-1; i<=x+1; i++) { int jj = clip(0, n_lines-1, j); int ii = clip(0, n_cols-1, i); if(map[jj][ii] != map[y][x]) boundary_flag = 1; } } for(int k=0; k<n_bands; k++) out_map->IMG[k][y][x] = ((boundary_flag==1) ? 0xFFFF : in_image->IMG[k][y][x]); } } free2((char **)map); return n_seg; }
TR discord3_reg(const T1& rho1, arma::uword nodal, arma::uvec dim) { const auto& rho = as_Mat(rho1); arma::uword party_no = dim.n_elem; arma::uword dim1 = arma::prod(dim); #ifndef QICLIB_NO_DEBUG if (rho.n_elem == 0) throw Exception("qic::discord3_reg", Exception::type::ZERO_SIZE); if (rho.n_rows != rho.n_cols) throw Exception("qic::discord3_reg", Exception::type::MATRIX_NOT_SQUARE); if (any(dim == 0)) throw Exception("qic::discord3_reg", Exception::type::INVALID_DIMS); if (dim1 != rho.n_rows) throw Exception("qic::discord3_reg", Exception::type::DIMS_MISMATCH_MATRIX); if (nodal <= 0 || nodal > party_no) throw Exception("qic::discord3_reg", "Invalid measured party index"); if (dim(nodal - 1) != 3) throw Exception("qic::discord3_reg", "Measured party is not qutrit"); #endif arma::uvec party = arma::zeros<arma::uvec>(party_no); for (arma::uword i = 0; i < party_no; ++i) party.at(i) = i + 1; arma::uvec rest = party; rest.shed_row(nodal - 1); auto rho_A = TrX(rho, rest, dim); auto rho_B = TrX(rho, {nodal}, dim); auto S_A = entropy(rho_A); auto S_B = entropy(rho_B); auto S_A_B = entropy(rho); auto I1 = S_A + S_B - S_A_B; dim1 /= 3; arma::uword dim2(1); for (arma::uword i = 0; i < nodal - 1; ++i) dim2 *= dim.at(i); arma::uword dim3(1); for (arma::uword i = nodal; i < party_no; ++i) dim3 *= dim.at(i); arma::Mat<trait::pT<T1> > eye2 = arma::eye<arma::Mat<trait::pT<T1> > >(dim1, dim1); arma::Mat<trait::pT<T1> > eye3 = arma::eye<arma::Mat<trait::pT<T1> > >(dim2, dim2); arma::Mat<trait::pT<T1> > eye4 = arma::eye<arma::Mat<trait::pT<T1> > >(dim3, dim3); typename arma::Col<trait::pT<T1> >::template fixed<3> disc; for (arma::uword i = 0; i < 3; ++i) { arma::Mat<std::complex<trait::pT<T1> > > proj1 = SPM<trait::pT<T1> >::get_instance().proj3.at(0, i + 1); arma::Mat<std::complex<trait::pT<T1> > > proj2 = SPM<trait::pT<T1> >::get_instance().proj3.at(1, i + 1); arma::Mat<std::complex<trait::pT<T1> > > proj3 = SPM<trait::pT<T1> >::get_instance().proj3.at(2, i + 1); if (nodal == 1) { proj1 = kron(proj1, eye2); proj2 = kron(proj2, eye2); proj3 = kron(proj3, eye2); } else if (party_no == nodal) { proj1 = kron(eye2, proj1); proj2 = kron(eye2, proj2); proj3 = kron(eye2, proj3); } else { proj1 = kron(kron(eye3, proj1), eye4); proj2 = kron(kron(eye3, proj2), eye4); proj3 = kron(kron(eye3, proj3), eye4); } arma::Mat<std::complex<trait::pT<T1> > > rho_1 = (proj1 * rho * proj1); arma::Mat<std::complex<trait::pT<T1> > > rho_2 = (proj2 * rho * proj2); arma::Mat<std::complex<trait::pT<T1> > > rho_3 = (proj3 * rho * proj3); trait::pT<T1> p1 = std::real(arma::trace(rho_1)); trait::pT<T1> p2 = std::real(arma::trace(rho_2)); trait::pT<T1> p3 = std::real(arma::trace(rho_3)); trait::pT<T1> S_max = 0.0; if (p1 > _precision::eps<trait::pT<T1> >::value) { rho_1 /= p1; S_max += p1 * entropy(rho_1); } if (p2 > _precision::eps<trait::pT<T1> >::value) { rho_2 /= p2; S_max += p2 * entropy(rho_2); } if (p3 > _precision::eps<trait::pT<T1> >::value) { rho_3 /= p3; S_max += p3 * entropy(rho_3); } disc.at(i) = I1 - (S_B - S_max); } return disc; }
// return minor dimension size_type dim2() const { return dim2(orientation()); }