Changeset 427a48c


Ignore:
Timestamp:
Jan 2, 2019, 10:54:21 PM (5 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/cnn_org, feature/crepe_org
Children:
a85c7f3
Parents:
f5ea4fb
Message:

[tensor] view any tensor as fvec/fmat

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ai/tensor.c

    rf5ea4fb r427a48c  
    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.