t_matrix *set_translate(double dx, double dy, double dz) { t_matrix *t; t = matrix_init(4, 4); t->m[0] = 1; t->m[3] = dx; t->m[5] = 1; t->m[7] = dy; t->m[10] = 1; t->m[11] = dz; t->m[15] = 1; return (t); }
int main (int argc, char **argv) { struct matrix A; struct matrix B; gmp_randstate_ptr rands; mpz_t bs; int i; tests_start (); rands = RANDS; matrix_init (&A, MAX_SIZE); matrix_init (&B, MAX_SIZE); mpz_init (bs); for (i = 0; i < 17; i++) { mp_size_t an, bn; mpz_urandomb (bs, rands, 32); an = 1 + mpz_get_ui (bs) % MAX_SIZE; mpz_urandomb (bs, rands, 32); bn = 1 + mpz_get_ui (bs) % MAX_SIZE; matrix_random (&A, an, rands); matrix_random (&B, bn, rands); one_test (&A, &B, i); } mpz_clear (bs); matrix_clear (&A); matrix_clear (&B); return 0; }
void uni_size_estimator_init(struct uniform_size_estimator *estim) { assert(estim != NULL); /* This info is used at post-processing time */ printf("size-estimator: M=%d, D=%d\n", UNIFORM_SIZE_ESTIMATOR_M, UNIFORM_SIZE_ESTIMATOR_D); estim->epoch = 0; matrix_init(&estim->consensus_mat, __consensus_mat_storage, UNIFORM_SIZE_ESTIMATOR_M, UNIFORM_SIZE_ESTIMATOR_D); _enable(estim); }
int main(int argc, char **argv) { /* create a simple definite positive symetric matrix example * * Hilbert matrix : h(i,j) = 1/(i+j+1) * */ float ***bmat; int rank, nodes, ret; double timing, flops; int correctness; ret = starpu_init(NULL); STARPU_CHECK_RETURN_VALUE(ret, "starpu_init"); ret = starpu_mpi_init(&argc, &argv, 1); STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init"); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &nodes); starpu_cublas_init(); parse_args(argc, argv, nodes); matrix_init(&bmat, rank, nodes, 1); matrix_display(bmat, rank); dw_cholesky(bmat, size/nblocks, rank, nodes, &timing, &flops); starpu_mpi_shutdown(); matrix_display(bmat, rank); dw_cholesky_check_computation(bmat, rank, nodes, &correctness, &flops); matrix_free(&bmat, rank, nodes, 1); starpu_cublas_shutdown(); starpu_shutdown(); assert(correctness); if (rank == 0) { FPRINTF(stdout, "Computation time (in ms): %2.2f\n", timing/1000); FPRINTF(stdout, "Synthetic GFlops : %2.2f\n", (flops/timing/1000.0f)); } return 0; }
void keyboard_init(void) { timer_init(); matrix_init(); #ifdef PS2_MOUSE_ENABLE ps2_mouse_init(); #endif #ifdef BOOTMAGIC_ENABLE bootmagic(); #endif #ifdef BACKLIGHT_ENABLE backlight_init(); #endif }
int main(int argc, char *argv[]) { // Catch signals signal(SIGINT, mh_sigint); signal(SIGTERM, mh_sigint); // Initialise LEDs if (matrix_init() < 0) return 1; // Set up OSC server const char *path; lo_server_thread st; int chmod_err = 0; if (argc > 1) { path = argv[1]; } else { path = SOCKET_PATH; } unlink(path); st = lo_server_thread_new(path, mh_osc_error); chmod_err = chmod_socket(path); if (chmod_err != 0) { fprintf(stderr, "Error changing socket permissions\n"); return 1; } // Set up OSC message handlers lo_server_thread_add_method(st, "/set", "iii", mh_osc_set, NULL); lo_server_thread_add_method(st, "/render", NULL, mh_osc_render, NULL); lo_server_thread_add_method(st, "/clear", NULL, mh_osc_clear, NULL); lo_server_thread_start(st); // Ready printf("Listening on socket: %s\n", path); while (1) { usleep(1000); } // Cleanup lo_server_thread_free(st); mh_cleanup(); return 0; }
int main(void) { // Vars struct fp_dev *device; struct fp_driver *driver; struct fp_print_data *print_data; struct fp_img *img; int err; // Init the LCD lcdinit(0x00, 0x12, 0x20); lcd_reset(); // Init libfprint fp_init(); // Init the keypad matrix_init(4, 17, 27, 22, 10, 9, 11, handle_key_press); // Signal handler - does an fp_exit() on SIGINT init_signals(); // Get the first fingerprint device if ((err = get_fingerprint_device(&device)) < 0 || !device) { // Errorz if (err == -1) { error("No devices found"); } else if (err == -2) { error("Couldn't open the device"); } return 1; } // Get driver driver = fp_dev_get_driver(device); // Init message printf("Programme started! Device is %s\n\n", fp_driver_get_full_name(driver)); // Scan the print fp_enroll_finger_img(device, &print_data, &img); // Deinit libfprint fp_exit(); return 0; }
void hw_init(void) { /* Disable watchdog */ at91_disable_wdt(); /* * while coming from the ROM code, we run on PLLA @ 396 MHz / 132 MHz * so we need to slow down and configure MCKR accordingly. * This is why we have a special flavor of the switching function. */ /* Switch PCK/MCK on Main Clock output */ pmc_cfg_mck_down(BOARD_PRESCALER_MAIN_CLOCK); /* Configure PLLA */ pmc_cfg_plla(PLLA_SETTINGS); /* Initialize PLLA charge pump */ /* No need: we keep what is set in ROM code */ //pmc_init_pll(0x3); /* Switch MCK on PLLA output */ pmc_cfg_mck(BOARD_PRESCALER_PLLA); /* Enable External Reset */ writel(AT91C_RSTC_KEY_UNLOCK | AT91C_RSTC_URSTEN, AT91C_BASE_RSTC + RSTC_RMR); #if defined(CONFIG_MATRIX) /* Initialize the matrix */ matrix_init(); #endif /* initialize the dbgu */ initialize_dbgu(); /* Init timer */ timer_init(); #if defined(CONFIG_DDR3) /* Initialize MPDDR Controller */ ddramc_init(); #elif defined(CONFIG_LPDDR1) lpddr1_init(); #endif /* Prepare L2 cache setup */ l2cache_prepare(); }
void test_question_one(){ int m = 8; int n = 8; int lda = 8; double * A = matrix_alloc(m,n); matrix_init(A,m,n); printf("Affiche A\n"); affiche(m,n,A,lda,stdout); printf("Affiche B\n"); affiche(m/2,n/2,A+3,lda,stdout); matrix_free(A); }
void matrix_mult(int m_size) { double A[m_size][m_size]; double B[m_size][m_size]; double C[m_size][m_size]; int i, j, k; matrix_init(A, B); for (i = 0; i < m_size; i++) { int i_m = m_size - i; for (j = 0; j < m_size; j++) { double sum = A[i_m][j] * B[j][i]; for (k = 0; k < m_size; k++) sum += A[i_m][k]*B[k][j]; C[i][j] = sum; } } }
void game_update(void) { int ch = wgetch(main_window); while (ch != ERR) { switch (ch) { case 'q': running = false; break; case 'h': wmove(main_window, getcury(main_window), getcurx(main_window)-2); break; case 'j': wmove(main_window, getcury(main_window)+1, getcurx(main_window)); break; case 'k': wmove(main_window, getcury(main_window)-1, getcurx(main_window)); break; case 'l': wmove(main_window, getcury(main_window), getcurx(main_window)+2); break; case 'c': matrix_change(); break; case 'C': matrix_init(); break; case 'i': if (game_delay - DELAY_STEP > DELAY_MIN) game_delay -= DELAY_STEP; panel_draw(); break; case 'd': if (game_delay + DELAY_STEP < DELAY_MAX) game_delay += DELAY_STEP; panel_draw(); break; case 'p': stat = !stat; break; } ch = wgetch(main_window); } }
//Subtracts the second from the first argument, storing result. //Returns: result, or null pointer if dimensions don't add up. matrix* matrix_sub(matrix* m1, matrix* m2) { //check dimensionality if (m1->rows != m2->rows || m1->cols != m2->cols) return NULL; //initialize output matrix *res = malloc(sizeof(matrix)); matrix_init(res, m1->rows, m1->cols); //perform subtraction for (uint32_t r = 1; r <= m1->rows; r++) { for (uint32_t c = 1; c <= m1->cols; c++) { *matrix_elem(res, r, c) = (*matrix_elem(m1, r, c)) - (*matrix_elem(m2, r, c)); } } return res; }
bool matrix_copy(matrix* from, matrix* to) { //Only include this branch if we decide it is acceptable for 'to' to be uninitiated on function call. //I don't see any reason that this should not be the case. if (to->size == 0 || to->size != to->rows * to->cols) { matrix_init(to, from->rows, from->cols); } //from->cols; if (from->cols != to->cols || from->rows != to->rows) { printf("dimension mismatch! (%d, %d) vs. (%d, %d)\n", from->rows, from->cols, to->rows, to->cols); return false; } for (uint32_t r = 0; r < from->rows; r++) { for (uint32_t c = 0; c < from->cols; c++) { to->data[r][c] = from->data[r][c]; } } return true; }
int main(void) { setup_hardware(); setup_set_handedness(); sei(); /* wait for USB startup to get ready for debug output */ uint8_t timeout = 200; // timeout when USB is not available while (timeout-- && USB_DeviceState != DEVICE_STATE_Configured) { wait_ms(5); #if defined(INTERRUPT_CONTROL_ENDPOINT) ; #else USB_USBTask(); #endif } /* if (USB_DeviceState != DEVICE_STATE_Configured) { */ if (!has_usb()) { // USB failed to connect, so run this device in slave mode. matrix_init(); serial_slave_init(); while (1) { matrix_slave_scan(); } } /* init modules */ keyboard_init(); host_set_driver(&lufa_driver); #ifdef SLEEP_LED_ENABLE sleep_led_init(); #endif while (1) { keyboard_task(); #if !defined(INTERRUPT_CONTROL_ENDPOINT) USB_USBTask(); #endif } }
enum plugin_status plugin_start(const void* parameter) { int button; int sleep = SLEEP; bool frozen = false; (void)parameter; rb->lcd_set_background(LCD_BLACK); rb->lcd_set_backdrop(NULL); rb->lcd_clear_display(); matrix_init(); while (1) { if (!frozen) { matrix_loop(); rb->lcd_update(); rb->sleep(sleep); } button = rb->button_get(frozen); switch(button) { case MATRIX_PAUSE: frozen = !frozen; break; case MATRIX_EXIT: return PLUGIN_OK; break; case MATRIX_SLEEP_MORE: /* Sleep longer */ sleep += SLEEP; break; case MATRIX_SLEEP_LESS: /* Sleep less */ sleep -= SLEEP; if (sleep < 0) sleep = 0; break; default: if (rb->default_event_handler(button) == SYS_USB_CONNECTED) { return PLUGIN_USB_CONNECTED; } break; } } return PLUGIN_OK; }
void keyboard_init(void) { timer_init(); matrix_init(); #ifdef LED_MATRIX_ENABLE led_matrix_init(); #endif #ifdef PS2_MOUSE_ENABLE if (ps2_enabled()) { ps2_mouse_init(); } #endif #ifdef BOOTMAGIC_ENABLE bootmagic(); #endif #ifdef LEDMAP_ENABLE #ifdef LEDMAP_IN_EEPROM_ENABLE ledmap_in_eeprom_init(); #endif ledmap_init(); #endif #ifdef SOFTPWM_LED_ENABLE softpwm_init(); #endif #ifdef BREATHING_LED_ENABLE breathing_led_init(); #endif #ifdef BACKLIGHT_ENABLE backlight_init(); #endif #ifdef KEYMAP_IN_EEPROM_ENABLE keymap_in_eeprom_init(); #endif }
t_matrix *matrix_sub(t_matrix *a, t_matrix *b) { t_matrix *c; int i; int size; if (!a || !b) return (NULL); if (a->x != b->x || a->y != b->y) return (NULL); c = matrix_init(a->x, a->y); size = c->x * c->y; i = 0; while (i < size) { c->m[i] = a->m[i] - b->m[i]; i++; } return (c); }
void check_matrix_mul_dotp(testresult_t *result, void (*start)(), void (*stop)()) { int N = SIZE; int M = SIZE; signed short matA[N*M]; signed short matB[N*M]; signed int matC[N*M]; matrix_init(matA, matB, matC); // start benchmark start(); matMul16_t_dot(matA, matB, matC, N, M); stop(); result->errors = matrix_check(matC); }
int main() { int code; char input[1024]; Tcl_Interp *interp; interp = Tcl_CreateInterp(); /* Initialize the wrappers */ if (matrix_init(interp) == TCL_ERROR) exit(0); fprintf(stdout,"matrix > "); while(fgets(input, 1024, stdin) != NULL) { code = Tcl_Eval(interp, input); fprintf(stdout,"%s\n",interp->result); fprintf(stdout,"matrix > "); } }
/** \brief keyboard_init * * FIXME: needs doc */ void keyboard_init(void) { timer_init(); // To use PORTF disable JTAG with writing JTD bit twice within four cycles. #if (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega32U4__)) MCUCR |= _BV(JTD); MCUCR |= _BV(JTD); #endif matrix_init(); #ifdef PS2_MOUSE_ENABLE ps2_mouse_init(); #endif #ifdef SERIAL_MOUSE_ENABLE serial_mouse_init(); #endif #ifdef ADB_MOUSE_ENABLE adb_mouse_init(); #endif #ifdef BOOTMAGIC_ENABLE bootmagic(); #else magic(); #endif #ifdef BACKLIGHT_ENABLE backlight_init(); #endif #ifdef RGBLIGHT_ENABLE rgblight_init(); #endif #ifdef STENO_ENABLE steno_init(); #endif #ifdef FAUXCLICKY_ENABLE fauxclicky_init(); #endif #ifdef POINTING_DEVICE_ENABLE pointing_device_init(); #endif #if defined(NKRO_ENABLE) && defined(FORCE_NKRO) keymap_config.nkro = 1; #endif }
int main(void) { // init max7219 spi communication matrix_init(); // define variable that will hold temperature digit and decimal part int8_t digit = 0; uint16_t decimal = 0; while(1) { therm_read_temperature(&digit, &decimal); // calculate digits char digit3 = digit/100; char kalan = digit%100; char digit2 = kalan/10; char digit1 = kalan%10; // calculate digits of the decimal part char decimal4 = decimal/1000; kalan = decimal%1000; char decimal3 = kalan/100; kalan = decimal%100; char decimal2 = kalan/10; char decimal1 = kalan%10; // print values to 7 segment display matrix_transmit(1, digit_map[digit2]); matrix_transmit(2, (digit_map[digit1]) | 0b10000000); // Light up the "dot" in the digit //matrix_transmit(4, digit_map[decimal4]); //matrix_transmit(5, digit_map[decimal3]); //matrix_transmit(6, digit_map[decimal2]); //matrix_transmit(7, digit_map[decimal1]); //_delay_ms(1000); } return 0; }
int filter2d_init_default(filter2d_t* q, int ntime, int nfreq, int sztime, int szfreq) { int i, j; int ret = -1; float **taps; if (matrix_init((void***) &taps, ntime, nfreq, sizeof(float))) { goto free_and_exit; } /* Compute the default 2-D interpolation mesh */ for (i = 0; i < ntime; i++) { for (j = 0; j < nfreq; j++) { if (j < nfreq / 2) taps[i][j] = (j + 1.0) / (2.0 * intceil(nfreq, 2)); else if (j == nfreq / 2) taps[i][j] = 0.5; else if (j > nfreq / 2) taps[i][j] = (nfreq - j) / (2.0 * intceil(nfreq, 2)); } } INFO("Using default interpolation matrix of size %dx%d\n", ntime, nfreq); if (verbose >= VERBOSE_DEBUG) { matrix_fprintf_f(stdout, taps, ntime, nfreq); } if (filter2d_init(q, taps, ntime, nfreq, sztime, szfreq)) { goto free_and_exit; } ret = 0; free_and_exit: matrix_free((void**) taps, ntime); return ret; }
int iniciarPartida(struct Partida partida) { int result; printf("Se inicia la partida entre %s y %s.\n", partida.jugadorOrigen.nombre, partida.jugadorDestino.nombre); // Inicializo la matriz grafica matrix_init(); // Cargo las posiciones ingresadas por el jugador for (i = 0; i < cantidad_barcos; i++) { my_matrix[posiciones_barcos[i][0] - VALUE][posiciones_barcos[i][1] - VALUE] = 'b'; } // Voy a separar la ejecucion en 2 threads, uno va a leer lo que ingresa el usuario // por consola y otro va a estar escuchando por mensajes que le lleguen desde el server result = pthread_create(&t1, NULL, leerJugada, NULL ); if (result != 0) { perror("Error en la creacion del thread\n"); return EXIT_FAILURE; } result = pthread_create(&t2, NULL, escucharServidor, NULL ); if (result != 0) { perror("Error en la creacion del thread\n"); return EXIT_FAILURE; } // bloqueo hasta que ambos threads terminen pthread_join(t2, NULL ); pthread_join(t1, NULL ); // Termino la partida return 0; }
int main(int argc, char **argv) { int fd; t_coord *coord; t_param *param; if (argc != 2) { ft_putstr("fdf error ! You must give only one argument.\n"); exit(2); } fd = open(argv[1], O_RDONLY); error_handler(fd); coord = (t_coord*)malloc(sizeof(t_coord)); param = (t_param*)malloc(sizeof(t_param)); param->matrix = matrix_init(fd, param); init_draw(param, coord); mlx_expose_hook(param->win, expose_function, param); mlx_key_hook(param->win, key_function, param); free(coord); mlx_loop(param->mlx); return (0); }
void Shape::Render(const char *path){ if(geom_ == NULL) return; cairo_surface_t *surface = cairo_ps_surface_create(path, width_, height_); if(cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) { std::cout << cairo_status_to_string(cairo_surface_status(surface)) << std::endl; exit(1); return; } ctx_ = cairo_create(surface); OGREnvelope env; geom_->getEnvelope(&env); cairo_matrix_t mat; matrix_init(&mat, width_, height_, &env); cairo_set_matrix(ctx_, &mat); Dispatch(geom_); cairo_show_page(ctx_); cairo_destroy(ctx_); cairo_surface_destroy(surface); }
void board_init_f(ulong dummy) { int ret; switch_to_main_crystal_osc(); #ifdef CONFIG_SAMA5D2 configure_2nd_sram_as_l2_cache(); #endif /* disable watchdog */ at91_disable_wdt(); /* PMC configuration */ at91_pmc_init(); at91_clock_init(CONFIG_SYS_AT91_MAIN_CLOCK); matrix_init(); redirect_int_from_saic_to_aic(); timer_init(); board_early_init_f(); mem_init(); ret = spl_init(); if (ret) { debug("spl_init() failed: %d\n", ret); hang(); } preloader_console_init(); }
int main() { /* AbelianGroup x; AbelianGroup y; abelian_init(&x, 2, 0); *(x.orders)=1; *(x.orders+1)=1; abelian_init(&y, 1, 0); *(y.orders)=2; Matrix *f = matrix_init(1,2); int val[2] = {2,2}; fill_matrix(val, f); Matrix *g = matrix_init(2,1); int val_g[2] = {1,1}; fill_matrix(val_g, g); test_kernel(2, f, x, y, g);*/ AbelianGroup x; AbelianGroup y; abelian_init(&x, 0, 2); abelian_init(&y, 0, 2); Matrix *f = matrix_init(2, 2); int val[4] = { 0, 1, 0, 0 }; fill_matrix(val, f); test_epi_mono(2, f, x, y); abelian_clear(&x); abelian_clear(&y); return 0; }
void s_init(void) { switch_to_main_crystal_osc(); /* disable watchdog */ at91_disable_wdt(); /* PMC configuration */ at91_pmc_init(); at91_clock_init(CONFIG_SYS_AT91_MAIN_CLOCK); matrix_init(); redirect_int_from_saic_to_aic(); timer_init(); board_early_init_f(); preloader_console_init(); mem_init(); }
void master(char *a_fname, char *b_fname, char *out_fname) { Matrix a = matrix_read(a_fname); Matrix b = matrix_read(b_fname); if (a.width != a.height || b.width != b.height || a.width != b.width) { printf("Invalid inputs. Both matricies must be nxn. A was %dx%d. B was" " %dx%d", a.height, a.width, b.height, b.width); MPI_Abort(MPI_COMM_WORLD, -1); } MPI_Bcast(&(a.width), 1, MPI_INT, 0, MPI_COMM_WORLD); Matrix result = matrix_malloc(a.width, b.width); matrix_init(&result); MPI_matrix_multiply(&result, &a, &b, a.width, 0, MPI_COMM_WORLD); matrix_write(out_fname, result); if (result.width <= 20) matrix_print(result); free(result.data); free(a.data); free(b.data); }
void keyboard_init(void) { timer_init(); matrix_init(); #ifdef PS2_MOUSE_ENABLE ps2_mouse_init(); #endif #ifdef SERIAL_MOUSE_ENABLE serial_mouse_init(); #endif #ifdef ADB_MOUSE_ENABLE adb_mouse_init(); #endif #ifdef BOOTMAGIC_ENABLE bootmagic(); #else magic(); #endif #ifdef BACKLIGHT_ENABLE backlight_init(); #endif #ifdef RGBLIGHT_ENABLE rgblight_init(); #endif #ifdef STENO_ENABLE steno_init(); #endif #ifdef FAUXCLICKY_ENABLE fauxclicky_init(); #endif #ifdef POINTING_DEVICE_ENABLE pointing_device_init(); #endif #if defined(NKRO_ENABLE) && defined(FORCE_NKRO) keymap_config.nkro = 1; #endif }