Changeset b496aa8


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

[tensor] add get_subtensor

Location:
src/ai
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/ai/tensor.c

    ra5986ff rb496aa8  
    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

    ra5986ff rb496aa8  
    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.