ring_elem GF::from_long(long n) const { long m1 = n % characteristic(); if (m1 < 0) m1 += characteristic(); int m = static_cast<int>(m1); m = _from_int_table[m]; return ring_elem(m); }
ring_elem GF::from_int(mpz_ptr n) const { mpz_t result; mpz_init(result); mpz_mod_ui(result, n, characteristic()); long m1 = mpz_get_si(result); mpz_clear(result); if (m1 < 0) m1 += characteristic(); int m = static_cast<int>(m1); m = _from_int_table[m]; return ring_elem(m); }
void GF::internal_add_to(ring_elem &f, ring_elem &g) const { if (g == _ZERO) return; if (f == _ZERO) f = g; else { int a = f.int_val; int b = g.int_val; int n = a-b; if (n > 0) { if (n == _MINUS_ONE) f = _ZERO; else f = modulus_add(b, _one_table[n], Q1_); } else if (n < 0) { if (-n == _MINUS_ONE) f = _ZERO; else f = modulus_add(a, _one_table[-n], Q1_); } else { if (characteristic() == 2) f = _ZERO; else f = modulus_add(a, _one_table[_ONE], Q1_); } } }
void ARingTower::text_out(buffer &o) const { o << "Tower[ZZ/" << characteristic() << "["; for (size_t i = 0; i < n_vars() - 1; i++) o << varNames()[i] << ","; if (n_vars() > 0) o << varNames()[n_vars() - 1]; o << "]]"; extensions_text_out(o); }
QList<QLowEnergyCharacteristic> QLowEnergyService::characteristics() const { QList<QLowEnergyCharacteristic> results; QList<QLowEnergyHandle> handles = d_ptr->characteristicList.keys(); std::sort(handles.begin(), handles.end()); foreach (const QLowEnergyHandle &handle, handles) { QLowEnergyCharacteristic characteristic(d_ptr, handle); results.append(characteristic); }
/** * @brief Upwind Riemann solver * * @param pL Perturbation pressure left state * @param rhoL Perturbation density left state * @param pR Perturbation pressure right state * @param rhoR Perturbation density right state * @param uL x perturbation velocity component left state * @param uR x perturbation velocity component right state * @param vL y perturbation velocity component left state * @param vR y perturbation velocity component right state * @param wL z perturbation velocity component left state * @param wR z perturbation velocity component right state * @param p0 Base pressure * @param rho0 Base density * @param u0 Base x velocity component * @param v0 Base y velocity component * @param w0 Base z velocity component * @param pF Computed Riemann flux for perturbation pressure * @param rhoF Computed Riemann flux for perturbation density * @param uF Computed Riemann flux for x perturbation velocity component * @param vF Computed Riemann flux for y perturbation velocity component * @param wF Computed Riemann flux for z perturbation velocity component */ void UpwindSolver::v_PointSolve( NekDouble pL, NekDouble rhoL, NekDouble uL, NekDouble vL, NekDouble wL, NekDouble pR, NekDouble rhoR, NekDouble uR, NekDouble vR, NekDouble wR, NekDouble p0, NekDouble rho0, NekDouble u0, NekDouble v0, NekDouble w0, NekDouble &pF, NekDouble &rhoF, NekDouble &uF, NekDouble &vF, NekDouble &wF) { // fetch params ASSERTL1(CheckParams("Gamma"), "Gamma not defined."); const NekDouble &gamma = m_params["Gamma"](); // Speed of sound NekDouble c = sqrt(gamma * p0 / rho0); Array<OneD, NekDouble> characteristic(4); Array<OneD, NekDouble> W(2); Array<OneD, NekDouble> lambda(2); // compute the wave speeds lambda[0] = u0 + c; lambda[1] = u0 - c; // calculate the caracteristic variables //left characteristics characteristic[0] = pL/2 + uL*c*rho0/2; characteristic[1] = pL/2 - uL*c*rho0/2; //right characteristics characteristic[2] = pR/2 + uR*c*rho0/2; characteristic[3] = pR/2 - uR*c*rho0/2; //take left or right value of characteristic variable for (int j = 0; j < 2; j++) { if (lambda[j] >= 0) { W[j] = characteristic[j]; } if (lambda[j] < 0) { W[j] = characteristic[j+2]; } } //calculate conservative variables from characteristics NekDouble p = W[0] + W[1]; NekDouble u = (W[0] - W[1])/(c*rho0); // assemble the fluxes pF = rho0*u + u0*p/(c*c); uF = p/rho0 + u0*u + v0*vL + w0*wL; vF = 0.0; wF = 0.0; }
std::vector<RingElem> BM_modp(const SparsePolyRing& P, const ConstMatrixView& pts) { ring Fp = CoeffRing(P); const int NumPts = NumRows(pts); const int NumVars = NumCols(pts); const long p = ConvertTo<long>(characteristic(Fp)); FF FFp = FFctor(p); FFselect(FFp); FFelem** points_p = (FFelem**)malloc(NumPts*sizeof(FFelem*)); for (int i=0; i < NumPts; ++i) { points_p[i] = (FFelem*)malloc(NumVars*sizeof(FFelem)); for (int j=0; j < NumVars; ++j) { points_p[i][j] = ConvertTo<FFelem>(LeastNNegRemainder(ConvertTo<BigInt>(pts(i,j)), p)); } } pp_cmp_PPM = &PPM(P); const BM modp = BM_affine_mod_p(NumVars, NumPts, points_p, pp_cmp); if (modp == NULL) return std::vector<RingElem>(); // empty list means error const int GBsize = modp->GBsize; std::vector<RingElem> GB(GBsize); vector<long> expv(NumVars); for (int i=0; i < GBsize; ++i) { for (int var = 0; var < NumVars; ++var) expv[var] = modp->pp[modp->GB[i]][var]; RingElem GBelem = monomial(P, 1, expv); for (int j=0; j < NumPts; ++j) { const int c = modp->M[modp->GB[i]][j+NumPts]; if (c == 0) continue; for (int var = 0; var < NumVars; ++var) expv[var] = modp->pp[modp->sep[j]][var]; GBelem += monomial(P, c, expv); } GB[i] = GBelem; } BM_dtor(modp); return GB; }
void ARingGFFlint::fromSmallIntegerCoefficients(ElementType& result, const std::vector<long>& poly) const { fq_nmod_t f; fq_nmod_init(f, mBigContext); #if 0 printf("input = "); for (long i=0; i<poly.size(); i++) printf("%ld ", poly[i]); printf("\n"); #endif for (long i=poly.size()-1; i>=0; i--) { long a = poly[i]; if (a == 0) continue; if (a < 0) a += characteristic(); nmod_poly_set_coeff_ui(f, i, a); } #if 0 printf(" result before reduction = "); fq_nmod_print_pretty(f, mBigContext); printf("\n"); #endif fq_nmod_reduce(f, mBigContext); #if 0 printf(" result = "); fq_nmod_print_pretty(f, mBigContext); printf("\n"); #endif fq_zech_set_fq_nmod(&result, f, mContext); #if 0 printf(" zech result = %lu", result.value); printf("\n"); #endif fq_nmod_clear(f, mBigContext); }
int main(int argc, char** argv) { int i; int j; int Ymax = 235; int Ymin = 16; int row,col; int sum = 0; int id = 0; double temp; double Cx = 109.38; double Cy = 152.02; double theta = 2.53; double ecx = 1.60; double ecy = 2.41; double a = 25.39; double b = 14.03; double t; double lea = 0; imt_l* H; imt_l* y; imt_c* resultr; imt_c* resultg; imt_c* resultb; imt_c* bi_graph; imt_c* result; imt_c* h; linux_mem_init(); rgb_mt_t* image = imread(argv[1]); if(image == NULL) { exit(2); } row = image->r->row; col = image->r->col; H = create_zero_l(3,3); resultr = create_zero_c(row,col); resultg = create_zero_c(row,col); resultb = create_zero_c(row,col); y = create_zero_l(row,col); medfilt2(image->r,resultr); move_c(resultr,image->r); medfilt2(image->g,resultg); move_c(resultg,image->g); medfilt2(image->b,resultb); move_c(resultb,image->b); imshow("blur.bmp",image); set_pixel_l(H,1,1,65.4810/255); set_pixel_l(H,1,2,128.5530/255); set_pixel_l(H,1,3,24.9660/255); set_pixel_l(H,2,1,-37.7970/255); set_pixel_l(H,2,2,-74.2030/255); set_pixel_l(H,2,3,112.0000/255); set_pixel_l(H,3,1,112.0000/255); set_pixel_l(H,3,2,-93.7860/255); set_pixel_l(H,3,3,-18.2140/255); for(i = 1;i <= row;i ++) for(j = 1;j <= col;j ++) { temp = get_pixel_l(H,1,1) * (double)get_pixel_c(image->r,i,j) + get_pixel_l(H,1,2) * (double)get_pixel_c(image->g,i,j) + get_pixel_l(H,1,3) * (double)get_pixel_c(image->b,i,j) + 16; set_pixel_c(resultr,i,j,(unsigned char)temp); temp = get_pixel_l(H,2,1) * (double)get_pixel_c(image->r,i,j) + get_pixel_l(H,2,2) * (double)get_pixel_c(image->g,i,j) + get_pixel_l(H,2,3) * (double)get_pixel_c(image->b,i,j) + 128; set_pixel_c(resultg,i,j,(unsigned char)temp); temp = get_pixel_l(H,3,1) * (double)get_pixel_c(image->r,i,j) + get_pixel_l(H,3,2) * (double)get_pixel_c(image->g,i,j) + get_pixel_l(H,3,3) * (double)get_pixel_c(image->b,i,j) + 128; set_pixel_c(resultb,i,j,(unsigned char)temp); } clear(H); bi_graph = create_zero_c(row,col); for(i = 1;i <= row;i ++) for(j = 1;j <= col;j ++) { temp = cos(theta) * ((double)get_pixel_c(resultg,i,j) - Cx) + sin(theta) * ((double)get_pixel_c(resultb,i,j) - Cy); set_pixel_l(y,i,j,-sin(theta)*((double)get_pixel_c(resultg,i,j) - Cx) + cos(theta)*((double)get_pixel_c(resultb,i,j) - Cy)); lea = (temp - ecx) * (temp - ecx) / (a * a) + (get_pixel_l(y,i,j) - ecy) * (get_pixel_l(y,i,j) - ecy) / b / b; if(lea < 1.0) { set_pixel_c(bi_graph,i,j,255); } if(get_pixel_c(resultr,i,j) <= 80) { set_pixel_c(bi_graph,i,j,0); } } clear(resultr); clear(resultg); clear(resultb); image->r = bi_graph; image->g = bi_graph; image->b = bi_graph; imshow("bigraph.bmp",image); h = create_zero_c(3,3); set_pixel_c(h,1,1,255); set_pixel_c(h,1,2,255); set_pixel_c(h,1,3,255); set_pixel_c(h,2,1,255); set_pixel_c(h,2,2,255); set_pixel_c(h,2,3,255); set_pixel_c(h,3,1,255); set_pixel_c(h,3,2,255); set_pixel_c(h,3,3,255); result = imrode(bi_graph,h); move_c(result,bi_graph); clear(result); clear(h); h = create_zero_c(12,12); for(i = 1;i <= 12;i ++) for(j = 1;j <= 12;j ++) set_pixel_c(h,i,j,255); result = imdilate(bi_graph,h); move_c(result,bi_graph); clear(result); clear(h); bwareaopen(bi_graph,row * col / 10); for(i = 1;i <= row;i ++) { for(j = 1;j <= col;j ++) { if(get_pixel_c(bi_graph,i,j) == 0) set_pixel_c(bi_graph,i,j,255); else set_pixel_c(bi_graph,i,j,0); } } bwareaopen(bi_graph,row * col / 10); for(i = 1;i <= row;i ++) { for(j = 1;j <= col;j ++) { if(get_pixel_c(bi_graph,i,j) == 0) set_pixel_c(bi_graph,i,j,255); else set_pixel_c(bi_graph,i,j,0); } } result = focus(bi_graph); id = identifier(result); image->r = bi_graph; image->g = bi_graph; image->b = bi_graph; imshow("result.bmp",image); clear(bi_graph); image = imread(argv[1]); for(i = 1;i <= row;i ++) for(j = 1;j < col;j ++) { if(i <= l1 && i >= l0 && j <= n1 && j >= n0) { if(get_pixel_c(result,i - l0,j - n0) == 255) { sum ++; set_pixel_c(image->r,i,j,0); set_pixel_c(image->g,i,j,255); set_pixel_c(image->b,i,j,0); } } if(((j > n0 - 5 && j < n0 + 5) || (j < n1 + 5 && j > n1 - 5)) && ((i < l1 + 5 && i > l1 - 5) || (i > l0 - 5&& i < l0 + 5))) { set_pixel_c(image->r,i,j,255); set_pixel_c(image->g,i,j,0); set_pixel_c(image->b,i,j,0); } } imshow("focus.bmp",image); m_stat(); characteristic(); if(id == 0) { printf("Unknown\n"); } else if(id == 1) { printf("Rock!\n"); } else if(id == 2) { printf("Scissors!\n"); } else if(id == 3) { printf("Paper!\n"); } return 0; }
void set_from_mpz(ElementType& result, mpz_srcptr a) const { int b = static_cast<int>(mpz_fdiv_ui(a, characteristic())); set_from_long(result, b); }
void set_from_long(ElementType& result, long a) const { long a1 = a % characteristic(); if (a1 < 0) a1 += characteristic(); fq_zech_set_ui(&result, a1, mContext); }
void ARingZZpFlint::text_out(buffer &o) const { o << "AZZFlint/" << characteristic(); }
long coerceToLongInteger(const elem& f) const { long result = static_cast<long>(f); if (result > characteristic()/2) result -= characteristic(); return result; }
void set_from_mpz(elem &result, mpz_ptr a) const { int b = static_cast<int>(mpz_fdiv_ui(a, characteristic())); result = mGF.fromZZTable(b); }
bool GF::initialize_GF(const RingElement *prim) { // set the GF ring tables. Returns false if there is an error. _primitive_element = prim; _originalR = prim->get_ring()->cast_to_PolynomialRing(); initialize_ring(_originalR->characteristic(), PolyRing::get_trivial_poly_ring()); declare_field(); int i,j; if (_originalR->n_quotients() != 1) { ERROR("rawGaloisField expected an element of a quotient ring of the form ZZ/p[x]/(f)"); return false; } ring_elem f = _originalR->quotient_element(0); Nterm *t = f; int n = _originalR->getMonoid()->primary_degree(t->monom); Q_ = static_cast<int>(characteristic()); for (i=1; i<n; i++) Q_ *= static_cast<int>(characteristic()); Qexp_ = n; Q1_ = Q_-1; _ZERO = 0; _ONE = Q1_; _MINUS_ONE = (characteristic() == 2 ? _ONE : Q1_/2); // Get ready to create the 'one_table' array<ring_elem> polys; polys.append(_originalR->from_long(0)); ring_elem primelem = prim->get_value(); polys.append(_originalR->copy(primelem)); ring_elem oneR = _originalR->one(); _x_exponent = -1; ring_elem x = _originalR->var(0); if (_originalR->is_equal(primelem, x)) _x_exponent = 1; for (i=2; i<Q_; i++) { ring_elem g = _originalR->mult(polys[i-1], primelem); polys.append(g); if (_originalR->is_equal(g, oneR)) break; if (_originalR->is_equal(g, x)) _x_exponent = i; } if (polys.length() != Q_) { ERROR("GF: primitive element expected"); return false; } assert(_x_exponent >= 0); // Set 'one_table'. _one_table = newarray_atomic(int,Q_); _one_table[0] = Q_-1; for (i=1; i<=Q_-1; i++) { if (system_interrupted()) return false; ring_elem f1 = _originalR->add(polys[i], oneR); for (j=1; j<=Q_-1; j++) if (_originalR->is_equal(f1, polys[j])) break; _one_table[i] = j; } // Create the Z/P ---> GF(Q) inclusion map _from_int_table = newarray_atomic(int,characteristic()); int a = _ONE; _from_int_table[0] = _ZERO; for (i=1; i<characteristic(); i++) { _from_int_table[i] = a; a = _one_table[a]; } zeroV = from_long(0); oneV = from_long(1); minus_oneV = from_long(-1); // M2::GaloisFieldTable G(*_originalR, primelem); // G.display(std::cout); return true; }
void random(ElementType &result) const { result = rawRandomInt((int32_t)characteristic()); }
void ARingZZp::text_out(std::ostream& o) const { o << "AZZ/" << characteristic(); }
void set_from_int(elem &result, int a) const { a = a % characteristic(); if (a < 0) a += characteristic(); result = mGF.fromZZTable(a); }
void ARingGFFlint::text_out(buffer &o) const { o << "GF(" << characteristic() << "^" << dimension() << ",Flint)"; }