Changeset 49e7171 for src


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

[tensor] add print helpers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ai/tensor.c

    rf90051d r49e7171  
    22#include "fmat.h"
    33#include "tensor.h"
     4
     5#define STRN_LENGTH 40
     6#if !HAVE_AUBIO_DOUBLE
     7#define AUBIO_SMPL_TFMT "% 9.4f"
     8#else
     9#define AUBIO_SMPL_TFMT "% 9.4lf"
     10#endif /* HAVE_AUBIO_DOUBLE */
    411
    512aubio_tensor_t *new_aubio_tensor(uint_t ndim, uint_t *shape)
     
    151158  return shape_str;
    152159}
     160
     161static void aubio_tensor_print_subtensor(aubio_tensor_t *t, uint_t depth)
     162{
     163  uint_t i;
     164  AUBIO_MSG("[");
     165  for (i = 0; i < t->shape[0]; i ++) {
     166    AUBIO_MSG("%*s", i == 0 ? 0 : depth + 1, i == 0 ? "" : " ");
     167    if (t->ndim == 1) {
     168      AUBIO_MSG(AUBIO_SMPL_TFMT, t->buffer[i]);
     169    } else {
     170      aubio_tensor_t st;
     171      aubio_tensor_get_subtensor(t, i, &st);
     172      aubio_tensor_print_subtensor(&st, depth + 1); // recursive call
     173    }
     174    AUBIO_MSG("%s%s", (i < t->shape[0] - 1) ? "," : "",
     175        t->ndim == 1 ? " " : ((i < t->shape[0] - 1) ? "\n" : ""));
     176  }
     177  AUBIO_MSG("]");
     178}
     179
     180void aubio_tensor_print(aubio_tensor_t *t)
     181{
     182  AUBIO_MSG("tensor of shape %s\n", aubio_tensor_get_shape_string(t));
     183  aubio_tensor_print_subtensor(t, 0);
     184  AUBIO_MSG("\n");
     185}
Note: See TracChangeset for help on using the changeset viewer.