/* * bool testWithLength(int length) * * Creates three random vectors with the given length and times the performance of scalar_fma() and * vectorized_fma() with these vectors as input. * * Returns true if the results match. */ bool testWithLength(int length) { printf("Test length: %d\n", length); // Create (and clone) three vectors with the given length struct doubleVector a = random_vector(length); struct doubleVector b = random_vector(length); struct doubleVector c = random_vector(length); struct doubleVector a2 = vector_clone(&a); struct doubleVector b2 = vector_clone(&b); struct doubleVector c2 = vector_clone(&c); // Test scalar performance printf("\tScalar cycle count: %d\n", perfTest(&a, &b, &c, scalar_fma)); // Test vector performance printf("\tVector cycle count: %d\n", perfTest(&a2, &b2, &c2, vector_fma)); // Compare results bool correct = vector_compare(&a, &a2); printf("\t%s\n", correct ? "MATCH" : "NO MATCH"); // Free dynamic resources free(a.data); free(b.data); free(c.data); free(a2.data); free(b2.data); free(c2.data); return correct; }
R_API RVector *r_vector_clone(RVector *vec) { RVector *ret = R_NEW (RVector); if (!ret) { return NULL; } if (!vector_clone (ret, vec)) { free (ret); return NULL; } return ret; }
int main(int argc, char * argv[]) { int n, n_threads = 0; matrix_t * A, * A_orig; vector_t * b, * b_orig, * x, * check_res_mat; double t_start, t_end; get_input_params(argc, argv, &n); initialize_global_state(); /* initialize data */ A_orig = matrix_create_rand(n, n), A = matrix_clone(A_orig), b_orig = vector_create_rand(n), b = vector_clone(b_orig), x = vector_create(n), check_res_mat = vector_create(n); t_start = get_time_in_sec(); perform_gaussian_elimination_on_matrix(A, b); perform_back_substitution(A, x, b); t_end = get_time_in_sec(); /* calculate Ax - b and find it's l2norm to test for correctness */ matrix_mult_vector(A_orig, x, check_res_mat); vector_subtract(check_res_mat, check_res_mat, b_orig); /* c = c - b */ printf("num-procs = %d\n", omp_get_num_procs()); #pragma omp parallel num_threads(num_threads) #pragma omp single n_threads = omp_get_num_threads(); printf("num-threads = %d\n", n_threads); printf("Performed Gaussian Elimination in %.12lfs\n", t_end - t_start); printf("Ax-b l2norm = %.6le\n", vector_l2norm(check_res_mat)); puts("done"); return 0; }
sip_call_group_t * call_group_clone(sip_call_group_t *original) { sip_call_group_t *clone; if (!original) return NULL; if (!(clone = sng_malloc(sizeof(sip_call_group_t)))) { return NULL; } clone->calls = vector_clone(original->calls); return clone; }
void sip_sort_list() { // Cloning the vector automatically sorts it vector_t *clone = vector_clone(calls.list); // FIXME FIXME FIXME // There should be a way to destroy the vector without calling the // vector destroyer for each item... vector_set_destroyer(calls.list, NULL); vector_destroy(calls.list); // The new sorted list calls.list = clone; }
//// rotate /////////////////////////////////////////////////////////////////// // // rotate an img by given pitch, roll, yaw // return error // uint32_t * rotate(float roll, float pitch, float yaw, uint32_t *in_img, uint32_t *out_img) { //// init ///////////////////////////////////////////////////////////////// // float lat, lng, nx, ny, nz, clt, slt, r, pi, tau; uint32_t xx, yy, x, y, z, ilt, iln, h, w; struct vector v, vr, vp, vy, ar, ap, ay, pix; // pi = 4.0*atan(1.0); tau = pi*2; // /////////////////////////////////////////////////////////////////////////// //// size config ////////////////////////////////////////////////////////// // // image height h = 1792; // image width w = 3584; // radius of sphere r = 570.41131604135256; // /////////////////////////////////////////////////////////////////////////// //// angles to single vector ////////////////////////////////////////////// // see vector.c // // roll vector_set(&ar, 1, 0, 0, roll); vector_from_axis_angle(&vr, &ar); // // pitch vector_set(&ap, 0, 1, 0, pitch); vector_from_axis_angle(&vp, &ap); // // yaw // if (yaw > 180) { // yaw -= 360; // } // vector_set(&ay, 0, 0, 1, yaw); vector_from_axis_angle(&vy, &ay); // // combine quaternions into v vector_multiply(&vp, &vy); vector_multiply(&vr, &vp); // vector_clone(&vr, &v); // vector_normalize(&v); // /////////////////////////////////////////////////////////////////////////// //// rotation ///////////////////////////////////////////////////////////// // for (y = 0; y < h; y++) { yy = y * w * 3; // y to sphere latitude lat = (float) y / h * pi; // store the values slt = sin(lat); clt = cos(lat); for (x = 0; x < w; x++) { xx = x * 3; // x to sphere longitude lng = (float) x / w * tau - pi; //// spherical to cartesian /////////////////////////////////////// // nx = r * slt * cos(lng); ny = r * slt * sin(lng); nz = r * clt; // /////////////////////////////////////////////////////////////////// //// rotate /////////////////////////////////////////////////////// // see vector.c // // translate pixel into vector vector_set(&pix, nx, ny, nz, 0); // and rotate the pixel vector_conjugate(&pix, &v); // vector_print(&pix); // /////////////////////////////////////////////////////////////////// //// x,y,z -> lat,lng ///////////////////////////////////////////// lat = (float) acos(pix.z / r) / pi * h; lng = (float) (atan2(pix.y, pix.x) + pi) / tau * w; // // pixel coords must be int ilt = (int) lat; iln = (int) lng; // // wrap latitude if (ilt >= h) { ilt -= h; } // // wrap longitude if (iln >= w) { iln -= w; } // /////////////////////////////////////////////////////////////////// for (z = 0; z < 3; z++) { int pos = ilt * w * 3 + iln * 3 + z; // pos > h * w * 3 + w * 3 + 3 if (pos > 19278339) { printf("ERROR OVERFLOW"); return out_img; } out_img[yy + xx + z] = in_img[pos]; } } } // /////////////////////////////////////////////////////////////////////////// // we did it, we did it return out_img; }