/**
  *  dr=sum_j v_j dv_j; ddr=sum_j dv_j^2
  *  v_j = bar_j - bar_{p(j)} where p(j) is j's parent. 
  *
  *  output: newleaf_v, newleaf_dep_factor, focus_dbar, 
  *          vdv_sum, dv2_dum, dr, ddr
 **/
void AzReg_Tsrbase::update()
{
  /* vdv_sum, dv2_sum: don't include new leaf nodes */
  /* dr, ddr:           include new leaf nodes */

  dr = ddr = 0; 

  if (forNewLeaf) {
    checkLeaf("update"); 

    /*---  new leaf  ---*/
    newleaf_v = get_newleaf_v(); 
    double dv = get_newleaf_dv(); 
    int newleaf_depth = get_newleaf_depth(); 
    newleaf_dep_factor = reg_depth->apply(1, newleaf_depth); 
    dr += newleaf_v*dv*newleaf_dep_factor; 
    ddr += dv*dv*newleaf_dep_factor; 

    /*---  new leaf's sibling (v is the same)  ---*/
    dv = get_newleaf_sib_dv(); 
    dr += newleaf_v*dv*newleaf_dep_factor; 
    ddr += dv*dv*newleaf_dep_factor; 

    focus_dbar = av_dbar.point(focus_nx)->get(focus_nx); 
  }

  vdv_sum = 0;  
  int nx; 
  if (v_v.rowNum() > 0) {
    /*---  for efficiency don't use get_v and get_dv  ---*/
    const double *v_arr = v_v.point(); 
    if (av_dv.size() <= 0) {
      throw new AzException("AzReg_Tsrbase::update", "no dv?"); 
    }
    const double *dv_arr = av_dv.point(focus_nx)->point(); 

    for (nx = 0; nx < tree->nodeNum(); ++nx) {
      double v = v_arr[nx]; 
      double dv = dv_arr[nx]; 
      int depth = tree->node(nx)->depth; 
      vdv_sum += reg_depth->apply(v * dv, depth); 
    } 
  }  
  else {
    for (nx = 0; nx < tree->nodeNum(); ++nx) {
      double v = get_v(nx); 
      double dv = get_dv(nx); 
      int depth = tree->node(nx)->depth; 
      vdv_sum += reg_depth->apply(v * dv, depth); 
    } 
  }
  dv2_sum = get_dv2_sum(); 

  dr += vdv_sum; 
  ddr += dv2_sum; 
}
Beispiel #2
0
int VFrame::copy_from(VFrame *frame)
{
	int w = MIN(this->w, frame->get_w());
	int h = MIN(this->h, frame->get_h());
	

	switch(frame->color_model)
	{
		case BC_COMPRESSED:
			allocate_compressed_data(frame->compressed_size);
			memcpy(data, frame->data, frame->compressed_size);
			this->compressed_size = frame->compressed_size;
			break;

		case BC_YUV420P:
//printf("%d %d %p %p %p %p %p %p\n", w, h, get_y(), get_u(), get_v(), frame->get_y(), frame->get_u(), frame->get_v());
			memcpy(get_y(), frame->get_y(), w * h);
			memcpy(get_u(), frame->get_u(), w * h / 4);
			memcpy(get_v(), frame->get_v(), w * h / 4);
			break;

		case BC_YUV422P:
//printf("%d %d %p %p %p %p %p %p\n", w, h, get_y(), get_u(), get_v(), frame->get_y(), frame->get_u(), frame->get_v());
			memcpy(get_y(), frame->get_y(), w * h);
			memcpy(get_u(), frame->get_u(), w * h / 2);
			memcpy(get_v(), frame->get_v(), w * h / 2);
			break;

		default:
// printf("VFrame::copy_from %d\n", calculate_data_size(w, 
// 				h, 
// 				-1, 
// 				frame->color_model));
			memcpy(data, frame->data, calculate_data_size(w, 
				h, 
				-1, 
				frame->color_model));
			break;
	}

	return 0;
}
Beispiel #3
0
static int xiphrtp_to_mkv(rtp_vorbis *vorb, uint8_t **value, int *size)
{
    uint8_t *conf;
    rtp_xiph_conf *tmp;
    int i, count, offset = 1, val;
    int id  = nms_consume_BE3(value);
    int len = nms_consume_BE2(value);

    //XXX check len

    if (len) {
        // convert the format
        count = get_v(value, size);
        if (count != 2) {
            // corrupted packet?
            return RTP_PARSE_ERROR;
        }
        conf = malloc(len + len/255 + 64);
        for (i=0; i < count && *size > 0 && offset < len; i++) {
            val = get_v(value, size);
            offset += nms_xiphlacing(conf + offset, val);
        }
        if (len > *size) {
            free(conf);
            return RTP_PARSE_ERROR;
        }
        conf[0] = count;
        memcpy(conf + offset, *value, len);
        *value += len;
        // append to the list
        vorb->conf_len++;
        vorb->conf = realloc(vorb->conf,
                               vorb->conf_len*sizeof(rtp_xiph_conf));
        tmp = vorb->conf + vorb->conf_len - 1;
        tmp->conf = conf;
        tmp->len = len + offset;
        tmp->id = id;
    }
    return 0;
}
Beispiel #4
0
    void Number::trim(unsigned precision/* = s_default_precision*/)
    {
        switch (type())
        {
        case Number::INTEGER:
            break;

        case Number::FLOATING:
            {
                assign(str(precision, std::ios_base::fixed));

                integer_type i = to_i();
                floating_type f = static_cast<floating_type>(i);
                if (f == get_f())
                    assign(i);
            }
            break;

        case Number::RATIONAL:
            {
                rational_type r = get_r();
                if (b_mp::denominator(r) == 1)
                    assign(b_mp::numerator(r));
            }
            break;

#ifndef PMP_DISABLE_VECTOR
        case Number::VECTOR:
            for (size_t i = 0; i < get_v().size(); ++i)
                get_v()[i].trim(precision);
            if (size() == 1)
                assign(get_v()[0]);
            break;
#endif

        default:
            assert(0);
            break;
        }
    }
Beispiel #5
0
void downheap(struct cell **head, int v, int n)
{
  struct cell **p, **w;
  int temp;
   
  if(v > n/2)
    return; 
  
  p = get_v(head, v);
  v = 2*v;
  w = get_v(head, v);
  if( v+1 <= n && (*w)->value < (*w)->next->value ) {
    w = &((*w)->next);
    v++;
  }
  
  if( (*p)->value < (*w)->value ) {
    temp        = (*p)->value;
    (*p)->value = (*w)->value;
    (*w)->value = temp;
    downheap(head, v, n);
  }
}
Beispiel #6
0
    std::string Number::str(unsigned precision,
                            std::ios_base::fmtflags flags) const
    {
        switch (type())
        {
        case Number::INTEGER:
            return get_i().str(precision, flags);

        case Number::FLOATING:
            return get_f().str(precision, flags);

        case Number::RATIONAL:
            return get_r().str();

#ifndef PMP_DISABLE_VECTOR
        case Number::VECTOR:
            {
                std::string s;
                if (!empty())
                {
                    s += get_v()[0].str(precision, flags);
                    for (size_t i = 1; i < size(); ++i)
                    {
                        s += ", ";
                        s += get_v()[i].str(precision, flags);
                    }
                }
                return s;
            }
#endif

        default:
            assert(0);
            return "";
        }
    }
Beispiel #7
0
static int get_str(ByteIOContext *bc, char *string, unsigned int maxlen){
    unsigned int len= get_v(bc);

    if(len && maxlen)
        get_buffer(bc, string, FFMIN(len, maxlen));
    while(len > maxlen){
        get_byte(bc);
        len--;
    }

    if(maxlen)
        string[FFMIN(len, maxlen-1)]= 0;

    if(maxlen == len)
        return -1;
    else
        return 0;
}
/*--------------------------------------------------------*/
double AzReg_Tsrbase::penalty()
const
{
  double r = 0; 
  int nx; 
  for (nx = 0; nx < tree->nodeNum(); ++nx) {
    double v = get_v(nx); 
    r += reg_depth->apply(v*v/2, tree->node(nx)->depth); 
  }

  if (forNewLeaf) {
    checkLeaf("penalty"); 
    double v = get_newleaf_v(); 
    double rr = 2*reg_depth->apply(v*v/2, get_newleaf_depth()); /* 2* for siblings */
    r += rr; 
  }

  return r; 
}
Beispiel #9
0
int main()
{
  vector<int> res = get_v();
  vector<int> guesses;
  char play_again;

  cout << "Do you want to play? (y/n): ";
  cin >> play_again;

  while (play_again != 'n') {
    for (int guess; cin>>guess; ) {
      guesses.push_back(guess);
      if (guesses.size() == 4) break;
    }

    int count = 0;
    for (int i = 0; i < guesses.size(); ++i) {
      if (guesses[i] == res[i]) ++count;
    }

    switch (count) {
      case 4:
        cout << "four bulls";
        break;
      case 3:
        cout << "three bulls one cow";
        break;
      case 2:
        cout << "two bulls two cows";
        break;
      case 1:
        cout << "one bull three cows";
        break;
      default:
        cout << "four cows";
        break;
    }
    guesses.clear();
    cout << "\nDo you want to play? (y/n): ";
    cin >> play_again;
  }
Beispiel #10
0
void heapsort(struct cell **head, int n)
{
  struct cell **p;
  int temp;
  int i;
  
  for(i = n/2; i > 0; i--)
    downheap(head, i, n); 
  
  while(n > 1) {
    p = get_v(head, n);
    
    temp           = (*head)->value;
    (*head)->value = (*p)->value;
    (*p)->value    = temp;
    
    downheap(head, 1, n-1);  
    
    n--;
  }
}
Beispiel #11
0
void CubeCreature::avoid_collision(){
	if(cur_move_state()->get_move_state()==MS_AVOID_COLLISION)return;
	if(colli_state()==C_STATE_COLLI_OFF)return;
	if(get_v()<0.00001)return;
	std::vector<CubeCreature*>*creature_v;
	CubeCreature* avoid_creature;
	int x=in_x(),y=in_y(),z=in_z();
	for(int i=-1;i<=1;i++){
		for(int j=-1;j<=1;j++){
			for(int k=-1;k<=1;k++){
				creature_v=map->creature_map->get_creature_map(x+i,y+j,z+k);
				for(unsigned i=0;i<creature_v->size();i++){
					avoid_creature=creature_v->at(i);
					if(avoid_creature!=this&&avoid_creature->colli_state()!=C_STATE_COLLI_OFF
							&&avoid_creature->belong_to()==belong_to())
					if(pre_collide(creature_v->at(i))){
						creature_v->at(i)->avoid_collision(this);
					}
				}
			}
		}
	}
}
Beispiel #12
0
void
usrAppInit(void)
{
    printf("In usr usrAppInit\n");
//    task_leds_start();
    int i = 0;
    uint32_t cnt = 0;
    uint32_t heart_5[5];
    uint32_t heart;
    uint32_t max;
    uint32_t min;
    uint32_t total;
    adc_init();

    OSTaskChangePrio(0, 7);

    uint32_t ad;
    uint32_t pre_ad = get_v();
    pre_tick = tickGet();
    while (1)
    {
        ad = get_v();
        if ((pre_ad < 570) && (ad >= 570))
        {
//            printf("%d pre_ad:%d ad:%d", i++, pre_ad, ad);
            heart_tick = tickGet();
            pre_tick = heart_tick - pre_tick;
            heart = (1200000 / pre_tick);
            if (heart > 35*10 && heart < 180*10)
            {
                memmove(&heart_5[0], &heart_5[1], 4*sizeof(uint32_t));
                heart_5[4] = heart;
                if (cnt < 5)
                {
                    cnt++;
                }
                else
                {
                    total = max = min = heart_5[0];
                    for(int i = 1; i < 5; i++)
                    {
                        total += heart_5[i];

                        if (heart_5[i] > max)
                        {
                            max = heart_5[i];
                        }
                        if (heart_5[i] < min)
                        {
                            min = heart_5[i];
                        }
                    }
                    heart = (total - max - min) / 3;

                    printf("心率:%d.%d\n", heart / 10,  heart % 10);//pre_tick
                }
            }

            pre_tick = heart_tick;
            sys_gpio_write(IO_LED2, E_LED_ON);
        }
        else if ((ad < 570) && (pre_ad >= 570))
        {
            sys_gpio_write(IO_LED2, E_LED_OFF);
        }

        pre_ad = ad;
        taskDelay(2);
    }
}
Beispiel #13
0
static int64_t get_s(ByteIOContext *bc){
    int64_t v = get_v(bc) + 1;

    if (v&1) return -(v>>1);
    else     return  (v>>1);
Beispiel #14
0
int VFrame::clear_frame()
{
	int sz = w * h;
//printf("VFrame::clear_frame %d\n", __LINE__);
	switch(color_model) {
	case BC_COMPRESSED:
		break;

	case BC_YUV410P:
		bzero(get_y(), sz);
		bzero(get_u(), w / 4 * h / 4);
		bzero(get_v(), w / 4 * h / 4);
		break;

	case BC_YUV411P:
	case BC_YUV420P:
		bzero(get_y(), sz);
		bzero(get_u(), sz / 4);
		bzero(get_v(), sz / 4);
		break;

	case BC_YUV422P:
		bzero(get_y(), sz);
		bzero(get_u(), sz / 2);
		bzero(get_v(), sz / 2);
		break;

	case BC_RGBA_FLOATP: if( a ) {
		float *ap = (float *)a;
		for( int i=sz; --i>=0; ++ap ) *ap = 1.f; }
	case BC_RGB_FLOATP: {
		float *rp = (float *)y;
		for( int i=sz; --i>=0; ++rp ) *rp = 0.f;
		float *gp = (float *)u;
		for( int i=sz; --i>=0; ++gp ) *gp = 0.f;
		float *bp = (float *)v;
		for( int i=sz; --i>=0; ++bp ) *bp = 0.f;
		break; }
	case BC_YUV444P:
		bzero(get_y(), sz);
		bzero(get_u(), sz);
		bzero(get_v(), sz);
		break;

	case BC_YUV888:
		ZERO_YUV(3, unsigned char, 0xff);
		break;

	case BC_YUVA8888:
		ZERO_YUV(4, unsigned char, 0xff);
		break;

	case BC_YUV161616:
		ZERO_YUV(3, uint16_t, 0xffff);
		break;

	case BC_YUVA16161616:
		ZERO_YUV(4, uint16_t, 0xffff);
		break;

	default:
		bzero(data, calculate_data_size(w, h, bytes_per_line, color_model));
		break;
	}
	return 0;
}
Beispiel #15
0
void disp()
{
Lcd_Custom_Cmd(LCD_CURSOR_OFF);
Lcd_Custom_Cmd(LCD_CLEAR);
 switch(c1)
        {
          case 1:
          bat=get_v(bat_temp);
          bat=bat*6;
          bat_int=bat/1000;
          bat=bat/10;// integer part
        //  bat_d2=bat%10;  // fractional part upto 2 dec places
          bat=bat/10;
          bat_d1=bat%10;
          temp_bat[0]=(bat_int/10)+48;
          temp_bat[1]=bat_int%10 + 48;
         /* Lcd_Custom_Cmd(LCD_CLEAR);
          Lcd_Custom_Cmd(LCD_CURSOR_OFF); */
          Lcd_Custom_Out(1,1," Batt V  :");
          Lcd_Custom_Out(1,12,temp_bat);
          Lcd_Custom_Chr_CP('.');
          Lcd_Custom_Chr_CP(48+bat_d1);
         // Lcd_Custom_Chr_CP(48+bat_d2);
          Lcd_Custom_Chr_CP('V');


          ct_int=ct/100;// integer part
       //   ct_d2=ct%10;  // fractional part upto 2 dec places
          ct=ct/10;
          ct_d1=ct%10;
          if(ct_neg==1)
          Lcd_Custom_Chr(2,11,'-');

          temp_ct[0]=(ct_int/100)+48;
          temp_ct[1]=(ct_int/10)%10 + 48;
          temp_ct[2]=ct_int%10 + 48;

          Lcd_Custom_Out(2,1," Coolant :");
          Lcd_Custom_Out(2,12,temp_ct);


          Lcd_Custom_Chr_CP('.');
          Lcd_Custom_Chr_CP(48+ct_d1);
         // Lcd_Custom_Chr_CP(48+ct_d2);
          Lcd_Custom_Chr_CP(223);
          Lcd_Custom_Chr_CP('C');




           lop_int=lop/100;// integer part
          // lop_d2=lop%10;  // fractional part upto 2 dec places
           lop=lop/10;
           lop_d1=lop%10;
           //converting to ASCII for display
           temp_lop[0]=(lop_int/100)+48;
           temp_lop[1]=(lop_int/10)%10 + 48;
           temp_lop[2]=lop_int%10 + 48;


           Lcd_Custom_Out(3,1," L O P   :");
           Lcd_Custom_Out(3,12,temp_lop);
           Lcd_Custom_Chr_CP('.');
           Lcd_Custom_Chr_CP(48+lop_d1);
          // Lcd_Custom_Chr_CP(48+lop_d2);
           Lcd_Custom_Chr_CP('p');
           Lcd_Custom_Chr_CP('s');
           Lcd_Custom_Chr_CP('i');



           Lcd_Custom_Out(4,1," E G Temp: ");

           Lcd_Custom_Chr_CP((egt/100)+48);
           Lcd_Custom_Chr_CP((egt/10)%10 + 48);
           Lcd_Custom_Chr_CP(egt%10 + 48);

           Lcd_Custom_Chr_CP(223);
           Lcd_Custom_Chr_CP('C');
        break;

           case 2:
          // c1=0;
           Lcd_Custom_Cmd(LCD_CLEAR);
           Lcd_Custom_Cmd(LCD_CURSOR_OFF);
           Lcd_Custom_Out(1,1," E RPM   : ");

           Lcd_Custom_Chr_CP((freq/1000)+48);
           Lcd_Custom_Chr_CP((freq/100)%10 + 48);
           Lcd_Custom_Chr_CP((freq/10)%10 + 48);
           Lcd_Custom_Chr_CP(freq%10 + 48);


                       //displaying parameter values
          cot_int=cot/100;// integer part
       //   cot_d2=cot%10;  // fractional part upto 2 dec places
          cot=cot/10;
          cot_d1=cot%10;
          //converting to ASCII for display
          temp_cot[0]=(cot_int/100)+48;
          temp_cot[1]=(cot_int/10)%10 + 48;
          temp_cot[2]=cot_int%10 + 48;

          Lcd_Custom_Out(2,1," C O Temp:");
          Lcd_Custom_Out(2,12,temp_cot);
          Lcd_Custom_Chr_CP('.');
          Lcd_Custom_Chr_CP(48+cot_d1);
         // Lcd_Custom_Chr_CP(48+cot_d2);
          Lcd_Custom_Chr_CP(223);
          Lcd_Custom_Chr_CP('C');


                       //displaying parameter values
          imt_int=imt/100;// integer part
       //   imt_d2=imt%10;  // fractional part upto 2 dec places
          imt=imt/10;
          imt_d1=imt%10;
          //converting to ASCII for display
          temp_imt[0]=(imt_int/100)+48;
          temp_imt[1]=(imt_int/10)%10 + 48;
          temp_imt[2]=imt_int%10 + 48;
          Lcd_Custom_Out(3,1," I M Temp:");
          Lcd_Custom_Out(3,12,temp_imt);
          Lcd_Custom_Chr_CP('.');
          Lcd_Custom_Chr_CP(48+imt_d1);
       //   Lcd_Custom_Chr_CP(48+imt_d2);
          Lcd_Custom_Chr_CP(223);
          Lcd_Custom_Chr_CP('C');
          break;
        }
 }