Exemple #1
0
void euler(double dt, double *x, double *y)
{
  double x1, x2, y1, y2;
  
  myfunc(*x, *y, &x1, &y1);
  myfunc(dt * x1 + *x, dt * y1 + *y, &x2, &y2);
  *x += 0.5 * dt * (x1 + x2);
  *y += 0.5 * dt * (y1 + y2);
}
Exemple #2
0
void euler(double dt, double *x, double *y, double *z)
{
  double x1, x2, y1, y2, z1, z2;
  
  myfunc(*x, *y, *z, &x1, &y1, &z1);
  myfunc(dt * x1 + *x, dt * y1 + *y, dt * z1 + *z, &x2, &y2, &z2);
  *x += 0.5 * dt * (x1 + x2);
  *y += 0.5 * dt * (y1 + y2);
  *z += 0.5 * dt * (z1 + z2);
}
Exemple #3
0
/**
 * random walk metropolis sampling for a vector of parameters 
 * of length d using multivariate normal proposal
 *
 * @param d the dimension of the parameter
 * @param m current values of the parameter (also mean vector
 *      in the multivariate Normal)
 * @param v covariance matrix in the proposal distribution
 * @param sn simulated new vector 
 * @param myfunc user specified function to compute the log posterior 
 * @param data the struct used in myfunc
 *
 * @return  a 0-1 integer: 0 means not accepted and 1 accepted
 *
 */
int metrop_mvnorm_rw(int d, double *m, double *v, double *sn, 
		     double (*myfunc)(double *x, void *data), void *data){
  rmvnorm(d, m, v, sn) ;
  /* determine whether to accept the sample */
  double A = exp(myfunc(sn, data) - myfunc(m, data) ) ;
  if (A < 1 && runif(0, 1) >= A){
    Memcpy(sn, m, d) ;
    return 0 ;
  }
  else return 1 ;
  
}
Exemple #4
0
/**
 * RW Metropolis update using the truncated Normal 
 *
 * @param m the mean of the untruncated normal
 * @param sd the standard deviation of the untruncated normal
 * @param lb the left bound of the truncated normal
 * @param rb the right bound of the truncated normal
 * @param sn pointer to store simulated value
 * @param myfunc user specified function to compute the log posterior 
 * @param data the struct used in myfunc
 *
 * @return  a 0-1 integer: 0 means not accepted and 1 accepted
 */
int metrop_tnorm_rw(double m, double sd, double lb, double rb, double *sn, 
		     double (*myfunc)(double x, void *data), void *data){
  *sn = rtnorm(m, sd, lb, rb);
  double C = (lb == R_NegInf && rb == R_PosInf) ? 0.0 :  
    (dtnorm(m, *sn, sd, lb, rb) - dtnorm(*sn, m, sd, lb, rb));
  /* determine whether to accept the sample */
  double A = exp(myfunc(*sn, data) - myfunc(m, data) + C) ;  
  if (A < 1 && runif(0, 1) >= A){ 
    *sn = m ;
    return 0 ;
  }
  else return 1 ;  
}
Exemple #5
0
	    void GetLocation(cv::Mat& paramA,cv::Mat* img)
	        {
	        	if(paramA.empty())
	        		return;

	        	int r0=(img->rows-1)/2;
	        	//镜头横向近似中点:(img->cols-1)/2;
	        	dist_=(img->cols-1)/2-myfunc(paramA,r0);
	        	//计算拟合直线与y=0直线夹角;
	            theta_=atan((myfunc(paramA,r0+5)-myfunc(paramA,r0-5))/10);

	        	return;

	        };
Exemple #6
0
void main()
{
	int (*myfunc)(const char*);

	myfunc = puts;

	puts("hi~ good");
	myfunc("olleh~");

	myfunc = strlen;

	printf("str length : %d \n", strlen("aa"));
	printf("str2length : %d \n", myfunc("aa"));

}
Exemple #7
0
bool callAccessory(const char* accessory_func)
{
#ifdef XP_WIN32
  // Need to get a full path to load accessory.dll
  HMODULE hSelf = LoadLibraryW(L"crashme.dll");
  wchar_t accessory_path[MAX_PATH] = L"\0";
  if (!hSelf || !GetModuleFileNameW(hSelf, accessory_path, MAX_PATH))
    return false;

  wchar_t* s = wcsrchr(accessory_path, '\\');
  if (s) {
    s++;
    wcscpy(s, L"accessory.dll");
  }

  // accessory.dll is linked to mozcrt19.dll, so this load
  // will fail if our host build is not built with jemalloc.
  HMODULE hAccessory = LoadLibraryW(accessory_path);
  if (hAccessory) {
    typedef void (*accessory_ptr)();
    accessory_ptr myfunc = (accessory_ptr)GetProcAddress(hAccessory,
                                                         accessory_func);
    if (myfunc) {
      myfunc();
      return true; // not reached
    }
  }
#endif
  return false;
}
Exemple #8
0
int main()
{
    int x = 5;
    int y = myfunc(x);
    printf("Vals: %d %d\n", x, y);
    return 0;
}
Exemple #9
0
	    void DrawLine(cv::Mat& res,cv::Mat& paramA,cv::Point2f& pt_sta,cv::Point2f& pt_end)
	    {
	    	
	    	if(res.empty()||paramA.empty())
	    		return;
	    	int r=res.rows;
	    	int c=res.cols;
	    	int i,i_stop;
	    	if(pt_sta.x<=pt_end.x)
	    	{
	    	     i=pt_sta.x;
	    	     i_stop=pt_end.x;
	    	}
	    	else
	    	{
	    		 i_stop=pt_sta.x;
	    	     i=pt_end.x;

	    	}
	    	for(;i<i_stop;i++)
	    	{

	    		int y=myfunc(paramA,i);
	    		if(y<=0||y>=res.cols)
	    			continue;
	    		uchar* data = res.ptr<uchar>((int)i);
	    		 data[y * 3] = 0; //第row行的第col个像素点的第一个通道值 Blue
	             data[y * 3 + 1] = 0; // Green
	             data[y * 3 + 2] = 255; // Red
	    		// std::cout<<"["<<y<<","<<i<<"]"<<std::endl;
	    	}
	    	
	    	cv::imshow("result",res);

	    };
Exemple #10
0
void myfunc(int ncalls)
{
    if (ncalls > 1)
        myfunc(ncalls - 1);
    else
        myfunc2();
}
Exemple #11
0
VALUE call_tsk_istat(int argc, VALUE *args, VALUE self) {
  VALUE io; VALUE inum; VALUE options;
  rb_scan_args(argc, args, "21", &inum, &io, &options);
  if (! rb_obj_is_kind_of(io, rb_cIO) ) {
    rb_raise(rb_eArgError, "Method did not recieve IO object");
  }
  
  TSK_DADDR_T numblock; int32_t sec_skew;
  VALUE block = rb_hash_aref(options, ID2SYM(rb_intern("block")));
  if (! NIL_P(block)) { numblock = (TSK_DADDR_T)NUM2ULL(block); } else { numblock = 0; }
  VALUE skew = rb_hash_aref(options, rb_symname_p("skew"));
  if (! NIL_P(skew)) {  sec_skew = (int32_t)NUM2INT(skew); } else { sec_skew = 0; }

  TSK_INUM_T inum_int;
  inum_int = NUM2INT(inum);
  int fd = FIX2LONG(rb_funcall(io, rb_intern("fileno"), 0));
  FILE * hFile = fdopen((int)fd, "w");
  
  struct tsk4r_fs_wrapper * fs_ptr;
  Data_Get_Struct(self, struct tsk4r_fs_wrapper, fs_ptr);
  
  if (fs_ptr->filesystem != NULL) {
    uint8_t(*myfunc) (TSK_FS_INFO * fs, FILE * hFile, TSK_INUM_T inum,
                      TSK_DADDR_T numblock, int32_t sec_skew);
    myfunc = fs_ptr->filesystem->istat;
    int r = myfunc(fs_ptr->filesystem, hFile, inum_int, numblock, sec_skew);
    fflush(hFile); // clear file buffer, completing write
    if (r != 0 ) { rb_raise(rb_eRuntimeError, "TSK function: fsstat exited with an error."); }

  }
  return self;
}
Exemple #12
0
int main (int argc, char* argv[])
{
  char*  infilename;  char* outfilename;
  if (argc <= 2) {
    std::cout << "Usage: " << argv[0] << " infile outfile" << std::endl; 
    exit(1);
  } else {
    infilename = argv[1]; outfilename = argv[2];
  }
  std::ifstream ifile( infilename);
  std::ofstream ofile(outfilename);
  std::cout << argv[0] << ": converting " << infilename << " to "
	    << outfilename << std::endl;

  double x, y;
  std::ostringstream os;
  
  while (ifile >> x >> y) {
      y = myfunc(y);
      // printf's %g format
      os.unsetf(std::ios::floatfield);
      os << x << " ";
      os.setf(std::ios::scientific, std::ios::floatfield);
      os.precision(5);
      os << y << std::endl;
  }
  ofile << os.str();
}
int main(void)
{
	printf("x:%x y:%x\n",&x,&y);
  myfunc();
  printf("x = 0x%i y = 0x%i \n", x, y);
  return 0;
}
Exemple #14
0
int main (int argc, char* argv[])
{
  FILE *ifile;  /* input  file */
  FILE *ofile;  /* outout file */
  double x, y; 
  char *infilename;
  char *outfilename;
  int  n;
  int  ok;

  /* abort if there are too few command-line arguments */
  if (argc < 3) {
    printf("Usage: %s infile outfile\n", argv[0]);  exit(1);
  } else {
    infilename = argv[1]; outfilename = argv[2];
  }
  printf("%s: converting %s to %s\n",argv[0],infilename,outfilename);
  ifile = fopen( infilename, "r"); /* open for reading */
  ofile = fopen(outfilename, "w"); /* open for writing */

  ok = 1;  /* boolean variable for not end of file */
  while (ok) {
    n = fscanf(ifile, "%lf%lf", &x, &y); /* read x and y */
    if (n == 2) {
      /* successful read in fscanf: */
      /* printf("%g %12.5e\n", x, y); */
      y = myfunc(y);
      fprintf(ofile, "%g %12.5e\n", x, y);
    } else {
      /* no more numbers */ ok = 0;
    }
  }
  fclose(ifile);  fclose(ofile);
  return 0;
}
Exemple #15
0
main(){
cout << "hello \n ";

myfunc(0);

//return 0;

}
int main()
{
    Arg_comparator cmp;
    Item_bool_func2 equal_func;

    cmp.set_compare_func(&equal_func, 0);
    myfunc("cmp.func is %p (expected %p)\n", cmp.func, &compare_e_string);
}
Exemple #17
0
int main()
{

        myfunc();
		while(1)
			;
        return 0;
}
Exemple #18
0
int
myfunc_wrap(double x, double *y, double *a)
{
  int status;
  double dy;
  status = myfunc(x, y, &dy, *a);
  return status;
}
Exemple #19
0
int
main (void)
{
	printf ("calling myfunc()\n");
	myfunc ();
	printf ("done\n");

	return 0;
}
int main(){

  //std::vector<int> deb;
  //for(int i=0; i<10; i++) deb.push_back(i);

  std::vector<int> deb(10);
  for(int i=0; i<10; i++) deb[i] = i;
  for(auto it=deb.begin(); it < deb.end(); it++){
    std::cout << *it << std::endl;
  }

  myfunc();

  for(auto i=0; i<3; i++){
    myfunc();
  }
  return 1;
}
template <class T> void doSomething(T t) {
  assert(myfunc(1, 2));
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() that could be replaced by static_assert() [misc-static-assert]
  // CHECK-FIXES: {{^  }}static_assert(myfunc(1, 2), "");

  assert(t.method());
  // CHECK-FIXES: {{^  }}assert(t.method());

  assert(sizeof(T) == 123);
}
Exemple #22
0
int main(int argc, char *argv[])
{
    if (argc != 2) {
        fprintf(stderr, "%s num-calls\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    myfunc(atoi(argv[1]));
    exit(EXIT_SUCCESS);
}
Exemple #23
0
int main(int argc, char *argv[])
{
  if(argc < 2) {
    printf("usage: %s data\n", argv[0]); return 0;
  }
  printf("target: SHELL is at %p, system is at %p\n", getenv("SHELL"), &system);
  myfunc(argv);
  printf("And we returned safely from our function\n");
  return 0;
}
Exemple #24
0
int main (int argc, char ** argv)
{
    int a, b;
    if (argc < 3) {
        fprintf (stderr, "Too few arguments\n");
        return 1;
    }
    a = atoi (argv[1]);
    b = atoi (argv[2]);
    assert (myfunc (a, b) != FAIL_SUM);
    return 0;
}
int main(){
	
	int i = 0;
	while(1){
		fprintf(stdout, "Iteration number: %d\n", i+1);
		sleep(1);
		myfunc();
		fprintf(stdout, "second block");
		
	}
	
}
/** Finds one root in the given interval with the bisection method.
 * 
 *  Precision Mode:
 *  Set "max_runs" to 0 if you want to run until the desired precision is reached
 *
 *  Max Run Mode:
 *  Set "max_runs" to the amount of runs you want to calculate.
 *  This Mode ignores the precision parameter.   
 *
 */
void find_root_with_bisection(double interval_start, double interval_end, double precision, int max_runs)
{
  double current_precision = interval_end - interval_start;
  double interval_middle = ( interval_end + interval_start ) / 2 ;
  int run = 1;
  
  while( (current_precision > precision) & (run != max_runs) )
  {
    // check in which interval the root is. set the new interval borders
    if( myfunc(interval_start) * myfunc(interval_middle) < 0 ) interval_end = interval_middle; 
    else interval_start = interval_middle;

    // calculate current precision and the new interval middle
    current_precision = interval_end - interval_start; 
    interval_middle = ( interval_end + interval_start ) / 2 ;
    run++;
  }

  printf("Reached precision of %lf after %d runs. Root found at %lf\n", current_precision, run, interval_middle);
  return;
}
Exemple #27
0
int main ()
{
    int local = 5; // a local variable
    void *p = malloc(128); //a pointer to the beginning of a 128 byte piece of memory
    printf ("Address of main is %p\n", main);
    printf ("Address of global is %p\n", &global);
    printf ("Address of local is %p\n", &local);
    myfunc();
    mymalloc();
    printf ("Address of p is %p\n", p);
    
    return 0;
}
Exemple #28
0
void myfunc(int n,int k)
{
	if(n < 0 )return;
	if(n == 0)
	{
		count++;
		return;
	}
	int i;

	for(i = k; i < 4; i++)
	{	
	   	myfunc(n - num[i],i);
	}
}
Exemple #29
0
int main(int argc, char *argv[]) {
	int r = 0;
	e4c_using_context(E4C_FALSE) {
		e4c_context_set_handlers(NULL, NULL, BackTrace_create_for_exception, BackTrace_destroy);
		try {
			myfunc();
		}
		catch (RuntimeException) {
			const e4c_exception *e = e4c_get_exception();
			fprintf(stderr, "%s: %s", e->name, e->message);
			if (e->custom_data) {
				BackTrace_dump(e->custom_data);
			}
			r = 1;
		}
	}
	return r;
}
/** Finds one root in the given interval with the newton-raphson method.
 * 
 *  Precision Mode:
 *  Set "max_runs" to 0 if you want to run until the desired precision is reached
 *
 *  Max Run Mode:
 *  Set "max_runs" to the amount of runs you want to calculate.
 *  This Mode ignores the precision parameter.   
 *
 */
void find_root_with_newton(double interval_start, double interval_end, double precision, int max_runs)
{
  double current_precision = interval_end - interval_start;
  int run = 1;
  
  while( (current_precision > precision) & (run != max_runs) )
  {
    double old_interval_end = interval_end;

    interval_end -= myfunc(interval_end) / myfunc_der(interval_end);
    
    current_precision = fabs( old_interval_end - interval_end ) / 2.0;
    run++;
  }

  printf("Reached precision of %lf after %d runs. Root found at %lf\n", current_precision, run, interval_end);
  return;
}