int main(int argc, char **argv) { const int n = 3; // init our vectors of size n struct vector *x = vector_create(n); struct vector *y = vector_create(n); struct vector *z = vector_create(n); struct vector *z_ref = vector_create(n); // initialize values for testing for (int i = 0; i < n; i++) { VEC(x, i) = i + 1.f; VEC(y, i) = i + 2.f; VEC(z_ref, i) = 2*i + 3.f; } // test the vector_add() vector_add(x, y, z); // and make sure it equals the reference result assert(vector_is_equal(z, z_ref)); // clean up vector_destroy(x); vector_destroy(y); vector_destroy(z); vector_destroy(z_ref); return 0; }
/* * write_data * * Takes a FILE*, a data vector, a grid vector * a size and a mode. * mode 0: write real values * mode 1: write complex values * mode 2: write both real and comples values */ void write_data( FILE *fp, vector *v, vector *grid, const int n, int mode ) { int i; for( i = 0; i < n; i++ ) fprintf( fp, "%g %g\n", creal(VEC( grid, i )), creal(VEC( v, i )) ); }
void vv_remove(void *xx, int size, int i, int n) { char *x = xx; assert(size == VEC(x)->size); memmove(x+i*size, x+(i+n)*size, size * (VEC(x)->nelt-i-n)); VEC(x)->nelt -= n; }
void *vv_insert(void *xx, int size, int i, void *e, int n V_DEBUGPARAMS) { char *x = xx; assert(!x || size == VEC(x)->size); x=vv_growk(x, size, n V_DEBUGARGS); memmove(x+(i+n)*size, x+i*size, size*(VEC(x)->nelt-n-i)); memcpy(x+i*size, e, n*size); return x; }
static CVECTOR *VECTOR_copy(CVECTOR *_object) { CVECTOR *copy = VECTOR_create(SIZE(THIS), COMPLEX(THIS), FALSE); if (!COMPLEX(THIS)) gsl_vector_memcpy(VEC(copy), VEC(THIS)); else gsl_vector_complex_memcpy(CVEC(copy), CVEC(THIS)); return copy; }
void pdu_pdt( Vector *u, Vector *s, double dx ) { int i; double dx_3 = pow(dx,3); #pragma omp parallel for for( i = 0; i < u -> N; i++ ) { VEC(s,i) = -6 *VEC(u,i) * du_x(u,i,dx) -du_xxx(u,i,dx_3); } }
/* * fft * * Takes an input vector, output vector and a number of points * Performs a Fast Fourier Transform on the input vector * and stores it in the output vector. */ void fft( vector *in, vector *out, int n ) { int k; if( n == 1 ) VEC( out, 0 ) = VEC( in, 0 ); else { complex double wn = cexp( -2*M_PI*I / n ); vector *x, *y, *p, *q; create_vector( &x, n/2 ); create_vector( &y, n/2 ); create_vector( &p, n/2 ); create_vector( &q, n/2 ); for( k = 0; k < n/2; k++ ) { VEC( x, k ) = VEC( in, 2*k ); VEC( y, k ) = VEC( in, 2*k + 1 ); } fft( x, p, n/2 ); fft( y, q, n/2 ); for( k = 0; k < n; k++ ) { VEC( out, k ) = VEC( p, k % (n/2) ) + cpow(wn,k)*VEC( q, k % (n/2) ); } destroy_vector( x ); destroy_vector( y ); destroy_vector( p ); destroy_vector( q ); } }
static int _equal(CVECTOR *a, CVECTOR *b, bool invert) { if (COMPLEX(a) || COMPLEX(b)) { VECTOR_ensure_complex(a); VECTOR_ensure_complex(b); return gsl_vector_complex_equal(CVEC(a), CVEC(b)); } else return gsl_vector_equal(VEC(a), VEC(b)); }
double vector_dot(struct vector *x, struct vector *y) { // can only dot vectors of equal length assert(x->n == y->n); double sum = 0.; for (int i = 0; i < x->n; i++) { sum += VEC(x, i) * VEC(y, i); } return sum; }
static void setup_test_vectors(struct vector *x, struct vector *y_ref) { for (int i = 0; i < x->n; i++) { VEC(x, i) = i; } int len = y_ref->n; if (x->n < len) { len = x->n; } for (int i = 0; i < len; i++) { VEC(y_ref, i) = i * i; } }
static CVECTOR *_sub(CVECTOR *a, CVECTOR *b, bool invert) { CVECTOR *v = VECTOR_make(a); if (COMPLEX(v) || COMPLEX(b)) { VECTOR_ensure_complex(v); VECTOR_ensure_complex(b); gsl_vector_complex_sub(CVEC(v), CVEC(b)); } else gsl_vector_sub(VEC(v), VEC(b)); return v; }
VEC VEC::Vcross(VEC a) { double aa = v[1]*a.v[2] - v[2]*a.v[1]; double b = v[2]*a.v[0] - v[0]*a.v[2]; double c = v[0]*a.v[1] - v[1]*a.v[0]; return VEC(aa,b,c); }
int main(int argc, char** argv) { int64 nside=4096; double rad_radians=-1; int rad_in_file=0; process_args(argc, argv, &nside, &rad_radians, &rad_in_file); struct healpix* hpix = hpix_new(nside); VEC(int64) pixlist = VEC_NEW(int64); double ra=0, dec=0; while (2 == fscanf(stdin,"%lf %lf", &ra, &dec)) { if (rad_in_file) { if (1 != fscanf(stdin,"%lf", &rad_radians)) { fprintf(stderr,"failed to read radius\n"); exit(EXIT_FAILURE); } rad_radians *= D2R/3600.; } hpix_disc_intersect_radec(hpix, ra, dec, rad_radians, pixlist); printf("%.16g %.16g %lu", ra, dec, VEC_SIZE(pixlist); VEC_FOREACH(pix_ptr, pixlist) { printf(" %ld", *pix_ptr); } printf("\n"); }
static char *_to_string(CVECTOR *_object, bool local) { char *result = NULL; int i; int size = SIZE(THIS); char *str; int len; result = GB.AddChar(result, '['); for (i = 0; i < size; i++) { if (i) result = GB.AddChar(result, local ? ' ' : ','); if (!COMPLEX(THIS)) { GB.NumberToString(local, gsl_vector_get(VEC(THIS), i), NULL, &str, &len); result = GB.AddString(result, str, len); } else { str = COMPLEX_to_string(gsl_vector_complex_get(CVEC(THIS), i), local); result = GB.AddString(result, str, GB.StringLength(str)); GB.FreeString(&str); } } result = GB.AddChar(result, ']'); return result; }
static bool may_use_storent_in_loop_p (struct loop *loop) { bool ret = true; if (loop->inner != NULL) return false; /* If we must issue a mfence insn after using storent, check that there is a suitable place for it at each of the loop exits. */ if (FENCE_FOLLOWING_MOVNT != NULL_TREE) { VEC (edge, heap) *exits = get_loop_exit_edges (loop); unsigned i; edge exit; for (i = 0; VEC_iterate (edge, exits, i, exit); i++) if ((exit->flags & EDGE_ABNORMAL) && exit->dest == EXIT_BLOCK_PTR) ret = false; VEC_free (edge, heap, exits); } return ret; }
static void emit_mfence_after_loop (struct loop *loop) { VEC (edge, heap) *exits = get_loop_exit_edges (loop); edge exit; gimple call; gimple_stmt_iterator bsi; unsigned i; for (i = 0; VEC_iterate (edge, exits, i, exit); i++) { call = gimple_build_call (FENCE_FOLLOWING_MOVNT, 0); if (!single_pred_p (exit->dest) /* If possible, we prefer not to insert the fence on other paths in cfg. */ && !(exit->flags & EDGE_ABNORMAL)) split_loop_exit_edge (exit); bsi = gsi_after_labels (exit->dest); gsi_insert_before (&bsi, call, GSI_NEW_STMT); mark_virtual_ops_for_renaming (call); } VEC_free (edge, heap, exits); update_ssa (TODO_update_ssa_only_virtuals); }
/* * vec_fill_grid_mpi * * Takes a vector and a scalar and fills the vector * to be an evenly spaced grid from 0 ... scale. * Scaling with the rank from MPI. */ void vec_fill_grid_mpi( vector *v, val_type scale, int rank, int size ) { int i; for( i = 0; i < v->n; i++ ) VEC( v, i ) = (double)((rank*size)+i) / (double)v->n; //VEC( v, i ) = ((double)i / (double)v->n) * (double)(rank+1); }
static obj_ptr _vec_length(obj_ptr arg, obj_ptr env) { if (NVECP(arg)) return MKERROR(MKSTRING("Expected a vector in vec-length"), arg); return MKINT(vec_length(&VEC(arg))); }
VEC VEC::Vmult (VEC a) { double x = v[0]* a.v[0]; double y = v[1]* a.v[1]; double z = v[2]* a.v[2]; return VEC (x,y,z); }
static tree vxworks_emutls_var_init (tree var, tree decl, tree tmpl_addr) { VEC(constructor_elt,gc) *v = VEC_alloc (constructor_elt, gc, 3); constructor_elt *elt; tree type = TREE_TYPE (var); tree field = TYPE_FIELDS (type); elt = VEC_quick_push (constructor_elt, v, NULL); elt->index = field; elt->value = fold_convert (TREE_TYPE (field), tmpl_addr); elt = VEC_quick_push (constructor_elt, v, NULL); field = DECL_CHAIN (field); elt->index = field; elt->value = build_int_cst (TREE_TYPE (field), 0); elt = VEC_quick_push (constructor_elt, v, NULL); field = DECL_CHAIN (field); elt->index = field; elt->value = fold_convert (TREE_TYPE (field), DECL_SIZE_UNIT (decl)); return build_constructor (type, v); }
static enum efp_result set_coord_points(struct frag *frag, const double *coord) { if (frag->n_atoms < 3) { efp_log("fragment must contain at least three atoms"); return EFP_RESULT_FATAL; } double ref[9] = { frag->lib->atoms[0].x, frag->lib->atoms[0].y, frag->lib->atoms[0].z, frag->lib->atoms[1].x, frag->lib->atoms[1].y, frag->lib->atoms[1].z, frag->lib->atoms[2].x, frag->lib->atoms[2].y, frag->lib->atoms[2].z }; vec_t p1; mat_t rot1, rot2; efp_points_to_matrix(coord, &rot1); efp_points_to_matrix(ref, &rot2); rot2 = mat_transpose(&rot2); frag->rotmat = mat_mat(&rot1, &rot2); p1 = mat_vec(&frag->rotmat, VEC(frag->lib->atoms[0].x)); /* center of mass */ frag->x = coord[0] - p1.x; frag->y = coord[1] - p1.y; frag->z = coord[2] - p1.z; update_fragment(frag); return EFP_RESULT_SUCCESS; }
static void verify_flow_insensitive_alias_info (void) { tree var; bitmap visited = BITMAP_ALLOC (NULL); referenced_var_iterator rvi; FOR_EACH_REFERENCED_VAR (var, rvi) { size_t j; var_ann_t ann; VEC(tree,gc) *may_aliases; tree alias; ann = var_ann (var); may_aliases = ann->may_aliases; for (j = 0; VEC_iterate (tree, may_aliases, j, alias); j++) { bitmap_set_bit (visited, DECL_UID (alias)); if (!may_be_aliased (alias)) { error ("non-addressable variable inside an alias set"); debug_variable (alias); goto err; } } }
/* Complete on filenames. */ VEC (char_ptr) * filename_completer (struct cmd_list_element *ignore, const char *text, const char *word) { int subsequent_name; VEC (char_ptr) *return_val = NULL; subsequent_name = 0; while (1) { char *p, *q; p = rl_filename_completion_function (text, subsequent_name); if (p == NULL) break; /* We need to set subsequent_name to a non-zero value before the continue line below, because otherwise, if the first file seen by GDB is a backup file whose name ends in a `~', we will loop indefinitely. */ subsequent_name = 1; /* Like emacs, don't complete on old versions. Especially useful in the "source" command. */ if (p[strlen (p) - 1] == '~') { xfree (p); continue; } if (word == text) /* Return exactly p. */ q = p; else if (word > text) { /* Return some portion of p. */ q = xmalloc (strlen (p) + 5); strcpy (q, p + (word - text)); xfree (p); } else { /* Return some of TEXT plus p. */ q = xmalloc (strlen (p) + (text - word) + 5); strncpy (q, word, text - word); q[text - word] = '\0'; strcat (q, p); xfree (p); } VEC_safe_push (char_ptr, return_val, q); } #if 0 /* There is no way to do this just long enough to affect quote inserting without also affecting the next completion. This should be fixed in readline. FIXME. */ /* Ensure that readline does the right thing with respect to inserting quotes. */ rl_completer_word_break_characters = ""; #endif return return_val; }
static bool reachable_at_most_once (basic_block va_arg_bb, basic_block va_start_bb) { VEC (edge, heap) *stack = NULL; edge e; edge_iterator ei; sbitmap visited; bool ret; if (va_arg_bb == va_start_bb) return true; if (! dominated_by_p (CDI_DOMINATORS, va_arg_bb, va_start_bb)) return false; visited = sbitmap_alloc (last_basic_block); sbitmap_zero (visited); ret = true; FOR_EACH_EDGE (e, ei, va_arg_bb->preds) VEC_safe_push (edge, heap, stack, e); while (! VEC_empty (edge, stack)) { basic_block src; e = VEC_pop (edge, stack); src = e->src; if (e->flags & EDGE_COMPLEX) { ret = false; break; } if (src == va_start_bb) continue; /* va_arg_bb can be executed more times than va_start_bb. */ if (src == va_arg_bb) { ret = false; break; } gcc_assert (src != ENTRY_BLOCK_PTR); if (! TEST_BIT (visited, src->index)) { SET_BIT (visited, src->index); FOR_EACH_EDGE (e, ei, src->preds) VEC_safe_push (edge, heap, stack, e); } } VEC_free (edge, heap, stack); sbitmap_free (visited); return ret; }
static obj_ptr _vec_clear(obj_ptr arg, obj_ptr env) { if (NVECP(arg)) return MKERROR(MKSTRING("Expected a vector in vec-clear"), arg); vec_clear(&VEC(arg)); return NIL; }
void simple_sec( Vector *u0, double dx, double M, double loc ) { int i; for( i = 0; i < u0 -> N; i++ ) { VEC(u0, i) = (M*(M+1) )/ pow(cosh(dx*i-loc), 2); } }
void VECTOR_ensure_complex(CVECTOR *_object) { gsl_vector_complex *v; int size = SIZE(THIS); int i; if (COMPLEX(THIS)) return; v = gsl_vector_complex_alloc(size); for (i = 0; i < size; i++) gsl_vector_complex_set(v, i, gsl_complex_rect(gsl_vector_get(VEC(THIS), i), 0)); gsl_vector_free(VEC(THIS)); THIS->vector = v; THIS->complex = TRUE; }
/* * write_vector * * Takes a FILE*, and a vector and writes it */ void write_vector( FILE *fp, vector *v ) { int i; fprintf( fp, "\n" ); for( i = 0; i < v->n; i++ ) fprintf( fp, "%g ", VEC( v, i ) ); fprintf( fp, "\n" ); }
static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi) { gimple asm_or_stmt, call_stmt; tree old_fptr, new_fptr, input, output; #if BUILDING_GCC_VERSION <= 4007 VEC(tree, gc) *inputs = NULL; VEC(tree, gc) *outputs = NULL; #else vec<tree, va_gc> *inputs = NULL; vec<tree, va_gc> *outputs = NULL; #endif call_stmt = gsi_stmt(*gsi); old_fptr = gimple_call_fn(call_stmt); // create temporary fptr variable new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or"); #if BUILDING_GCC_VERSION <= 4007 add_referenced_var(new_fptr); #endif new_fptr = make_ssa_name(new_fptr, NULL); // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr)); input = build_tree_list(NULL_TREE, build_string(2, "0")); input = chainon(NULL_TREE, build_tree_list(input, old_fptr)); output = build_tree_list(NULL_TREE, build_string(3, "=r")); output = chainon(NULL_TREE, build_tree_list(output, new_fptr)); #if BUILDING_GCC_VERSION <= 4007 VEC_safe_push(tree, gc, inputs, input); VEC_safe_push(tree, gc, outputs, output); #else vec_safe_push(inputs, input); vec_safe_push(outputs, output); #endif asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL); SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt; gimple_asm_set_volatile(asm_or_stmt, true); gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT); update_stmt(asm_or_stmt); // replace call stmt fn with the new fptr gimple_call_set_fn(call_stmt, new_fptr); update_stmt(call_stmt); }
static obj_ptr _vec_add(obj_ptr args, obj_ptr env) { obj_ptr arg = CAR(args); if (NVECP(arg)) return MKERROR(MKSTRING("Expected a vector in vec-add"), arg); _vec_add_imp(&VEC(arg), CDR(args), env); return NIL; }