Changeset 6006760


Ignore:
Timestamp:
Jan 7, 2019, 11:26:09 PM (5 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/cnn_org, feature/crepe_org
Children:
791b436
Parents:
147afba
Message:

[tensor] add matmul

Location:
src/ai
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/ai/tensor.c

    r147afba r6006760  
    204204  AUBIO_MSG("\n");
    205205}
     206
     207void aubio_tensor_matmul(aubio_tensor_t *a, aubio_tensor_t *b,
     208    aubio_tensor_t *c)
     209{
     210  AUBIO_ASSERT (a->shape[0] == c->shape[0]);
     211  AUBIO_ASSERT (a->shape[1] == b->shape[0]);
     212  AUBIO_ASSERT (b->shape[1] == c->shape[1]);
     213#if !defined(HAVE_BLAS)
     214  uint_t i, j, k;
     215  for (i = 0; i < c->shape[0]; i++) {
     216    for (j = 0; j < c->shape[1]; j++) {
     217      smpl_t sum = 0.;
     218      for (k = 0; k < a->shape[1]; k++) {
     219          sum += a->buffer[i * a->shape[1] + k]
     220            * b->buffer[k * b->shape[1] + j];
     221      }
     222      c->buffer[i * c->shape[1] + j] = sum;
     223    }
     224  }
     225#else
     226  cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, a->shape[0],
     227      b->shape[1], b->shape[0], 1.F, a->buffer, a->shape[1], b->buffer,
     228      b->shape[1], 0.F, c->buffer, b->shape[1]);
     229#endif
     230}
  • src/ai/tensor.h

    r147afba r6006760  
    149149const char_t *aubio_tensor_get_shape_string(aubio_tensor_t *t);
    150150
     151void aubio_tensor_matmul(aubio_tensor_t *a, aubio_tensor_t *b,
     152    aubio_tensor_t *c);
     153
    151154#ifdef __cplusplus
    152155}
Note: See TracChangeset for help on using the changeset viewer.