Voice Lab
matrix_allocate
void matrix_allocate(double ***matrix, double **matrix_data_ptr, int vector_width, int *number_vectors_max)
{
int i;
/* allocate space for reading in the vectors */
(*matrix_data_ptr) = malloc((*number_vectors_max) * vector_width * sizeof(double));
if((*matrix_data_ptr) == NULL) {
fprintf(stderr, "Cannot allocate memory for data\n");
exit(1);
}
/* allocate space for pointers to the vectors */
*matrix = malloc((*number_vectors_max) * sizeof(double *));
if(*matrix == NULL) {
fprintf(stderr, "Cannot allocate memory for data\n");
exit(1);
}
/* set pointers to point to array of data */
for(i = 0; i < (*number_vectors_max); i++) {
(*matrix)[i] = (*matrix_data_ptr) + (i * vector_width);
}
}
No comments:
Post a Comment