Changeset 7e0b641


Ignore:
Timestamp:
Jan 2, 2019, 10:56:47 PM (5 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/cnn_org, feature/crepe_org
Children:
dc257cc
Parents:
9bffada
Message:

[tensor] add get_subtensor

Location:
src/ai
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/ai/tensor.c

    r9bffada r7e0b641  
    8181}
    8282
     83uint_t aubio_tensor_get_subtensor(aubio_tensor_t *t, uint_t i,
     84    aubio_tensor_t *st)
     85{
     86  uint_t j;
     87  if (!t || !st) return AUBIO_FAIL;
     88  if (i >= t->shape[0]) {
     89    AUBIO_ERR("tensor: index %d out of range, only %d subtensors\n",
     90        i, t->shape[0]);
     91    return AUBIO_FAIL;
     92  }
     93  if(t->ndim > 1) {
     94    st->ndim = t->ndim - 1;
     95    for (j = 0; j < st->ndim; j++) {
     96      st->shape[j] = t->shape[j + 1];
     97    }
     98    for (j = st->ndim; j < AUBIO_TENSOR_MAXDIM; j++) {
     99      st->shape[j] = 0;
     100    }
     101    st->size = t->size / t->shape[0];
     102  } else {
     103    st->ndim = 1;
     104    st->shape[0] = 1;
     105    st->size = 1;
     106  }
     107  // st was allocated on the stack, row indices are lost
     108  st->data = NULL;
     109  st->buffer = &t->buffer[0] + st->size * i;
     110  return AUBIO_OK;
     111}
     112
    83113smpl_t aubio_tensor_max(aubio_tensor_t *t)
    84114{
  • src/ai/tensor.h

    r9bffada r7e0b641  
    5959uint_t aubio_fmat_as_tensor(fmat_t *o, aubio_tensor_t *c);
    6060
     61uint_t aubio_tensor_get_subtensor(aubio_tensor_t *t, uint_t i,
     62        aubio_tensor_t *st);
     63
    6164smpl_t aubio_tensor_max(aubio_tensor_t *t);
    6265
Note: See TracChangeset for help on using the changeset viewer.