// static void Viterbi::ExcludeAlignment(ViterbiMatrix * matrix,HMMSimd* q_four, HMMSimd* t_four,int elem, int * i_steps, int * j_steps, int nsteps){ const HMM * q = (const HMM *) q_four->GetHMM(elem); const HMM * t = (const HMM *) t_four->GetHMM(elem); // Exclude cells in direct neighbourhood from all further alignments for(int step=1;step < nsteps;step++){ int i=i_steps[step]; int j=j_steps[step]; for (int ii=imax(i- VITERBI_PATH_WIDTH,1); ii<=imin(i+ VITERBI_PATH_WIDTH,q->L); ++ii){ matrix->setCellOff(ii, j, elem, true); } for (int jj=imax(j- VITERBI_PATH_WIDTH,1); jj<=imin(j+ VITERBI_PATH_WIDTH,t->L); ++jj){ matrix->setCellOff(i, jj, elem, true); } } }
int sc_hist_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag) { scr_stat *scp; int error; switch (cmd) { case CONS_HISTORY: /* set history size */ scp = SC_STAT(tp->t_dev); if (*(int *)data <= 0) return EINVAL; if (scp->status & BUFFER_SAVED) return EBUSY; DPRINTF(5, ("lines:%d, ysize:%d, pool:%d\n", *(int *)data, scp->ysize, extra_history_size)); error = sc_alloc_history_buffer(scp, imax(*(int *)data, scp->ysize), scp->ysize, TRUE); DPRINTF(5, ("error:%d, rows:%d, pool:%d\n", error, sc_vtb_rows(scp->history), extra_history_size)); return error; case CONS_CLRHIST: scp = SC_STAT(tp->t_dev); sc_vtb_clear(scp->history, scp->sc->scr_map[0x20], SC_NORM_ATTR << 8); return 0; } return ENOIOCTL; }
void init_contexts (Slice *currSlice) { MotionInfoContexts* mc = currSlice->mot_ctx; TextureInfoContexts* tc = currSlice->tex_ctx; int i, j; int qp = imax(0, currSlice->qp); //p_Vid->qp); int model_number = currSlice->model_number; //printf("%d -", p_Vid->currentSlice->model_number); //--- motion coding contexts --- if ((currSlice->slice_type == I_SLICE)||(currSlice->slice_type == SI_SLICE)) { IBIARI_CTX_INIT2 (3, NUM_MB_TYPE_CTX, mc->mb_type_contexts, INIT_MB_TYPE, model_number, qp); IBIARI_CTX_INIT2 (2, NUM_B8_TYPE_CTX, mc->b8_type_contexts, INIT_B8_TYPE, model_number, qp); IBIARI_CTX_INIT2 (2, NUM_MV_RES_CTX, mc->mv_res_contexts, INIT_MV_RES, model_number, qp); IBIARI_CTX_INIT2 (2, NUM_REF_NO_CTX, mc->ref_no_contexts, INIT_REF_NO, model_number, qp); IBIARI_CTX_INIT1 ( NUM_DELTA_QP_CTX, mc->delta_qp_contexts, INIT_DELTA_QP, model_number, qp); IBIARI_CTX_INIT1 ( NUM_MB_AFF_CTX, mc->mb_aff_contexts, INIT_MB_AFF, model_number, qp); //--- texture coding contexts --- IBIARI_CTX_INIT1 ( NUM_TRANSFORM_SIZE_CTX, tc->transform_size_contexts, INIT_TRANSFORM_SIZE, model_number, qp); IBIARI_CTX_INIT1 ( NUM_IPR_CTX, tc->ipr_contexts, INIT_IPR, model_number, qp); IBIARI_CTX_INIT1 ( NUM_CIPR_CTX, tc->cipr_contexts, INIT_CIPR, model_number, qp); IBIARI_CTX_INIT2 (3, NUM_CBP_CTX, tc->cbp_contexts, INIT_CBP, model_number, qp); IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_BCBP_CTX, tc->bcbp_contexts, INIT_BCBP, model_number, qp); IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_MAP_CTX, tc->map_contexts[0], INIT_MAP, model_number, qp); #if ENABLE_FIELD_CTX IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_MAP_CTX, tc->map_contexts[1], INIT_FLD_MAP, model_number, qp); IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_LAST_CTX, tc->last_contexts[1], INIT_FLD_LAST, model_number, qp); #endif IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_LAST_CTX, tc->last_contexts[0], INIT_LAST, model_number, qp); IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_ONE_CTX, tc->one_contexts, INIT_ONE, model_number, qp); IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_ABS_CTX, tc->abs_contexts, INIT_ABS, model_number, qp); } else { PBIARI_CTX_INIT2 (3, NUM_MB_TYPE_CTX, mc->mb_type_contexts, INIT_MB_TYPE, model_number, qp); PBIARI_CTX_INIT2 (2, NUM_B8_TYPE_CTX, mc->b8_type_contexts, INIT_B8_TYPE, model_number, qp); PBIARI_CTX_INIT2 (2, NUM_MV_RES_CTX, mc->mv_res_contexts, INIT_MV_RES, model_number, qp); PBIARI_CTX_INIT2 (2, NUM_REF_NO_CTX, mc->ref_no_contexts, INIT_REF_NO, model_number, qp); PBIARI_CTX_INIT1 ( NUM_DELTA_QP_CTX, mc->delta_qp_contexts, INIT_DELTA_QP, model_number, qp); PBIARI_CTX_INIT1 ( NUM_MB_AFF_CTX, mc->mb_aff_contexts, INIT_MB_AFF, model_number, qp); //--- texture coding contexts --- PBIARI_CTX_INIT1 ( NUM_TRANSFORM_SIZE_CTX, tc->transform_size_contexts, INIT_TRANSFORM_SIZE, model_number, qp); PBIARI_CTX_INIT1 ( NUM_IPR_CTX, tc->ipr_contexts, INIT_IPR, model_number, qp); PBIARI_CTX_INIT1 ( NUM_CIPR_CTX, tc->cipr_contexts, INIT_CIPR, model_number, qp); PBIARI_CTX_INIT2 (3, NUM_CBP_CTX, tc->cbp_contexts, INIT_CBP, model_number, qp); PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_BCBP_CTX, tc->bcbp_contexts, INIT_BCBP, model_number, qp); PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_MAP_CTX, tc->map_contexts[0], INIT_MAP, model_number, qp); #if ENABLE_FIELD_CTX PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_MAP_CTX, tc->map_contexts[1], INIT_FLD_MAP, model_number, qp); PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_LAST_CTX, tc->last_contexts[1], INIT_FLD_LAST, model_number, qp); #endif PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_LAST_CTX, tc->last_contexts[0], INIT_LAST, model_number, qp); PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_ONE_CTX, tc->one_contexts, INIT_ONE, model_number, qp); PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_ABS_CTX, tc->abs_contexts, INIT_ABS, model_number, qp); } }
Float tweedie_logW(Float y, Float phi, Float p){ bool ok = (0 < y) && (0 < phi) && (1 < p) && (p < 2); if (!ok) return NAN; Float p1 = p - 1.0, p2 = 2.0 - p; Float a = - p2 / p1, a1 = 1.0 / p1; Float cc, w, sum_ww = 0.0, ww_max ; double j; /* only need the lower bound and the # terms to be stored */ int jh, jl, jd; double jmax = 0; Float logz = 0; /* compute jmax for the given y > 0*/ cc = a * log(p1) - log(p2); jmax = asDouble( fmax2(1.0, pow(y, p2) / (phi * p2)) ); logz = - a * log(y) - a1 * log(phi) + cc; /* find bounds in the summation */ /* locate upper bound */ cc = logz + a1 + a * log(-a); j = jmax ; w = a1 * j ; while (1) { j += TWEEDIE_INCRE ; if (j * (cc - a1 * log(j)) < (w - TWEEDIE_DROP)) break ; } jh = ceil(j); /* locate lower bound */ j = jmax; while (1) { j -= TWEEDIE_INCRE ; if (j < 1 || j * (cc - a1 * log(j)) < w - TWEEDIE_DROP) break ; } jl = imax2(1, floor(j)) ; jd = jh - jl + 1; /* set limit for # terms in the sum */ int nterms = imin2(imax(&jd, 1), TWEEDIE_NTERM), iterm ; Float *ww = Calloc(nterms, Float) ; /* evaluate series using the finite sum*/ /* y > 0 */ sum_ww = 0.0 ; iterm = imin2(jd, nterms) ; for (int k = 0; k < iterm; k++) { j = k + jl ; ww[k] = j * logz - lgamma(1 + j) - lgamma(-a * j); } ww_max = dmax(ww, iterm) ; for (int k = 0; k < iterm; k++) sum_ww += exp(ww[k] - ww_max); Float ans = log(sum_ww) + ww_max ; Free(ww); return ans; }
static int sysctl_kern_quantum(SYSCTL_HANDLER_ARGS) { int error, new_val, period; period = 1000000 / realstathz; new_val = period * sched_slice; error = sysctl_handle_int(oidp, &new_val, 0, req); if (error != 0 || req->newptr == NULL) return (error); if (new_val <= 0) return (EINVAL); sched_slice = imax(1, (new_val + period / 2) / period); hogticks = imax(1, (2 * hz * sched_slice + realstathz / 2) / realstathz); return (0); }
RGBREF _RGBtoHSL(RGBREF lRGBColor) { BYTE R,G,B; /* input RGB values */ BYTE H,L,S; /* output HSL values */ BYTE cMax,cMin; /* max and min RGB values */ WORD Rdelta,Gdelta,Bdelta; /* intermediate value: % of spread from max*/ RGBREF hsl; R = lRGBColor.rgb.Red; /* get R, G, and B out of DWORD */ G = lRGBColor.rgb.Green; B = lRGBColor.rgb.Blue; cMax = imax( imax(R,G), B); /* calculate lightness */ cMin = imin( imin(R,G), B); L = (BYTE)((((cMax+cMin)*HSLMAX)+RGBMAX)/(2*RGBMAX)); if (cMax==cMin){ /* r=g=b --> achromatic case */ S = 0; /* saturation */ H = UNDEFINED; /* hue */ } else { /* chromatic case */ if (L <= (HSLMAX/2)) /* saturation */ S = (BYTE)((((cMax-cMin)*HSLMAX)+((cMax+cMin)/2))/(cMax+cMin)); else S = (BYTE)((((cMax-cMin)*HSLMAX)+((2*RGBMAX-cMax-cMin)/2))/(2*RGBMAX-cMax-cMin)); /* hue */ Rdelta = (WORD)((((cMax-R)*(HSLMAX/6)) + ((cMax-cMin)/2) ) / (cMax-cMin)); Gdelta = (WORD)((((cMax-G)*(HSLMAX/6)) + ((cMax-cMin)/2) ) / (cMax-cMin)); Bdelta = (WORD)((((cMax-B)*(HSLMAX/6)) + ((cMax-cMin)/2) ) / (cMax-cMin)); if (R == cMax) H = (BYTE)(Bdelta - Gdelta); else if (G == cMax) H = (BYTE)((HSLMAX/3) + Rdelta - Bdelta); else /* B == cMax */ H = (BYTE)(((2*HSLMAX)/3) + Gdelta - Rdelta); // if (H < 0) H += HSLMAX; //always false // if (H > HSLMAX) H -= HSLMAX; } hsl.rgb.Red = H; hsl.rgb.Green = S; hsl.rgb.Blue = L; hsl.rgb.Alpha = 0; return hsl; }
my::DiskHole::DiskHole(const float & bigRadius, const float & smallRadius, const int & nbSlices, const int & nbCirc) :ParametricMesh("DiskHole", nbCirc+2, 2*nbSlices), _bigRadius(bigRadius), _smallRadius(smallRadius), _nbSlices(nbSlices), _nbCirc(nbCirc) { _preDiskHole(_bigRadius, _smallRadius, _nbSlices, _nbCirc); Circular coord(_bigRadius); parametricVertexInsertion(imax(), jmax(), coord); parametricTriangleInsertion(imax()-1, jmax()); computeNormalsT(); computeNormalsV(); }
static int sysctl_kern_securelvl(SYSCTL_HANDLER_ARGS) { struct prison *pr; int error, level; pr = req->td->td_ucred->cr_prison; /* * If the process is in jail, return the maximum of the global and * local levels; otherwise, return the global level. */ if (pr != NULL) { mtx_lock(&pr->pr_mtx); level = imax(securelevel, pr->pr_securelevel); mtx_unlock(&pr->pr_mtx); } else level = securelevel; error = sysctl_handle_int(oidp, &level, 0, req); if (error || !req->newptr) return (error); /* * Permit update only if the new securelevel exceeds the * global level, and local level if any. */ if (pr != NULL) { mtx_lock(&pr->pr_mtx); if (!regression_securelevel_nonmonotonic && (level < imax(securelevel, pr->pr_securelevel))) { mtx_unlock(&pr->pr_mtx); return (EPERM); } pr->pr_securelevel = level; mtx_unlock(&pr->pr_mtx); } else { mtx_lock(&securelevel_mtx); if (!regression_securelevel_nonmonotonic && (level < securelevel)) { mtx_unlock(&securelevel_mtx); return (EPERM); } securelevel = level; mtx_unlock(&securelevel_mtx); } return (error); }
/*! ************************************************************************ * \brief * Initialization of GOP structure. * ************************************************************************ */ void init_gop_structure() { int max_gopsize = input->HierarchicalCoding != 3 ? input->successive_Bframe : input->jumpd; gop_structure = calloc(imax(10,max_gopsize), sizeof (GOP_DATA)); // +1 for reordering if (NULL==gop_structure) no_mem_exit("init_gop_structure: gop_structure"); }
/*! ************************************************************************ * \brief * Initialization of GOP structure. * ************************************************************************ */ void init_gop_structure(VideoParameters *p_Vid, InputParameters *p_Inp) { int max_gopsize = p_Inp->NumberBFrames; p_Vid->gop_structure = calloc(imax(10,max_gopsize), sizeof (GOP_DATA)); // +1 for reordering if (NULL==p_Vid->gop_structure) no_mem_exit("init_gop_structure: gop_structure"); }
void RenderableChunk::set(int x, int y, int z, block_type type) { uint16_t prev = blk[x][y][z].type; blk[x][y][z] = type; if (!prev) { // assume i'm adding a block block_counter++; } if (!type.type) { // pysch i'm actually not adding a block block_counter--; if (prev) { // i removed a block. dude... bool anyMatchingLower = (x == lower_bound.x) || (y == lower_bound.y) || (z == lower_bound.z); bool anyMatchingUpper = (x == upper_bound.x) || (y == upper_bound.y) || (z == upper_bound.z); if (anyMatchingLower || anyMatchingUpper) { // we removed a block on the periphery. update dimensions! update_dimensions(); } } } else { // update lower_bound, upper_bound lower_bound.x = imin(x, lower_bound.x); lower_bound.y = imin(y, lower_bound.y); lower_bound.z = imin(z, lower_bound.z); upper_bound.x = imax(x, upper_bound.x); upper_bound.y = imax(y, upper_bound.y); upper_bound.z = imax(z, upper_bound.z); } // When updating blocks at the edge of this chunk, // visibility of blocks in the neighbouring chunk might change. if(x == 0 && left) left->changed = true; if(x == CX - 1 && right) right->changed = true; if(y == 0 && below) below->changed = true; if(y == CY - 1 && above) above->changed = true; if(z == 0 && front) front->changed = true; if(z == CZ - 1 && back) back->changed = true; changed = true; }
int main(void) { int ar[SIZE] = {1, 9, 3, 14, 5}; int max; max = imax(ar, SIZE); printf("%d", max); return 0; }
my::Torus::Torus(const float & pathRadius, const float & tubeRadius, const int & nbSlices, const int & nbStacks) :ParametricMesh("Torus", 2*nbSlices, 2*(nbStacks+1)), _pathRadius(pathRadius), _tubeRadius(tubeRadius), _nbSlices(nbSlices), _nbStacks(nbStacks) { _preTorus(_pathRadius, _tubeRadius, _nbSlices, _nbStacks); my::Toric coord(_pathRadius, _tubeRadius); parametricVertexInsertion(imax(), jmax(), coord); parametricTriangleInsertion(imax(), jmax()); computeNormalsT(); computeNormalsV(); }
static int nmdm_param(struct tty *tp, struct termios *t) { struct nmdmpart *np = tty_softc(tp); struct tty *tp2; int bpc, rate, speed, i; tp2 = np->np_other->np_tty; if (!((t->c_cflag | tp2->t_termios.c_cflag) & CDSR_OFLOW)) { np->np_rate = 0; np->np_other->np_rate = 0; return (0); } /* * DSRFLOW one either side enables rate-simulation for both * directions. * NB: the two directions may run at different rates. */ /* Find the larger of the number of bits transmitted */ bpc = imax(bits_per_char(t), bits_per_char(&tp2->t_termios)); for (i = 0; i < 2; i++) { /* Use the slower of our receive and their transmit rate */ speed = imin(tp2->t_termios.c_ospeed, t->c_ispeed); if (speed == 0) { np->np_rate = 0; np->np_other->np_rate = 0; return (0); } speed <<= QS; /* [bit/sec, scaled] */ speed /= bpc; /* [char/sec, scaled] */ rate = (hz << QS) / speed; /* [hz per callout] */ if (rate == 0) rate = 1; speed *= rate; speed /= hz; /* [(char/sec)/tick, scaled */ np->np_credits = speed; np->np_rate = rate; callout_reset(&np->np_callout, rate, nmdm_timeout, np); /* * swap pointers for second pass so the other end gets * updated as well. */ np = np->np_other; t = &tp2->t_termios; tp2 = tp; } return (0); }
int main(void) { double ar[SIZE] = {1.8, 9.4, 3.8, 4.2, 5.6}; double differ; differ = imax(ar, SIZE); printf("%f", differ); return 0; }
//======================================================================== //======================================================================== // // NAME: complex<double> bessel_1_complex(int n, complex<double> arg) // // DESC: Calculates the Bessel function of the first kind (Jn) for // complex arguments. // // INPUT: // int n:: Order of Bessel function // complex<double> arg: Bessel function argument // // OUTPUT: // Jn:: Bessel function of the first kind of order n // // NOTES: 1) The Bessel function of the first kind is defined as: // Jn(x) = ((x/2.0)^n)*sum{m=0, m=inf}[(((-x^2)/4.0)^m)/(m!*(n+m)!) // // 2) J-n = ((-1)^n)*Jn // // 3) The infinite series representing the Bessel function // converges for all arguments given that enough terms are taken: // k >> |arg| // //======================================================================== //======================================================================== complex<double> bessel_1_complex(int n, complex<double> arg) { complex<double> Jn(0.0, 0.0); complex<double> Jn_series(0.0, 0.0); complex<double> Jn_seriesm1(0.0, 0.0); double tolerance = 100.0*depsilon(); // Make sure that we calculate the positive order Bessel function int m = abs(n); // !!! I don't know if this will be large enough int k_max_r, k_max_im; k_max_r = static_cast<int>(real(arg)); k_max_im = static_cast<int>(imag(arg)); /* int k_max = 10*imax(k_max_r, k_max_im); for(int k = 0; k <= k_max; k++) { Jn_series = Jn_series + pow((0.0 - arg*arg/4.0), k)/(dfactorial(k)*dfactorial(k+m)); } */ // !!! my concern with this do loop is that if a certain term contributes 0 then the // loop may inappropriately exit int k_max2 = static_cast<int>(2.0*static_cast<double>(imax(k_max_r, k_max_im))) + 1; int k = 0; do { Jn_seriesm1 = Jn_series; Jn_series = Jn_series + pow((0.0 - arg*arg/4.0), k)/(dfactorial(k)*dfactorial(k+m)); k = k + 1; } while ((sqrt(real(Jn_series*conj(Jn_series) - Jn_seriesm1*conj(Jn_seriesm1))) > tolerance) || (k < k_max2)); Jn = pow((arg/2.0), m)*Jn_series; // NOW WE WILL MAKE USE OF THE BESSEL FUNCTION RELATION FOR NEGATIVE n: // J(n-1) = (-1)^n*Jn if(n < 0) { Jn = pow((0.0 - 1.0), m)*Jn; } return Jn; }
static void init_header(multirom_theme_data *t) { button **tab_btns = t->tab_btns; fb_text **tab_texts = t->tab_texts; const int TAB_BTN_WIDTH = fb_width*0.21; int i, x; static const char *str[] = { "INTERNAL", "EXTERNAL", "MISC" }; char buff[64]; fb_add_rect_lvl(100, 0, 0, fb_width, HEADER_HEIGHT, C_HIGHLIGHT_BG); fb_add_rect(0, HEADER_HEIGHT, fb_width, (3*DPI_MUL), C_BTN_FAKE_SHADOW); ncard_set_top_offset(HEADER_HEIGHT); int maxW = 0; for(i = 0; i < TAB_COUNT; ++i) { fb_text_proto *p = fb_text_create(0, 0, C_HIGHLIGHT_TEXT, SIZE_NORMAL, str[i]); p->level = 110; p->style = STYLE_MEDIUM; tab_texts[i] = fb_text_finalize(p); maxW = imax(maxW, tab_texts[i]->w); } maxW += (30*DPI_MUL); x = fb_width/2 - (maxW*TAB_COUNT)/2; snprintf(buff, sizeof(buff), ":/miri_%dx%d.png", (int)MIRI_W, (int)MIRI_W); fb_add_png_img_lvl(110, 10*DPI_MUL, HEADER_HEIGHT/2 - MIRI_W/2, MIRI_W, MIRI_W, buff); for(i = 0; i < TAB_COUNT; ++i) { center_text(tab_texts[i], x, 0, maxW, HEADER_HEIGHT); tab_btns[i] = mzalloc(sizeof(button)); tab_btns[i]->x = x; tab_btns[i]->y = 0; tab_btns[i]->w = maxW; tab_btns[i]->h = HEADER_HEIGHT; tab_btns[i]->clicked_data = malloc(sizeof(int)); *((int*)tab_btns[i]->clicked_data) = i; tab_btns[i]->clicked = &multirom_ui_switch_btn; tab_btns[i]->level_off = 100; button_init_ui(tab_btns[i], "", 0); keyaction_add(tab_btns[i], button_keyaction_call, tab_btns[i]); x += maxW; if(i < TAB_COUNT-1) t->selected_rect[i] = fb_add_rect_lvl(120, 0, 0, 0, 0, (0x4C << 24) | (C_HIGHLIGHT_BG & 0x00FFFFFF)); } t->selected_tab_rect = fb_add_rect_lvl(110, tab_btns[0]->x, HEADER_HEIGHT-SELECTED_RECT_H + (3*DPI_MUL), maxW, SELECTED_RECT_H, C_HIGHLIGHT_TEXT); t->tabs = tabview_create(0, HEADER_HEIGHT, fb_width, fb_height-HEADER_HEIGHT); header_set_tab_selector_pos(t, 0.f); }
void draw_thickline(SDL_Surface* s, Line* l, float thickness,Color c) { int xmin = imin(l->end.x,l->start.x) - thickness; int ymin = imin(l->end.y,l->start.y) - thickness; int xmax = imax(l->end.x,l->start.x) + thickness; int ymax = imax(l->end.y,l->start.y) + thickness; Color cc = c; int x,y; for(x=xmin; x < xmax; x++) { for(y=ymin; y < ymax; y++) { Point inv = dilarot_inv_Point(l->length,thickness,l->arg, subs_Point((Point) {x,y},l->start)); if(inv.x >= 0.0 && inv.y <= 1.0 && inv.y >= -1.0 && inv.x <= 1.0) { set_pixel(s,x,y,cc); } } } }
static void get_max_distance(node * root,int * max_dis,int * max_dep) { if(!root){ *max_dis = 0; *max_dep = -1; return; } node *l = root->l; node *r = root->r; int l_max_dep,r_max_dep,l_max_dis,r_max_dis; get_max_distance(l,&l_max_dis,&l_max_dep); get_max_distance(r,&r_max_dis,&r_max_dep); *max_dep = imax(l_max_dep+1,r_max_dep+1); *max_dis = imax(imax(l_max_dis,r_max_dis),l_max_dep+r_max_dep+2); }
void StringItem::Measure(HDC hDC, SIZE *size) { MenuItem::Measure(hDC, size); if (false == Settings_menu.showBroams) { size->cx = imax(size->cx + 20, 120); size->cy += 6; } SetRectEmpty(&m_textrect); }
void index_boolean_array(const boolean_array_t* source, const index_spec_t* source_spec, boolean_array_t* dest) { _index_t* idx_vec1; _index_t* idx_vec2; _index_t* idx_size; int j; int i; assert(base_array_ok(source)); assert(base_array_ok(dest)); assert(index_spec_ok(source_spec)); assert(index_spec_fit_base_array(source_spec,source)); for(i = 0, j = 0; i < source->ndims; ++i) { if((source_spec->index_type[i] == 'W') || (source_spec->index_type[i] == 'A')) { ++j; } } assert(j == dest->ndims); idx_vec1 = size_alloc(source->ndims); /*indices in the source array*/ idx_vec2 = size_alloc(dest->ndims); /* indices in the destination array*/ idx_size = size_alloc(source_spec->ndims); for(i = 0; i < source->ndims; ++i) { idx_vec1[i] = 0; } for(i = 0; i < source_spec->ndims; ++i) { if(source_spec->index[i]) { idx_size[i] = imax(source_spec->dim_size[i],1); } else { idx_size[i] = source->dim_size[i]; } } do { for(i = 0, j = 0; i < source->ndims; ++i) { if((source_spec->index_type[i] == 'W') || (source_spec->index_type[i] == 'A')) { idx_vec2[j] = idx_vec1[i]; j++; } } boolean_set(dest, calc_base_index(dest->ndims, idx_vec2, dest), boolean_get(*source, calc_base_index_spec(source->ndims, idx_vec1, source, source_spec))); } while(0 == next_index(source->ndims, idx_vec1, idx_size)); }
static jv* jvp_array_write(jv_nontrivial* a, int i) { assert(i >= 0); jvp_array* array = jvp_array_ptr(a); int pos = i + a->i[0]; if (pos < array->alloc_length) { // maybe we can update it in-place // FIXME: this "optimisation" can cause circular references #if 0 int can_write_past_end = array->length <= pos && /* the end of this array has never been used */ a->i[1] == array->length; /* the current slice sees the end of the array */ #endif int can_write_past_end = 0; if (can_write_past_end || jvp_refcnt_unshared(a)) { // extend the array for (int j = array->length; j <= pos; j++) { array->elements[j] = JV_NULL; } array->length = imax(pos + 1, array->length); a->i[1] = imax(pos + 1, a->i[1]); return &array->elements[pos]; } } int new_length = imax(i + 1, jvp_array_length(a)); jvp_array* new_array = jvp_array_alloc(ARRAY_SIZE_ROUND_UP(new_length)); int j; for (j = 0; j < jvp_array_length(a); j++) { new_array->elements[j] = jv_copy(array->elements[j + a->i[0]]); } for (; j < new_length; j++) { new_array->elements[j] = JV_NULL; } new_array->length = new_length; jvp_array_free(a); a->ptr = &new_array->refcnt; a->i[0] = 0; a->i[1] = new_length; return &new_array->elements[i]; }
/*! This function allocates the memory neeed to compute the long-range PM * force. Three fields are used, one to hold the density (and its FFT, and * then the real-space potential), one to hold the force field obtained by * finite differencing, and finally a workspace field, which is used both as * workspace for the parallel FFT, and as buffer for the communication * algorithm used in the force computation. */ void pm_init_periodic_allocate(int dimprod) { static int first_alloc = 1; int dimprodmax; double bytes_tot = 0; size_t bytes; MPI_Allreduce(&dimprod, &dimprodmax, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD); /* allocate the memory to hold the FFT fields */ if(!(rhogrid = (fftw_real *) malloc(bytes = fftsize * sizeof(fftw_real)))) { printf("failed to allocate memory for `FFT-rhogrid' (%g MB).\n", bytes / (1024.0 * 1024.0)); endrun(1); } bytes_tot += bytes; if(!(forcegrid = (fftw_real *) malloc(bytes = imax(fftsize, dimprodmax) * sizeof(fftw_real)))) { printf("failed to allocate memory for `FFT-forcegrid' (%g MB).\n", bytes / (1024.0 * 1024.0)); endrun(1); } bytes_tot += bytes; if(!(workspace = (fftw_real *) malloc(bytes = imax(maxfftsize, dimprodmax) * sizeof(fftw_real)))) { printf("failed to allocate memory for `FFT-workspace' (%g MB).\n", bytes / (1024.0 * 1024.0)); endrun(1); } bytes_tot += bytes; if(first_alloc == 1) { first_alloc = 0; if(ThisTask == 0) printf("\nAllocated %g MByte for FFT data.\n\n", bytes_tot / (1024.0 * 1024.0)); } fft_of_rhogrid = (fftw_complex *) & rhogrid[0]; }
int cam_ccbq_init(struct cam_ccbq *ccbq, int openings) { bzero(ccbq, sizeof(*ccbq)); if (camq_init(&ccbq->queue, imax(64, 1 << fls(openings + openings / 2))) != 0) return (1); ccbq->total_openings = openings; ccbq->dev_openings = openings; return (0); }
void MenuItem::Measure(HDC hDC, SIZE *size) { const char *title = GetDisplayString(); RECT r = { 0, 0, 0, 0 }; bbDrawText(hDC, title, &r, DT_MENU_MEASURE_STANDARD, 0); size->cx = r.right; size->cy = MenuInfo.nItemHeight; //#ifdef BBOPT_MENUICONS if (m_hIcon && Settings_menu.iconSize)/* BlackboxZero 1.3.2012 */ size->cy = imax(MenuInfo.nIconSize+2, size->cy); //#endif }
int my::Torus::_indiceOfSampled(const int & i, const int & j)const throw(std::logic_error, std::invalid_argument) { _preIndiceOfSampled("Torus", "path angle", "tube angle", "[0,imax()]", "[0, jmax()]", i, imax(), j, jmax()); int imod; int jmod; imod = i % imax(); jmod = j % jmax(); return jmod + imod*jmax(); }
double fas197(double *b, int pq, void *params) { double value, ssq, fact, delta; int ip, iq, i, ifault, N; double *phi, *theta,*VW,*VK,*VL; int MR, MRP1; alik_object obj = (alik_object)params; value = ssq = fact = 0.0; ip = obj->p; iq = obj->q; N = obj->N; MR = imax(ip, iq + 1); MRP1 = MR + 1; phi = (double*)malloc(sizeof(double)* ip); theta = (double*)malloc(sizeof(double)* iq); VW = (double*)malloc(sizeof(double*)*MRP1); VL = (double*)malloc(sizeof(double*)*MRP1); VK = (double*)malloc(sizeof(double*)*MR); for (i = 0; i < ip; ++i) { phi[i] = b[i]; } for (i = 0; i < iq; ++i) { theta[i] = b[i + ip]; } if (obj->M == 1) { for (i = 0; i < N; ++i) { obj->x[i] = obj->x[2 * N + i] - b[ip + iq]; } } delta = 0.001; //mdisplay(P, 1, np); obj->ssq = ssq; //mdisplay(phi, 1, ip); ifault = flikam(phi, ip, theta, iq, obj->x, obj->x+N, N, &ssq, &fact, VW, VL, MRP1, VK, MR, delta); value = ssq*fact; //printf("sumlog ssq %g %g %d \n", sumlog,value,iter); free(phi); free(theta); free(VW); free(VL); free(VK); //free(bt); return value; }
my::ConicMesh::ConicMesh(const float & height, const float & aperture, const int & nbSlices, const int & nbStacks) :ParametricMesh("ConicMesh", nbStacks+2, 2*nbSlices), _height(height), _aperture(aperture), _nbSlices(nbSlices), _nbStacks(nbStacks) { _preConicMesh(_height, _aperture, _nbSlices, _nbStacks); my::Conic coord(Point(0,-1,0), _aperture); parametricVertexInsertion(imax()-1, jmax(), coord); this->addVertex(0,-1,0); parametricTriangleInsertion(imax()-1, jmax()); flipTriangles(); computeNormalsT(); computeNormalsV(); }
void draw_ring(SDL_Surface* s, Point pos, float r, float rin, Color c) { int xmin = imax(0,pos.x - r); int ymin = imax(0,pos.y - r); int xmax = imin(pos.x + r + 1,s->w); int ymax = imin(pos.y + r + 1,s->h); float r2 = pow(r,2); float rin2 = pow(rin,2); Uint32* pix; int x,y; for(x=xmin; x < xmax; x++) { float x2 = pow(x-pos.x,2); for(y=ymin; y < ymax; y++) { float y2 = pow(y-pos.y,2); if(x2+y2 <= r2 && x2+y2 >= rin2){ pix = ((Uint32*) s->pixels + x + (s->pitch/4) * y); *pix = intColor_fmt(c,s->format); } } } }
/*! This function allocates the workspace needed for the non-periodic FFT * algorithm. Three fields are used, one for the density/potential fields, * one to hold the force field obtained by finite differencing, and finally * an additional workspace which is used both in the parallel FFT itself, and * as a buffer for the communication algorithm. */ void pm_init_nonperiodic_allocate(int dimprod) { static int first_alloc = 1; int dimprodmax; double bytes_tot = 0; size_t bytes; MPI_Allreduce(&dimprod, &dimprodmax, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD); if(!(rhogrid = (fftw_real *) malloc(bytes = fftsize * sizeof(fftw_real)))) { printf("failed to allocate memory for `FFT-rhogrid' (%g MB).\n", bytes / (1024.0 * 1024.0)); endrun(1); } bytes_tot += bytes; fft_of_rhogrid = (fftw_complex *) rhogrid; if(!(forcegrid = (fftw_real *) malloc(bytes = imax(fftsize, dimprodmax) * sizeof(fftw_real)))) { printf("failed to allocate memory for `FFT-forcegrid' (%g MB).\n", bytes / (1024.0 * 1024.0)); endrun(1); } bytes_tot += bytes; if(!(workspace = (fftw_real *) malloc(bytes = imax(maxfftsize, dimprodmax) * sizeof(fftw_real)))) { printf("failed to allocate memory for `FFT-workspace' (%g MB).\n", bytes / (1024.0 * 1024.0)); endrun(1); } bytes_tot += bytes; if(first_alloc == 1) { first_alloc = 0; if(ThisTask == 0) printf("\nUsing %g MByte for non-periodic FFT computation.\n\n", bytes_tot / (1024.0 * 1024.0)); } }