long int left(int i, int j){ int k; long int p; if (limit_back(j)){ p = 1; for (k=0; k<N_ADJ; k++) p *= get_val(grid, i, j-k); } else p = 0; return p; }
long int up(int i, int j){ int k; long int p; if (limit_back(i)){ p = 1; for (k=0; k<N_ADJ; k++) p *= get_val(grid, i-k, j); } else p = 0; return p; }
long int right(int i, int j){ int k; long int p; if (limit_front(j)){ p = 1; for (k=0; k<N_ADJ; k++) p *= get_val(grid, i, j+k); } else p = 0; return p; }
static ojcVal get_word_val(ParseInfo pi, const char *str, int len) { ojcVal val = get_val(pi, OJC_WORD); if ((int)sizeof(val->str.ca) <= len) { len = (int)sizeof(val->str.ca) - 1; } val->str_len = len; memcpy(val->str.ca, str, len); return val; }
long int down(int i, int j){ int k; long int p; if (limit_front(i)){ p = 1; for (k=0; k<N_ADJ; k++) p *= get_val(grid, i+k, j); } else p = 0; return p; }
long int diag_down_right(int i, int j){ int k; long int p; if (limit_front(j) && limit_front(i)){ p = 1; for (k=0; k<N_ADJ; k++) p *= get_val(grid, i+k, j+k); } else p = 0; return p; }
/* Busy bit wait loop for MMCST1 */ static int dmmc_busy_wait(volatile struct davinci_mmc_regs *regs) { uint wdog = WATCHDOG_COUNT; while (--wdog && (get_val(®s->mmcst1) & MMCST1_BUSY)) udelay(10); if (wdog == 0) return -ECOMM; return 0; }
/* Append table T, which should have been returned by covariance_dump_enc_header with an entry corresponding to case C for the covariance matrix COV */ void covariance_dump_enc (const struct covariance *cov, const struct ccase *c, struct tab_table *t) { static int row = 0; int i; ++row; for (i = 0 ; i < cov->dim; ++i) { double v = get_val (cov, i, c); tab_double (t, i, row, 0, v, i < cov->n_vars ? NULL : &F_8_0, RC_OTHER); } }
void ps_write_pars(FILE *fp) { int div,rem,i,j; double z; fprintf(fp,"\n %%%% %s \n %%%% Parameters ...\n",this_file); div=NUPAR/4; rem=NUPAR%4; for(j=0;j<div;j++){ for(i=0;i<4;i++) { get_val(upar_names[i+4*j],&z); fprintf(fp,"%%%% %s=%.16g ",upar_names[i+4*j],z); } fprintf(fp,"\n"); } for(i=0;i<rem;i++){ get_val(upar_names[i+4*div],&z); fprintf(fp,"%%%% %s=%.16g ",upar_names[i+4*div],z); } fprintf(fp,"\n"); }
void exchange_cards_null(Player *p, Game *g) { //skat aufnehmen p->hand[10] = g->skat[0]; p->hand[11] = g->skat[1]; p->hcardcount = 12; for(; p->hcardcount > 10; --p->hcardcount) { int c = -1; //Risikofarbe suchen //dabei wird der wert jeder Karte (ass = 0 … sieben = 7) quadriert //und durch die anzahl der Karten der Farbe +1 geteilt //die Farbe mit dem geringsten Wert ist ein Risiko int col_risk = 0; float val_risk = 100.0; for(int col = 0; col < 4; ++col) { int val = 0; for(int j = 0; j < p->hcardcount; j++) if(get_col(p->hand[j]) == col) val += get_val(p->hand[j]); float risk = (float)(val*val+1)/((float)length_of_color(p, col)+1.0); if(val_risk > risk && risk != 0) { val_risk = risk; col_risk = col; } } //höchste Karte der Risikofarbe in den Skat for(int i = 0; i < p->hcardcount; ++i) { if(get_col(p->hand[i]) == col_risk) { if(c == -1) c = i; else if(get_val(p->hand[i]) < get_val(p->hand[c])) c = i; } } g->skat[p->hcardcount-10] = p->hand[c]; p->hand[c] = p->hand[p->hcardcount-1]; } }
float find_val(char **tab, int power) { int i; i = 0; while (tab[i]) { if (get_power(tab[i]) == power) return (get_val(tab[i])); i++; } return (0); }
void parse_mem_work(struct sdp_work *curr, const char *filename, const char *p) { struct mem_work *wp; struct mem_work **link; struct mem_work w; unsigned int i; const char *start = p; p = skip(p,':'); memset(&w, 0, sizeof(w)); if (strncmp(p, "read", 4) == 0) { p += 4; p = skip(p,','); i = MEM_TYPE_READ; } else if (strncmp(p, "write", 5) == 0) { p += 5; p = skip(p,','); i = MEM_TYPE_WRITE; } else if (strncmp(p, "modify", 6) == 0) { p += 6; p = skip(p,','); i = MEM_TYPE_MODIFY; } else { printf("%s: syntax error: %s {%s}\n", filename, p, start); } w.type = i; i = 0; for (;;) { w.vals[i] = get_val(&p, 16); if (i >= w.type) break; p = skip(p,','); if ((*p == 0) || (*p == '#')) { printf("%s: missing argment: %s {%s}\n", filename, p, start); return; } i++; } if (!end_of_line(p)) { printf("%s: syntax error: %s {%s}\n", filename, p, start); return; } wp = (struct mem_work *)malloc(sizeof(struct mem_work)); if (!wp) return; link = &curr->mem; while (*link) link = &(*link)->next; *wp = w; *link = wp; }
//validation template<class X> void splay_forest<X>::test_find (Pos eqn) { //test find_pair Pos pos = find_pair(get_root(eqn), get_key(eqn), get_val(eqn)); POMAGMA_ASSERT(pos, "invalid: eqn not found in own " << nameof<X>() << " tree"); POMAGMA_ASSERT(pos == eqn, "invalid: wrong eqn found in own " << nameof<X>() << " tree"); //test find_key pos = find_key(get_root(eqn), get_key(eqn)); POMAGMA_ASSERT(pos, "invalid: key not found in own " << nameof<X>() << " tree"); POMAGMA_ASSERT(get_key(pos) == get_key(eqn), "invalid: wrong key found in own " << nameof<X>() << " tree"); }
/* *-------------------------------------------------------------------------------------- * Class: ImageSensor * Method: ImageSensor :: get_projections * Description: Writes latest data to vector of matches. *-------------------------------------------------------------------------------------- */ int FeatureIO::get_projections ( ) { char str[20]; strcpy( str, (isHex) ? "%d,%lx,%lx,%lx" : "%d,%lf,%lf,%lf" ); std::vector<projection>::iterator it=matches.begin(); for( ; it!=matches.end(); ++it ) { get_val( fp, "image", str, &it->id,&it->source.x, &it->source.y, &it->reflection.x, &it->reflection.y ); } return 1; } /* ----- end of method imageSensor::get_projections ----- */
int search(int target){ int low = 0,mid,val,high = N-1; while(low <= high){ mid = (high+low)/2; val = get_val(leaves[mid]); if(target >= val){ low = mid+1; }else{ high = mid-1; } } return high; }
static void setbridge_timeout(const char *arg, int d, int s, const struct afswtch *afp) { struct ifbrparam param; u_long val; if (get_val(arg, &val) < 0 || (val & ~0xffffffff) != 0) errx(1, "invalid value: %s", arg); param.ifbrp_ctime = val & 0xffffffff; if (do_cmd(s, BRDGSTO, ¶m, sizeof(param), 1) < 0) err(1, "BRDGSTO %s", arg); }
unsigned int get_adc7(void) { unsigned int ret; // Enable the adc SBI(ADCSRA, ADEN); // Set mux to adc 7 ADMUX = (0 << REFS1) | (1 << REFS0) | (1 << MUX2) | (1 << MUX1) | (1 << MUX0); // Convert ret = get_val(); // Disable ADC CBI(ADCSRA, ADEN); return ret; }
void math_op(enum opcode opcode, OPERAND **operands) { int vals[2]; vals[0] = get_val(operands[0]); vals[1] = get_val(operands[1]); switch(opcode) { case ADD: cpu->registers[RESERVED_REG(REG_MATH)] = vals[0] + vals[1]; break; case SUB: cpu->registers[RESERVED_REG(REG_MATH)] = vals[0] - vals[1]; break; case MUL: cpu->registers[RESERVED_REG(REG_MATH)] = vals[0] * vals[1]; break; case DIV: cpu->registers[RESERVED_REG(REG_MATH)] = vals[0] / vals[1]; break; case MOD: cpu->registers[RESERVED_REG(REG_MATH)] = vals[0] % vals[1]; break; case XOR: cpu->registers[RESERVED_REG(REG_MATH)] = vals[0] ^ vals[1]; break; case OR: cpu->registers[RESERVED_REG(REG_MATH)] = vals[0] | vals[1]; break; case SHL: cpu->registers[RESERVED_REG(REG_MATH)] = vals[0] << vals[1]; break; case SHR: cpu->registers[RESERVED_REG(REG_MATH)] = vals[1] >> vals[0]; break; } }
static void info_opt(int level, int type, void *ptr, int len) { uint32_t mask; uint64_t fc_mask; int i; p_indent(level, 0); switch (type) { case 0x0001: printf("Connectionless MTU %d\n", get_val(ptr, len)); break; case 0x0002: mask = get_val(ptr, len); printf("Extended feature mask 0x%4.4x\n", mask); if (parser.flags & DUMP_VERBOSE) for (i=0; l2cap_features[i].name; i++) if (mask & l2cap_features[i].flag) { p_indent(level + 1, 0); printf("%s\n", l2cap_features[i].name); } break; case 0x0003: fc_mask = bt_get_le64(ptr); printf("Fixed channel list 0x%8.8" PRIx64 "\n", fc_mask); if (parser.flags & DUMP_VERBOSE) for (i=0; l2cap_fix_chan[i].name; i++) if (fc_mask & l2cap_fix_chan[i].flag) { p_indent(level + 1, 0); printf("%s\n", l2cap_fix_chan[i].name); } break; default: printf("Unknown (len %d)\n", len); break; } }
static inline void command_rej(int level, struct frame *frm) { l2cap_cmd_rej *h = frm->ptr; uint16_t reason = btohs(h->reason); uint32_t cid; printf("Command rej: reason %d", reason); switch (reason) { case 0x0001: printf(" mtu %d\n", get_val(frm->ptr + L2CAP_CMD_REJ_SIZE, 2)); break; case 0x0002: cid = get_val(frm->ptr + L2CAP_CMD_REJ_SIZE, 4); printf(" dcid 0x%4.4x scid 0x%4.4x\n", cid & 0xffff, cid >> 16); break; default: printf("\n"); break; } p_indent(level + 1, frm); printf("%s\n", reason2str(reason)); }
static int compute_roman(char *str) { char *p; int val = 0; int next_val; int remainder; if (str && *str) { p = str; p++; if (*p == '\0') { val = get_val(*str); } else { remainder = compute_roman(p); val = get_val(*str); next_val = get_val(*p); if (val < next_val) { val = remainder - val; } else { val = remainder + val; } } } return val; }
int get_points_2d(struct urg_params urg, struct coord *points){ int data_max, n, i; long *data; data_max = urg_max_data_size(urg.ptr);//aquisition du nombre de points data = (long*)malloc(sizeof(long) * data_max); if(data == NULL){ fprintf(stderr, "data malloc error\n"); exit(1); } if(points == NULL){ fprintf(stderr, "get_points_2d : points non alloué\n"); exit(1); } n = urg_get_distance(urg.ptr, data, NULL); // CONVERSION EN COORDONNEES for(i=0; i<n; i++){ /* double rad = urg_index2rad(urg.ptr, i); points[i].x = data[i]*cos(rad) - urg.x; //x points[i].y = data[i]*sin(rad) - urg.y; //y */ points[i].x = data[i]*get_val(cosinus, i, urg.ptr) + urg.x; //x points[i].y = data[i]*get_val(sinus, i, urg.ptr) + urg.y; //y if(urg.side == GREEN_SIDE){//si blue side, symétrie centrale points[i].x = LX - points[i].x; points[i].y = LY - points[i].y; } } free(data);//free raw datas return n; }
/** * calc distance between two items. * Let a be all the users rated item 1 * Let b be all the users rated item 2 * * 3) Using Pearson correlation * Dist_ab = (a - mean)*(b- mean)' / (std(a)*std(b)) * * 4) Using cosine similarity: * Dist_ab = (a*b) / sqrt(sum_sqr(a)) * sqrt(sum_sqr(b))) * * 5) Using chebychev: * Dist_ab = max(abs(a-b)) * * 6) Using manhatten distance: * Dist_ab = sum(abs(a-b)) * * 7) Using tanimoto: * Dist_ab = 1.0 - [(a*b) / (sum_sqr(a) + sum_sqr(b) - a*b)] * * 8) Using log likelihood similarity * Dist_ab = 1.0 - 1.0/(1.0 + loglikelihood) * * 9) Using Jaccard: * Dist_ab = intersect(a,b) / (size(a) + size(b) - intersect(a,b)) */ double calc_distance(CE_Graph_vertex<VertexDataType, EdgeDataType> &v, vid_t pivot, int distance_metric) { //assert(is_pivot(pivot)); //assert(is_item(pivot) && is_item(v.id())); dense_adj &pivot_edges = adjs[pivot - pivot_st]; int num_edges = v.num_edges(); dense_adj item_edges; for(int i=0; i < num_edges; i++){ set_new(item_edges.edges, v.edge(i)->vertexid, v.edge(i)->get_data()); } if (distance_metric == JACCARD_WEIGHT){ return calc_jaccard_weight_distance(pivot_edges.edges, item_edges.edges, get_val( pivot_edges.edges, v.id()), 0); } return NAN; }
int main(int argc, char *argv[]) { int n = read_int(), m = read_int(); int size = (int)pow(2, ceil(log2(n))); /* printf("n %d size: %d\n", n, size); */ struct node* nodes = setup(size); for (int i = 0; i < m; ++i) { int a = read_int(), b = read_int(), k = read_int(); feed(nodes, 0, a, b, k); } /* dump(nodes, 2 * size - 1); */ printf("%lld\n", get_val(nodes, 0)); return 0; }
double my_cos(double nb, t_trigo_state mode) { static double *cosinuses = NULL; if (!cosinuses) { cosinuses = set_cosinuses(); } else if (mode == FREE) { my_free(cosinuses); cosinuses = NULL; } else return (cosinuses[get_val(nb)]); return (0.0); }
double my_sin(double nb, t_trigo_state mode) { static double *sinuses = NULL; if (!sinuses) { sinuses = set_sinuses(); } else if (mode == FREE) { my_free(sinuses); sinuses = NULL; } else return (sinuses[get_val(nb)]); return (0.0); }
static void setbridge_ifpriority(const char *ifn, const char *pri, int s, const struct afswtch *afp) { struct ifbreq req; u_long val; memset(&req, 0, sizeof(req)); if (get_val(pri, &val) < 0 || (val & ~0xff) != 0) errx(1, "invalid value: %s", pri); strlcpy(req.ifbr_ifsname, ifn, sizeof(req.ifbr_ifsname)); req.ifbr_priority = val & 0xff; if (do_cmd(s, BRDGSIFPRIO, &req, sizeof(req), 1) < 0) err(1, "BRDGSIFPRIO %s", pri); }
static void setbridge_ifpathcost(const char *ifn, const char *cost, int s, const struct afswtch *afp) { struct ifbreq req; u_long val; memset(&req, 0, sizeof(req)); if (get_val(cost, &val) < 0) errx(1, "invalid value: %s", cost); strlcpy(req.ifbr_ifsname, ifn, sizeof(req.ifbr_ifsname)); req.ifbr_path_cost = val; if (do_cmd(s, BRDGSIFCOST, &req, sizeof(req), 1) < 0) err(1, "BRDGSIFCOST %s", cost); }
static void setbridge_ifmaxaddr(const char *ifn, const char *arg, int s, const struct afswtch *afp) { struct ifbreq req; u_long val; memset(&req, 0, sizeof(req)); if (get_val(arg, &val) < 0 || (val & ~0xffffffff) != 0) errx(1, "invalid value: %s", arg); strlcpy(req.ifbr_ifsname, ifn, sizeof(req.ifbr_ifsname)); req.ifbr_addrmax = val & 0xffffffff; if (do_cmd(s, BRDGSIFAMAX, &req, sizeof(req), 1) < 0) err(1, "BRDGSIFAMAX %s", arg); }
/* Call this function for every case in the data set */ void covariance_accumulate_pass1 (struct covariance *cov, const struct ccase *c) { size_t i, j, m; const double weight = cov->wv ? case_data (c, cov->wv)->f : 1.0; assert (cov->passes == 2); if (!cov->pass_one_first_case_seen) { assert (cov->state == 0); cov->state = 1; } if (cov->categoricals) categoricals_update (cov->categoricals, c); for (i = 0 ; i < cov->dim; ++i) { double v1 = get_val (cov, i, c); if ( is_missing (cov, i, c)) continue; for (j = 0 ; j < cov->dim; ++j) { double pwr = 1.0; if ( is_missing (cov, j, c)) continue; for (m = 0 ; m <= MOMENT_MEAN; ++m) { double *x = gsl_matrix_ptr (cov->moments[m], i, j); *x += pwr * weight; pwr *= v1; } } } cov->pass_one_first_case_seen = true; }