Esempio n. 1
0
File: add.c Progetto: 8l/rsp
/*
 * -1:  VT *= -1, because VS < 0 // VT ^= -2 if even, or ^= -1, += 1
 *  0:  VT *=  0, because VS = 0 // VT ^= VT
 * +1:  VT *= +1, because VS > 0 // VT ^=  0
 *      VT ^= -1, "negate" -32768 as ~+32767 (corner case hack for N64 SP)
 */
INLINE static void do_abs(pi16 VD, pi16 VS, pi16 VT)
{
    i16 neg[N], pos[N];
    i16 nez[N], cch[N]; /* corner case hack -- abs(-32768) == +32767 */
    ALIGNED i16 res[N];
    register int i;

    vector_copy(res, VT);
    for (i = 0; i < N; i++)
        cch[i]  = (res[i] == -32768);

    for (i = 0; i < N; i++)
        neg[i]  = (VS[i] <  0x0000);
    for (i = 0; i < N; i++)
        pos[i]  = (VS[i] >  0x0000);
    vector_wipe(nez);

    for (i = 0; i < N; i++)
        nez[i] -= neg[i];
    for (i = 0; i < N; i++)
        nez[i] += pos[i];

    for (i = 0; i < N; i++)
        res[i] *= nez[i];
    for (i = 0; i < N; i++)
        res[i] -= cch[i];
    vector_copy(VACC_L, res);
    vector_copy(VD, VACC_L);
    return;
}
Esempio n. 2
0
  int matrix_square_root_n(int n, double *X, double *I, double *Y) {

    /*
      This function calculates one of the square roots of the matrix X and stores it in Y:
      X = sqrt(Y);
      X needs to be a symmetric positive definite matrix of dimension n*n in Fortran vector
      format. Y is of course a vector of similar size, and will contain the result on exit.
      Y will be used as a workspace variable in the meantime.
      The variable I is a vector of length n containing +1 and -1 elements. It can be used
      to select one of the 2^n different square roots of X
      This function first calculates the eigenvalue decomposition of X: X = U*D*U^T
      A new matrix F is then calculated with on the diagonal the square roots of D, with
      signs taken from I.
      The square root is then obtained by calculating U*F*U^T
    */

    if (check_input(X, Y, "matrix_square_root_n")) return 1;

    double *eigval, *eigvec, *temp;
    int info = 0, i, j;

    /* Memory allocation */
    eigval=(double*) malloc(n*sizeof(double));
    eigvec=(double*) malloc(n*n*sizeof(double));
    temp=(double*) malloc(n*n*sizeof(double));
    if ((eigval==NULL)||(eigvec==NULL)||(temp==NULL)) {
      printf("malloc failed in matrix_square_root_n\n");
      return 2;
    }

    /* Eigen decomposition */
    info=eigen_decomposition(n, X, eigvec, eigval);
    if (info != 0) return info;

    /* Check for positive definitiveness*/
    for (i=0; i<n; i++) if (eigval[i]<0) {
	fprintf(stderr, "In matrix_square_root_n: Matrix is not positive definite.\n");
	return 1;
      }

    /* Build square rooted diagonal matrix, with sign signature I */
    for (i=0; i<n; i++) for (j=0; j<n; j++) Y[i*n+j] = 0.0;
    for (i=0; i<n; i++) Y[i*n+i] = I[i]*sqrt(eigval[i]);

    /* Multiply the eigenvectors with this diagonal matrix Y. Store back in Y */
    matrix_matrix_mult(n, n, n, 1.0, 0, eigvec, Y, temp);
    vector_copy(n*n, temp, Y);

    /* Transpose eigenvectors. Store in temp */
    matrix_transpose(n, n, eigvec, temp);

    /* Multiply Y with this temp. Store in eigvec which is no longer required. Copy to Y */
    matrix_matrix_mult(n, n, n, 1.0, 0, Y, temp, eigvec);
    vector_copy(n*n, eigvec, Y);

    /* Cleanup and exit */
    free(eigvec); free(eigval); free(temp);
    return info;
  }
Esempio n. 3
0
void vector_calculateNormal(vector3D_t* normalOutput, vector3D_t* dif1, vector3D_t* dif2)
{
	vector3D_t t0, t1;

	vector_copy(&t0, dif1);
	vector_copy(&t1, dif2);

	vector_normalize(&t0);
	vector_normalize(&t1);

	vector_cross(normalOutput, &t0, &t1);
	vector_normalize(normalOutput);
}
Esempio n. 4
0
File: logical.c Progetto: Azimer/rsp
VECTOR_OPERATION VXOR(v16 vs, v16 vt)
{
#ifdef ARCH_MIN_SSE2
    vector_xor(vs, vt);
    *(v16 *)VACC_L = vs;
    return (vs);
#else
    vector_copy(VACC_L, vt);
    vector_xor(VACC_L, vs);
    vector_copy(V_result, VACC_L);
    return;
#endif
}
Esempio n. 5
0
  int eigen_decomposition(int n, double* X, double *eigvec, double *eigval) {
    /*
      This function calculates the eigenvalues and eigenvectors of
      the n*n symmetric matrix X.
      The matrices have to be in Fortran vector format.
      The eigenvectors will be put columnwise in the n*n matrix eigvec,
      where the corresponding eigenvalues will be put in the vector
      eigval (length n of course). Only the lower triangle of the matrix
      X is used. The content of X is not changed.
      This function first queries the Lapack routines for optimal workspace
      sizes. These memoryblocks are then allocated and the decomposition is
      calculated using the Lapack function "dsyevr". The allocated memory
      is then freed.
    */

    double *WORK, *Xc;
    int *ISUPPZ, *IWORK;
    int numeig, info, sizeWORK, sizeIWORK;

    if (check_input(X, eigvec, "eigen_decomposition")) return 1;

    /* Use a copy of X so we don't need to change its value or use its memoryblock */
    Xc=(double*) malloc(n*n*sizeof(double));

    /* The support of the eigenvectors. We will not use this but the routine needs it */
    ISUPPZ = (int*) malloc (2*n*sizeof(int));

    /* Allocate temporarily minimally allowed size for workspace arrays */
    WORK = (double*) malloc (26*n*sizeof(double));
    IWORK = (int*) malloc (10*n*sizeof(int));

    /* Check for NULL-pointers. */
    if ((Xc==NULL)||(ISUPPZ==NULL)||(WORK==NULL)||(IWORK==NULL)) {
      printf("malloc failed in eigen_decomposition\n");
      return 2;
    }

    vector_copy(n*n, X, Xc);

    /* Query the Lapack routine for optimal sizes for workspace arrays */
    info=dsyevr ('V', 'A', 'L', n, Xc, n, 0, 0, 0, 0, dlamch('S'), &numeig, eigval, eigvec, n, ISUPPZ, WORK, -1, IWORK, -1);
    sizeWORK = (int)WORK[0];
    sizeIWORK = IWORK[0];

    /* Free previous allocation and reallocate preferable workspaces, Check result */
    free(WORK);free(IWORK);
    WORK = (double*) malloc (sizeWORK*sizeof(double));
    IWORK = (int*) malloc (sizeIWORK*sizeof(int));
    if ((WORK==NULL)||(IWORK==NULL)) {
      printf("malloc failed in eigen_decomposition\n");
      return 2;
    }

    /* Now calculate the eigenvalues and vectors using optimal workspaces */
    info=dsyevr ('V', 'A', 'L', n, Xc, n, 0, 0, 0, 0, dlamch('S'), &numeig, eigval, eigvec, n, ISUPPZ, WORK, sizeWORK, IWORK, sizeIWORK);

    /* Cleanup and exit */
    free(WORK); free(IWORK); free(ISUPPZ); free(Xc);
    return info;
  }
Esempio n. 6
0
static void back_propagate_RN(pbqp_t *pbqp, pbqp_node_t *node)
{
	vector_t *vec = vector_copy(pbqp, node->costs);

	for (unsigned edge_index = 0; edge_index < pbqp_node_get_degree(node); edge_index++) {
		/* get neighbor node */
		pbqp_edge_t *edge     = node->edges[edge_index];
		pbqp_node_t *neighbor = edge->src == node ? edge->tgt : edge->src;

		/* node is edge src node */
		if (edge->src == node)
			vector_add_matrix_col(vec, edge->costs, neighbor->solution);
		/* node is edge tgt node */
		else
			vector_add_matrix_row(vec, edge->costs, neighbor->solution);
	}

	assert(vector_get_min(vec) != INF_COSTS);
	node->solution = vector_get_min_index(vec);

#if KAPS_DUMP
	if (pbqp->dump_file) {
		fprintf(pbqp->dump_file, "node n%u is set to %u<br>\n", node->index, node->solution);
	}
#endif

	obstack_free(&pbqp->obstack, vec);
}
Esempio n. 7
0
//sets up the view
void view2D_set(View2D *view, Point *vrp, double dx, Vector *x, double screenx, double screeny){
	point_copy(&(view->vrp), vrp);
	view->dx = dx;
	vector_copy(&(view->x), x);
	view->screenx = screenx;
	view->screeny = screeny;
}
Esempio n. 8
0
File: add.c Progetto: 8l/rsp
VECTOR_OPERATION VSAW(v16 vs, v16 vt)
{
    const unsigned int element = (inst >> 21) & 0x7;

    vt = vs; /* unused */
    if (element > 0x2)
    { /* branch very unlikely...never seen a game do VSAW illegally */
        message("VSAW\nIllegal mask.");
#ifdef ARCH_MIN_SSE2
        vector_wipe(vs);
#else
        vector_wipe(V_result);
#endif
    }
    else
    {
#ifdef ARCH_MIN_SSE2
        vs = *(v16 *)VACC[element];
#else
        vector_copy(V_result, VACC[element]);
#endif
    }
#ifdef ARCH_MIN_SSE2
    return (vs);
#else
    return;
#endif
}
int main() {
    struct vector_t myVector, secondVector;

    vector_init(&myVector);

    vector_push_back(&myVector,3);
    vector_push_back(&myVector,1);
    vector_push_back(&myVector,4);
    vector_push_back(&myVector,1);
    vector_push_back(&myVector,5);
    vector_push_back(&myVector,9);
    vector_push_back(&myVector,2);
    vector_push_back(&myVector,6);

    vector_copy(&myVector, &secondVector);
    printf("Size of copied vector: %d\n", vector_get_size(secondVector));

    printf("Size: %d\n", vector_get_size(myVector));
    printf("Pop: %d\n", vector_pop_back(&myVector));
    printf("Pop: %d\n", vector_pop_back(&myVector));
    printf("Pop: %d\n", vector_pop_back(&myVector));
    printf("Pop: %d\n", vector_pop_back(&myVector));
    printf("Pop: %d\n", vector_pop_back(&myVector));
    printf("Size: %d\n", vector_get_size(myVector));
    printf("Pop: %d\n", vector_pop_back(&myVector));
    printf("Pop: %d\n", vector_pop_back(&myVector));
    printf("Pop: %d\n", vector_pop_back(&myVector));
    printf("Size: %d\n", vector_get_size(myVector));

    vector_destroy(&myVector);
    return 0;
}
/*
% project v in direction of u
function p=project_vec(v,u)
p = (dot(v,u)/norm(u)^2)*u;
*/
void project_vector(vec *v, vec *u, vec *p){
    double dot_product_val, vec_norm, scalar_val; 
    dot_product_val = vector_dot_product(v, u);
    vec_norm = vector_get2norm(u);
    scalar_val = dot_product_val/(vec_norm*vec_norm);
    vector_copy(p, u);
    vector_scale(p, scalar_val); 
}
Esempio n. 11
0
void vector_add_to_new(double *z,
                       double *x,
                       double *y,
                       double factor,
                       int n) {
  vector_copy(z, x, n);
  vector_add(z, y, factor, n);
}
Esempio n. 12
0
//从点p,到地面的距离,如果就在地面上返回0
float FallLength( float p[3] ){
	float fl = 0;
	float v[6];
	unsigned long flag = 0X100111;
	vector_copy(v,p);
	vector_copy(&(v[3]),p);
	v[5] += 2;
	if( HitWrap(v,&g_collide,flag,0) != 0 ){
		if( g_collide.iDownCount > 0 ){
			float z = FLT_MAX;
			if( g_Downs[0].n[2] != 0 )
				z = -(g_Downs[0].n[0]*p[0] + g_Downs[0].n[1]*p[1] + g_Downs[0].n[3])/g_Downs[0].n[2];
			fl = p[2] - z;
		}
	}
	return fl;
}
Esempio n. 13
0
/**
 * Copy an array of vectors into another one.
 *
 * @param struct vector_t *const the old vector array
 * @param const struct vector_t *const the new vector array
 * @param const int the size of the array
 */
void vector_arrayCopy(struct vector_t *const oldVector, const struct vector_t *const newVector, const int arraySize)
{
    int i = 0;

    for (i = 0; i < arraySize; i++) {
        vector_copy((oldVector + i), (newVector + i));
    }
}
Esempio n. 14
0
Grid Grid::solve_difference_3layer(int time_steps) {
	std::vector< double > data(this->data);	
	std::vector< double > auxiliary1;
	std::vector< double > auxiliary2(size, 0);
	for (int i = 0; i < size - 1; i++)
		auxiliary2[i + 1] = data[i];

	double y = dt * xi / dh;		
	int steps = time_steps / dh;
	for (int j = 1; j < steps; j++) { // starting with 1 because we start with the 3rd layer, not with the 2nd one
		vector_copy(auxiliary1, auxiliary2);
		vector_copy(auxiliary2, data);
		data[size - 2] = 0;
		for (int i = 0; i < size - 1; i++) 
			data[i] = auxiliary1[i] + y * (auxiliary2[i - 1] - auxiliary2[i + 1]);
	}
	return Grid(data, dh, dt, xi);
}
Esempio n. 15
0
void eta_file_ftran(eta_file* ef, EXLPvector* b, EXLPvector* x, EXLPvector* w) {
  /* Bx = b  を解く. */
  eta_matrix* U;
  int  i;
  mpq_t  q;

  mpq_init(q);

  U = my_malloc(sizeof(eta_matrix));
  vector_copy(x, b);

  for (i = 0; i < ef->U->columns; i ++) {
    vector_swap_elements(x, i, ef->P[i]);
    eta_matrix_mul_vector(ef->L[i], x);
  }
  for (i = 0; i < ef->s; i ++) {
    if (ef->Ls[i]->row == ef->Ls[i]->column) {
      vector_mul_element(x, ef->Ls[i]->value, ef->Ls[i]->row);
    } else {
      vector_get_element(&q, x, ef->Ls[i]->column);
      if (mpq_sgn(q)==0)continue;
      mympq_mul(q, q, ef->Ls[i]->value);
      vector_add_element(x, q, ef->Ls[i]->row);
    }
  }

  vector_permutate_inv(ef->Q, x);
  if (w != NULL)
    vector_copy(w, x);
  //if (w!=NULL)printf("(%d ", w->nonzeros),fflush(stdout);

  for (i = ef->U->columns-1; i >= 0; i --) {
    U->eta_column = i;
    U->eta_vector = ef->U->column[i];
    eta_matrix_solve_Ex_is_equal_to_v(U, x);
  }

//fprintf(stderr, "%d ",x->i[0]);
  vector_permutate_inv(ef->R, x);
  //printf(" %d)", x->nonzeros);fflush(stdout);

  mpq_clear(q);
  free(U);
}
Esempio n. 16
0
// Fourier descriptor
int test_fourier_descriptor(vector_t *fd, point_list_t *plist)
{
  int i, n;
  vector_t *time, *fourier, *fd;
  complex_t comp;

  assert(fd);
  assert(plist);
  assert(vecter_get_length(fd) == point_list_get_count(plist));

  time = cvector_new_and_copy_point_list(plist);
  fourier = vector_new(vector_get_length(time), true);
  //fd = vector_new(vector_get_length(time), true);

  dft(fourier, time);
  n = vector_get_length(time);

  // filtering
  /*
  comp.real = comp.imag = 0.0;
  for (i = n / 2 - 16; i < n / 2 + 16; i++) {
    cvector_put_value(comp, i, fourier);
  }
  */

  ///////////////////////  Normalization ////////////////////////////
  vector_copy(fd, fourier);
  // For translation invariance, 0 frequency must have a zero value
  cvector_put_value(comp, 0, fd);

  // For scale invariance,
  // fourier descriptor must be divied by the absolute of 1 frequency component.
  cvector_read_value(&comp, 1, fd);
  val = complex_get_abs(&comp);
  vector_divide_scalar(fd, val);
  ivector_divide_scalar(fd, val);

  // For rotating and changes in starting point
  // remove all phase information and
  // consider only absolute values of the descriptor element
  //f = fopen("fourier_descriptor.txt", "a+");
  //fprintf(f, "%s", fn);
  for (i = 0; i < vector_get_length(fd); i++) {
    cvector_read_value(&comp, i, fd);
    val = complex_get_abs(&comp);
    vector_put_value(val, i, fd);
    ivector_put_value(0, i, fd);
    //fprintf(f, ", %lf", val);
  }
  //fprintf(f, "\n");
  //fclose(f);
  ///////////////////////////////////////////////////////////////////

  //  idft(time, fourier);
  return n;
}
Esempio n. 17
0
  //Invert twisted mass operator using e/o preconditioning.
  THREADABLE_FUNCTION_8ARG(inv_tmD_cg_eoprec, spincolor*,solution_lx, spincolor*,guess_Koo, quad_su3*,conf_lx, double,kappa, double,mass, int,nitermax, double,residue, spincolor*,source_lx)
  {
    if(!use_eo_geom) crash("eo geometry needed to use cg_eoprec");
    
    //prepare the e/o split version of the source
    spincolor *source_eos[2];
    source_eos[0]=nissa_malloc("source_eos0",loc_volh+bord_volh,spincolor);
    source_eos[1]=nissa_malloc("source_eos1",loc_volh+bord_volh,spincolor);
    split_lx_vector_into_eo_parts(source_eos,source_lx);
    
    //prepare the e/o split version of the solution
    spincolor *solution_eos[2];
    solution_eos[0]=nissa_malloc("solution_eos_0",loc_volh+bord_volh,spincolor);
    solution_eos[1]=nissa_malloc("solution_eos_1",loc_volh+bord_volh,spincolor);
    
    //prepare the e/o split version of the conf
    quad_su3 *conf_eos[2];
    conf_eos[0]=nissa_malloc("conf_eos_0",loc_volh+bord_volh,quad_su3);
    conf_eos[1]=nissa_malloc("conf_eos_1",loc_volh+bord_volh,quad_su3);
    split_lx_vector_into_eo_parts(conf_eos,conf_lx);
    
    ///////////////////////////////////// invert with e/o preconditioning ///////////////////////////////////
    
    //Equation (8.a)
    spincolor *temp=nissa_malloc("temp",loc_volh+bord_volh,spincolor);
    inv_tmDee_or_oo_eos(temp,kappa,mass,source_eos[EVN]);
    
    //Prepare the source according to Equation (8.b)
    spincolor *varphi=nissa_malloc("varphi",loc_volh+bord_volh,spincolor);
    inv_tmD_cg_eoprec_prepare_source(varphi,conf_eos,temp,source_eos[ODD]);
    
    //Equation (9) using solution_eos[EVN] as temporary vector
    inv_tmDkern_eoprec_square_eos_cg(temp,guess_Koo,conf_eos,kappa,mass,nitermax,residue,varphi);
    if(guess_Koo!=NULL) vector_copy(guess_Koo,temp); //if a guess was passed, return new one
    
    //Equation (10)
    tmDkern_eoprec_eos(solution_eos[ODD],solution_eos[EVN],conf_eos,kappa,-mass,temp);
    nissa_free(temp);
    
    //Equation (11)
    inv_tmD_cg_eoprec_almost_reco_sol(varphi,conf_eos,solution_eos[ODD],source_eos[EVN]);
    inv_tmDee_or_oo_eos(solution_eos[EVN],kappa,mass,varphi);
    nissa_free(varphi);
    
    /////////////////////////// paste the e/o parts of the solution together and free ///////////////////
    
    paste_eo_parts_into_lx_vector(solution_lx,solution_eos);
    
    for(int par=0;par<2;par++)
      {
	nissa_free(conf_eos[par]);
	nissa_free(source_eos[par]);
	nissa_free(solution_eos[par]);
      }
  }
Esempio n. 18
0
  THREADABLE_FUNCTION_6ARG(fft4d, complex*,out, complex*,in, int*,ext_dirs, int,ncpp, double,sign, int,normalize)
  {
    GET_THREAD_ID();
    
    //first of all put in to out
    if(out!=in) vector_copy(out,in);
    
    //list all dirs
    int dirs[NDIM],ndirs=0;
    for(int mu=0;mu<NDIM;mu++) if(ext_dirs[mu]) dirs[ndirs++]=mu;
    verbosity_lv2_master_printf("Going to FFT: %d dimensions in total\n",ndirs);
    
    if(ndirs)
      {
	//allocate buffer
	complex *buf=nissa_malloc("buf",max_locd_size*ncpp,complex);
	
	//allocate plans
	fftw_plan *plans=nissa_malloc("plans",ndirs,fftw_plan);
	if(IS_MASTER_THREAD)
	  for(int idir=0;idir<ndirs;idir++)
	    plans[idir]=fftw_plan_many_dft(1,glb_size+dirs[idir],ncpp,buf,NULL,ncpp,1,buf,NULL,ncpp,1,sign,FFTW_ESTIMATE);
	THREAD_BARRIER();
	
	//transpose each dir in turn and take fft
	for(int idir=0;idir<ndirs;idir++)
	  {
	    int mu=dirs[idir];
	    verbosity_lv2_master_printf("FFT-ing dimension %d/%d=%d\n",idir+1,ndirs,mu);
	    remap_lx_vector_to_locd(buf,out,ncpp*sizeof(complex),mu);
	    
	    //makes all the fourier transform
	    NISSA_PARALLEL_LOOP(ioff,0,locd_perp_size_per_dir[mu])
	      fftw_execute_dft(plans[idir],buf+ioff*glb_size[mu]*ncpp,buf+ioff*glb_size[mu]*ncpp);
	    THREAD_BARRIER();
	    
	    remap_locd_vector_to_lx(out,buf,ncpp*sizeof(complex),mu);
	  }
	
	//destroy plans
	if(IS_MASTER_THREAD) for(int idir=0;idir<ndirs;idir++) fftw_destroy_plan(plans[idir]);
	
	//put normaliisation
	if(normalize)
	  {
	    double norm=glb_size[dirs[0]];
	    for(int idir=1;idir<ndirs;idir++) norm*=glb_size[idir];
	    double_vector_prod_double((double*)out,(double*)out,1/norm,2*ncpp*loc_vol);
	  }
	
	nissa_free(buf);
	nissa_free(plans);
      }
  }
Esempio n. 19
0
 void inv_tmclovQ_cg(spincolor *sol,spincolor *guess,quad_su3 *conf,double kappa,clover_term_t *Cl,double mu,int niter,double residue,spincolor *source)
 {
   inv_tmclovQ2_cg(sol,NULL,conf,kappa,Cl,mu,niter,residue,source);
   spincolor *temp=nissa_malloc("temp",loc_vol+bord_vol,spincolor);
   
   //remove the "wrong r"
   vector_copy(temp,sol);
   apply_tmclovQ(sol,conf,kappa,Cl,-mu,temp);
   
   nissa_free(temp);
 }
Esempio n. 20
0
static void update_trails(void)
{
	int trail_index = (state.first_trail + state.num_trails) % MAX_TRAILS;
	for(int i = 0; i < state.sys->nplanets; i++)
		vector_copy(state.views[i].trails[trail_index], state.sys->planets[i].position);

	if(state.num_trails == MAX_TRAILS)
		state.first_trail++;
	else
		state.num_trails++;
}
Esempio n. 21
0
void gauge_conf_t::copy(gauge_conf_t &in)
{
  destroy();
  create();
  
  for(int mu=0;mu<4;mu++) theta[mu]=in.theta[mu];
  beta=in.beta;
  kappa=in.kappa;
  
  if(in.is_allocated()) vector_copy(U,in.U);
  else crash("copying from an unallocated conf");
}
Esempio n. 22
0
void test_vector_copy() {
  vector* v = create_test_vector();
  vector* copy = vector_copy(v);

  int* v_element =  (int*)vector_at(v, 5);
  int* copy_element =  (int*)vector_at(copy, 5);

  printf("v[5] = %i at %p\n", *v_element, v_element);
  printf("v[5] = %i at %p\n", *copy_element, copy_element);

  vector_free(v, NULL);
}
Esempio n. 23
0
Grid Grid::solve(int time_steps) {
	std::vector< double > data(this->data);	
	std::vector< double > auxiliary;
	int steps = time_steps / dh;
	for (int i = 0; i < steps; i++) {
		vector_copy(auxiliary, data);
		for (int j = 1; j < size; j++) {
			data[j] = auxiliary[j] - xi * dt * (auxiliary[j] - auxiliary[j - 1]) / dh;
		}
	}
	return Grid(data, dh, dt, xi);
}
Esempio n. 24
0
NIL_type Main_Reallocate_Vector_M(VRF_type Vector_reference,
                                  UNS_type Increment)
  { UNS_type new_size,
             old_size;
    VEC_type new_vector,
             old_vector;
    old_vector = *Vector_reference;
    old_size = size_VEC(old_vector);
    new_size = old_size + Increment;
    new_vector = make_VEC_Z(new_size);
    vector_copy(old_vector,
                new_vector);
    *Vector_reference = new_vector; }
Esempio n. 25
0
ray_of_death_t	*ray_of_death_ctor( vector_t *destination )
{
	ray_of_death_t	*rod = malloc(sizeof(*rod));
	hboolean	collides;

	body_create((body_t*)rod, &Ray_of_death);

	rod->intensity = MAX_ROD_INTENSITY;
	vector_copy(rod->body.pos, hedgehog[local_hedgehog]->body.pos);
	vector_inc(rod->body.pos, &arm1_relative_pos);
	vector_sub(destination, rod->body.pos, &rod->direction);
	vector_mul(&rod->direction, 500/vector_len(&rod->direction),
		   &rod->direction);
	collides = NULL != polygon_check_collision(map, rod->body.pos,
					   &rod->direction, destination);
	vector_sub(destination, rod->body.pos, &rod->direction);
	if (!collides)
	{
		vector_mul(&rod->direction, 500/vector_len(&rod->direction),
			   &rod->direction);
	}

	{
		int i;
		for(i = 0; i < 100; i++)
		{
			particle[i].pos.x =
				rod->body.pos->x + i * rod->direction.x / 100.0;
			particle[i].pos.y =
				rod->body.pos->y + i * rod->direction.y / 100.0;

			if (i % 2)
			{
				particle[i].color.red = 1;
				particle[i].color.green = 1;
				particle[i].color.blue = 1;
			}
			else
			{
				particle[i].color.red = 0;
				particle[i].color.green = 0;
				particle[i].color.blue = 1;
			}

		}
	}

	object_pool_push(&game_bodies, rod);

	return rod;
}
Esempio n. 26
0
static vertex *vertex_new(solid *s, vector v)
{
    vertex *vtx = (vertex*)malloc(sizeof(vertex));

    if(!vtx)
        return NULL;
    vtx->s = s;
    vtx->next = s->vertices;
    s->vertices = vtx;
    vector_copy(vtx->v, v);
    vector_init(vtx->f, 0, 0, 0);
    vector_init(vtx->vel, 0, 0, 0);
    return vtx;
}
Esempio n. 27
0
  //perform the fft in all directions
  void fft4d(complex *out,complex *in,int *dirs,int ncpp,double sign,int normalize)
  {
    //copy input in the output (if they differ!)
    if(out!=in) vector_copy(out,in);
    
    //perform the fft in each direction
    for(int mu=0;mu<NDIM;mu++)
      {
	//perform the 1d fft (slower dir)
	if(dirs[mu]) fft1d(out,out,ncpp*loc_vol/loc_size[mu],mu,sign,normalize);
	
	//for the time being we stick to transpose the data
	data_coordinate_order_shift(out,ncpp,mu);
      }
  }
Esempio n. 28
0
void test_vector_copy() {
    array *arr = vector_create();
    vector_append(arr, 0);
    vector_append(arr, 3);
    vector_append(arr, 5);
    array *copy_arr = vector_copy(arr);
    ASSERT(copy_arr->array[0] == 0);
    ASSERT(copy_arr->array[1] == 3);
    ASSERT(copy_arr->array[2] == 5);
    ASSERT(copy_arr->size == 3);
    ASSERT(copy_arr->capacity == 4);

    vector_free(arr);
    vector_free(copy_arr);
}
Esempio n. 29
0
int vector_copy_assign(Vector* destination, Vector* source) {
    assert(destination != NULL);
    assert(source != NULL);
    assert(vector_is_initialized(source));
    assert(vector_is_initialized(destination));

    if (destination == NULL) return VECTOR_ERROR;
    if (source == NULL) return VECTOR_ERROR;
    if (!vector_is_initialized(destination)) return VECTOR_ERROR;
    if (!vector_is_initialized(source)) return VECTOR_ERROR;

    vector_destroy(destination);

    return vector_copy(destination, source);
}
Esempio n. 30
0
File: add.c Progetto: 8l/rsp
INLINE static void set_bo(pi16 VD, pi16 VS, pi16 VT)
{ /* set CARRY and borrow out from difference */
    i32 dif[N];
    register int i;

    for (i = 0; i < N; i++)
        dif[i] = (u16)(VS[i]) - (u16)(VT[i]);
    for (i = 0; i < N; i++)
        VACC_L[i] = VS[i] - VT[i];
    for (i = 0; i < N; i++)
        cf_ne[i] = (VS[i] != VT[i]);
    for (i = 0; i < N; i++)
        cf_co[i] = (dif[i] < 0);
    vector_copy(VD, VACC_L);
    return;
}