Changeset 5010e61 for src/ai/tensor.c
- Timestamp:
- Jan 1, 2019, 6:38:05 PM (6 years ago)
- Branches:
- feature/cnn_org, feature/crepe_org
- Children:
- 6e4ef27
- Parents:
- d0ef4b7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ai/tensor.c
rd0ef4b7 r5010e61 3 3 #include "tensor.h" 4 4 5 aubio_tensor_t *new_aubio_tensor(uint_t n _dims, uint_t *dims)5 aubio_tensor_t *new_aubio_tensor(uint_t ndim, uint_t *shape) 6 6 { 7 7 aubio_tensor_t *c = AUBIO_NEW(aubio_tensor_t); 8 8 uint_t i; 9 9 10 if ((sint_t)n _dims<= 0) goto failure;11 for (i = 0; i < n _dims; i++) {12 if ((sint_t) dims[i] <= 0) goto failure;10 if ((sint_t)ndim <= 0) goto failure; 11 for (i = 0; i < ndim; i++) { 12 if ((sint_t)shape[i] <= 0) goto failure; 13 13 } 14 14 15 c->n _dims = n_dims;15 c->ndim = ndim; 16 16 c->items_per_row = 1; 17 //c-> dims = AUBIO_ARRAY(uint_t, n_dims);18 c-> dims[0] = dims[0];19 for (i = 1; i < n _dims; i++) {20 c-> dims[i] = dims[i];21 c->items_per_row *= dims[i];17 //c->shape = AUBIO_ARRAY(uint_t, ndim); 18 c->shape[0] = shape[0]; 19 for (i = 1; i < ndim; i++) { 20 c->shape[i] = shape[i]; 21 c->items_per_row *= shape[i]; 22 22 } 23 c->n_items = c->items_per_row * dims[0];24 c->data = AUBIO_ARRAY(smpl_t*, dims[0]);23 c->n_items = c->items_per_row * shape[0]; 24 c->data = AUBIO_ARRAY(smpl_t*, shape[0]); 25 25 c->data[0] = AUBIO_ARRAY(smpl_t, c->n_items); 26 for (i = 1; i < c-> dims[0]; i++) {26 for (i = 1; i < c->shape[0]; i++) { 27 27 c->data[i] = c->data[0] + i * c->items_per_row; 28 28 } … … 44 44 AUBIO_FREE(c->data); 45 45 } 46 //if (c-> dims)47 // AUBIO_FREE(c-> dims);46 //if (c->shape) 47 // AUBIO_FREE(c->shape); 48 48 AUBIO_FREE(c); 49 49 } 50 50 51 51 uint_t aubio_tensor_as_fvec(aubio_tensor_t *c, fvec_t *o) { 52 if (c->n _dims!= 1) return AUBIO_FAIL;53 if (c-> dims[0] <= 0) return AUBIO_FAIL;54 o->length = c-> dims[0];52 if (c->ndim != 1) return AUBIO_FAIL; 53 if (c->shape[0] <= 0) return AUBIO_FAIL; 54 o->length = c->shape[0]; 55 55 o->data = c->data[0]; 56 56 return AUBIO_OK; … … 59 59 uint_t aubio_fvec_as_tensor(fvec_t *o, aubio_tensor_t *c) { 60 60 if (o == NULL) return AUBIO_FAIL; 61 c->n _dims= 1;62 c-> dims[0] = o->length;61 c->ndim = 1; 62 c->shape[0] = o->length; 63 63 c->data = &o->data; 64 64 return AUBIO_OK; … … 66 66 67 67 uint_t aubio_tensor_as_fmat(aubio_tensor_t *c, fmat_t *o) { 68 if (c->n _dims!= 2) return AUBIO_FAIL;69 if (c-> dims[0] <= 0) return AUBIO_FAIL;70 if (c-> dims[1] <= 0) return AUBIO_FAIL;71 o->height = c-> dims[0];72 o->length = c-> dims[1];68 if (c->ndim != 2) return AUBIO_FAIL; 69 if (c->shape[0] <= 0) return AUBIO_FAIL; 70 if (c->shape[1] <= 0) return AUBIO_FAIL; 71 o->height = c->shape[0]; 72 o->length = c->shape[1]; 73 73 o->data = c->data; 74 74 return AUBIO_OK;
Note: See TracChangeset
for help on using the changeset viewer.