int main (int argc, char ** argv) { int mat_count; int **matrices; int *sizes; int *result; if (argc==1) matrices = read_matrices (&sizes, &mat_count); else if (argc==2) { FILE *f; if (NULL==(f=fopen(argv[1],"r"))) { printf("Failed to open file '%s'\n",argv[1]); return 1; } matrices = fread_matrices (f,&sizes,&mat_count); } if (matrices == NULL) { printf("Error while reading matrices...\n"); return 1; } result = naive_product (matrices, sizes, mat_count); print_matrix (result, sizes[0], sizes[mat_count]); return 0; }
int main(int argc, char **argv) { if (argc != 2) { printf("Enter a file to be scanned.\n"); exit(0); } int *A, *B, *C; int m, n, p; read_matrices(&A, &B, &C, &m, &n, &p, *(argv+1)); mult_matrices(A, B, C, m, n, p); printf("\nMatrix A contents:\n"); print_matrices(A, m, n); printf("\nMatrix B contents:\n"); print_matrices(B, n, p); printf("\nMatrix A * B is:\n"); print_matrices(C, m, p); free(A); free(B); free(C); exit(0); }
unsigned read_next_wfa (wfa_t *wfa, bitfile_t *input) /* * Read next WFA frame of the WFA stream 'input'. * WFA header information has to be already present in the 'wfainfo' struct. * (i.e. open_wfa must be called first!) * * No return value. * * Side effects: * wfa->into, wfa->weights, wfa->final_distribution, wfa->states * wfa->x, wfa->y, wfa->level_of_state, wfa->domain_type * mt->type, mt->number are filled with the values of the WFA file. */ { tiling_t tiling; /* tiling information */ unsigned frame_number; /* current frame number */ assert (wfa && input); /* * Frame header information */ { const unsigned rice_k = 8; /* parameter of Rice Code */ wfa->states = read_rice_code (rice_k, input); wfa->frame_type = read_rice_code (rice_k, input); frame_number = read_rice_code (rice_k, input); } if (wfa->wfainfo->release > 1) /* no alignment in version 1 */ { INPUT_BYTE_ALIGN (input); } /* * Read image tiling info */ if (get_bit (input)) /* tiling performed ? */ read_tiling (&tiling, wfa->wfainfo->width, wfa->wfainfo->height, wfa->wfainfo->level, input); else tiling.exponent = 0; INPUT_BYTE_ALIGN (input); read_tree (wfa, &tiling, input); /* * Compute domain pool. * Large images have not been used due to image tiling. */ { unsigned state; for (state = wfa->basis_states; state < wfa->states; state++) if ((!wfa->wfainfo->color || (int) state <= wfa->tree [wfa->tree [wfa->root_state][0]][0]) && (!tiling.exponent || wfa->level_of_state [state] <= (wfa->wfainfo->level - tiling.exponent)) && ((wfa->x [state][0] + width_of_level (wfa->level_of_state [state])) <= wfa->wfainfo->width) && ((wfa->y [state][0] + height_of_level (wfa->level_of_state [state])) <= wfa->wfainfo->height)) wfa->domain_type [state] = USE_DOMAIN_MASK; else wfa->domain_type [state] = 0; } if (tiling.exponent) Free (tiling.vorder); if (get_bit (input)) /* nondeterministic prediction used */ read_nd (wfa, input); if (wfa->frame_type != I_FRAME) /* motion compensation used */ read_mc (wfa->frame_type, wfa, input); locate_delta_images (wfa); /* * Read linear combinations (coefficients and indices) */ { unsigned edges = read_matrices (wfa, input); if (edges) read_weights (edges, wfa, input); } /* * Compute final distribution of all states */ { unsigned state; for (state = wfa->basis_states; state <= wfa->states; state++) wfa->final_distribution[state] = compute_final_distribution (state, wfa); } return frame_number; }