Initialize matrix, copy data from `data` if it's not NULL. */
| 45 | |
| 46 | /* Initialize matrix, copy data from `data` if it's not NULL. */ |
| 47 | void Matrix_Create(Matrix *self, float const *data, size_t n_samples, |
| 48 | size_t n_features) { |
| 49 | if (self == NULL) { |
| 50 | fprintf(stderr, "Invalid pointer to %s\n", __func__); |
| 51 | exit(-1); |
| 52 | } |
| 53 | |
| 54 | *self = (Matrix)malloc(sizeof(struct _Matrix)); |
| 55 | safe_malloc(*self); |
| 56 | (*self)->data = (float *)malloc(n_samples * n_features * sizeof(float)); |
| 57 | safe_malloc((*self)->data); |
| 58 | (*self)->shape[0] = n_samples; |
| 59 | (*self)->shape[1] = n_features; |
| 60 | |
| 61 | if (data != NULL) { |
| 62 | memcpy((*self)->data, data, |
| 63 | (*self)->shape[0] * (*self)->shape[1] * sizeof(float)); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | /* Generate random matrix. */ |
| 68 | void Matrix_Random(Matrix *self, size_t n_samples, size_t n_features) { |
no outgoing calls
no test coverage detected