Changeset 0d9ef90 for src/ai


Ignore:
Timestamp:
Dec 29, 2021, 5:51:46 PM (3 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/cnn, feature/crepe
Children:
533187f
Parents:
2859f89
git-author:
Paul Brossier <piem@piem.org> (01/02/19 22:54:21)
git-committer:
Paul Brossier <piem@piem.org> (12/29/21 17:51:46)
Message:

[tensor] view any tensor as fvec/fmat

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ai/tensor.c

    r2859f89 r0d9ef90  
    4646
    4747uint_t aubio_tensor_as_fvec(aubio_tensor_t *c, fvec_t *o) {
    48   if (c->ndim  != 1) return AUBIO_FAIL;
    49   if (c->shape[0] <= 0) return AUBIO_FAIL;
    50   o->length = c->shape[0];
     48  if (!c || !o) return AUBIO_FAIL;
     49  o->length = c->size;
    5150  o->data = c->data[0];
    5251  return AUBIO_OK;
     
    5453
    5554uint_t aubio_fvec_as_tensor(fvec_t *o, aubio_tensor_t *c) {
    56   if (o == NULL) return AUBIO_FAIL;
     55  if (!o || !c) return AUBIO_FAIL;
    5756  c->ndim = 1;
    5857  c->shape[0] = o->length;
    5958  c->data = &o->data;
     59  c->buffer = o->data;
    6060  c->size = o->length;
    6161  return AUBIO_OK;
     
    6363
    6464uint_t aubio_tensor_as_fmat(aubio_tensor_t *c, fmat_t *o) {
    65   if (c->ndim  != 2) return AUBIO_FAIL;
    66   if (c->shape[0] <= 0) return AUBIO_FAIL;
    67   if (c->shape[1] <= 0) return AUBIO_FAIL;
     65  if (!c || !o) return AUBIO_FAIL;
    6866  o->height = c->shape[0];
    69   o->length = c->shape[1];
     67  o->length = c->size / c->shape[0];
    7068  o->data = c->data;
    7169  return AUBIO_OK;
     
    7371
    7472uint_t aubio_fmat_as_tensor(fmat_t *o, aubio_tensor_t *c) {
    75   if (o == NULL) return AUBIO_FAIL;
    76   if (c == NULL) return AUBIO_FAIL;
     73  if (!o || !c) return AUBIO_FAIL;
    7774  c->ndim = 2;
    7875  c->shape[0] = o->height;
     
    8077  c->size = o->height * o->length;
    8178  c->data = o->data;
     79  c->buffer = o->data[0];
    8280  return AUBIO_OK;
    8381}
Note: See TracChangeset for help on using the changeset viewer.