MCPcopy Create free account
hub / github.com/dmlc/xgboost / Matrix_Create

Function Matrix_Create

demo/c-api/inference/inference.c:47–65  ·  view source on GitHub ↗

Initialize matrix, copy data from `data` if it's not NULL. */

Source from the content-addressed store, hash-verified

45
46/* Initialize matrix, copy data from `data` if it's not NULL. */
47void 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. */
68void Matrix_Random(Matrix *self, size_t n_samples, size_t n_features) {

Callers 2

Matrix_RandomFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected