Changeset b508ba6


Ignore:
Timestamp:
Dec 29, 2021, 5:51:45 PM (3 years ago)
Author:
Paul Brossier <piem@piem.org>
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)
Message:

[tensor] rename attributes to ndim and shape[] to match numpy

Location:
src/ai
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/ai/tensor.c

    re181d64 rb508ba6  
    33#include "tensor.h"
    44
    5 aubio_tensor_t *new_aubio_tensor(uint_t n_dims, uint_t *dims)
     5aubio_tensor_t *new_aubio_tensor(uint_t ndim, uint_t *shape)
    66{
    77  aubio_tensor_t *c = AUBIO_NEW(aubio_tensor_t);
    88  uint_t i;
    99
    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;
    1313  }
    1414
    15   c->n_dims = n_dims;
     15  c->ndim = ndim;
    1616  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];
    2222  }
    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]);
    2525  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++) {
    2727    c->data[i] = c->data[0] + i * c->items_per_row;
    2828  }
     
    4444    AUBIO_FREE(c->data);
    4545  }
    46   //if (c->dims)
    47   //  AUBIO_FREE(c->dims);
     46  //if (c->shape)
     47  //  AUBIO_FREE(c->shape);
    4848  AUBIO_FREE(c);
    4949}
    5050
    5151uint_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];
    5555  o->data = c->data[0];
    5656  return AUBIO_OK;
     
    5959uint_t aubio_fvec_as_tensor(fvec_t *o, aubio_tensor_t *c) {
    6060  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;
    6363  c->data = &o->data;
    6464  return AUBIO_OK;
     
    6666
    6767uint_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];
    7373  o->data = c->data;
    7474  return AUBIO_OK;
  • src/ai/tensor.h

    re181d64 rb508ba6  
    2727
    2828typedef struct {
    29   uint_t n_dims;
    30   uint_t dims[8];
     29  uint_t ndim;
     30  uint_t shape[8];
    3131  smpl_t **data;
    3232  uint_t n_items;
     
    3434} aubio_tensor_t;
    3535
    36 aubio_tensor_t *new_aubio_tensor(uint_t n_dims, uint_t *dims);
     36aubio_tensor_t *new_aubio_tensor(uint_t ndim, uint_t *shape);
    3737
    3838void del_aubio_tensor(aubio_tensor_t *c);
     
    4848#define AUBIO_ASSERT_EQUAL_SHAPE(t1, t2) { \
    4949    AUBIO_ASSERT(t1 && t2); \
    50     AUBIO_ASSERT(t1->n_dims == t2->n_dims); \
     50    AUBIO_ASSERT(t1->ndim == t2->ndim); \
    5151    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]); \
    5454    }
    5555
Note: See TracChangeset for help on using the changeset viewer.