Changeset b508ba6
- Timestamp:
- Dec 29, 2021, 5:51:45 PM (3 years ago)
- Branches:
- feature/cnn, feature/crepe
- Children:
- f4c5a95
- Parents:
- e181d64
- git-author:
- Paul Brossier <piem@piem.org> (01/01/19 18:38:05)
- git-committer:
- Paul Brossier <piem@piem.org> (12/29/21 17:51:45)
- Location:
- src/ai
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ai/tensor.c
re181d64 rb508ba6 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; -
src/ai/tensor.h
re181d64 rb508ba6 27 27 28 28 typedef struct { 29 uint_t n _dims;30 uint_t dims[8];29 uint_t ndim; 30 uint_t shape[8]; 31 31 smpl_t **data; 32 32 uint_t n_items; … … 34 34 } aubio_tensor_t; 35 35 36 aubio_tensor_t *new_aubio_tensor(uint_t n _dims, uint_t *dims);36 aubio_tensor_t *new_aubio_tensor(uint_t ndim, uint_t *shape); 37 37 38 38 void del_aubio_tensor(aubio_tensor_t *c); … … 48 48 #define AUBIO_ASSERT_EQUAL_SHAPE(t1, t2) { \ 49 49 AUBIO_ASSERT(t1 && t2); \ 50 AUBIO_ASSERT(t1->n _dims == t2->n_dims); \50 AUBIO_ASSERT(t1->ndim == t2->ndim); \ 51 51 uint_t nn; \ 52 for (nn = 0; nn < t1->n _dims; nn++) \53 AUBIO_ASSERT(t1-> dims[nn] == t2->dims[nn]); \52 for (nn = 0; nn < t1->ndim; nn++) \ 53 AUBIO_ASSERT(t1->shape[nn] == t2->shape[nn]); \ 54 54 } 55 55
Note: See TracChangeset
for help on using the changeset viewer.