source: src/ai/maxpool1d.c @ e75a48e

feature/crepe_org
Last change on this file since e75a48e was 8691154, checked in by Paul Brossier <piem@piem.org>, 6 years ago

[maxpool1d] improve debug string

  • Property mode set to 100644
File size: 2.5 KB
RevLine 
[ba0c332]1/*
2  Copyright (C) 2018 Paul Brossier <piem@aubio.org>
3
4  This file is part of aubio.
5
6  aubio is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10
11  aubio is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15
16  You should have received a copy of the GNU General Public License
17  along with aubio.  If not, see <http://www.gnu.org/licenses/>.
18
19*/
20
21#include "aubio_priv.h"
22#include "fmat.h"
23#include "tensor.h"
24#include "maxpool1d.h"
25
26#include <float.h> // FLT_MAX
27
28struct _aubio_maxpool1d_t {
29  uint_t pool_size;
30  uint_t stride;
31};
32
33static void aubio_maxpool1d_debug(aubio_maxpool1d_t *c,
34    aubio_tensor_t *input_tensor);
35
36aubio_maxpool1d_t *new_aubio_maxpool1d(uint_t pool_size[1])
37{
38  aubio_maxpool1d_t *c = AUBIO_NEW(aubio_maxpool1d_t);
39
40  AUBIO_GOTO_FAILURE((sint_t)pool_size[0] > 0);
41
42  c->pool_size = pool_size[0];
43
44  c->stride = 1;
45
46  return c;
47
48failure:
49  del_aubio_maxpool1d(c);
50  return NULL;
51}
52
53void del_aubio_maxpool1d(aubio_maxpool1d_t* c) {
54  AUBIO_ASSERT(c);
55  AUBIO_FREE(c);
56}
57
58void aubio_maxpool1d_debug(aubio_maxpool1d_t *c, aubio_tensor_t *input_tensor)
59{
[8691154]60  AUBIO_DBG("maxpool1d: %15s -> (%d, %d) (no params)"
61      " (pool_size=(%d,), )\n", aubio_tensor_get_shape_string(input_tensor),
[60c9db0]62      input_tensor->shape[0] / c->pool_size,
[8691154]63      input_tensor->shape[1], c->pool_size);
[ba0c332]64}
65
66uint_t aubio_maxpool1d_get_output_shape(aubio_maxpool1d_t *c,
67    aubio_tensor_t *input, uint_t *shape)
68{
69  AUBIO_ASSERT(c);
70  AUBIO_ASSERT(shape && sizeof(shape) == 2*sizeof(uint_t));
71  AUBIO_ASSERT(input);
[60c9db0]72  shape[0] = input->shape[0] / c->pool_size;
73  shape[1] = input->shape[1];
[ba0c332]74
75  aubio_maxpool1d_debug(c, input);
76
77  return AUBIO_OK;
78}
79
80void aubio_maxpool1d_do(aubio_maxpool1d_t *c, aubio_tensor_t *input_tensor,
81    aubio_tensor_t *output_tensor)
82{
83  uint_t i, j, a;
84  AUBIO_ASSERT(c && input_tensor && output_tensor);
85
[60c9db0]86  //aubio_maxpool1d_debug(c, input_tensor);
87
88  for (j = 0; j < output_tensor->shape[1]; j++) {
89    for (i = 0; i < output_tensor->shape[0]; i++) {
[f9f03ff]90      uint_t stride_i = i * c->pool_size;
91      smpl_t m = input_tensor->data[stride_i][j];
[ba0c332]92      for (a = 0; a < c->pool_size; a++) {
[f9f03ff]93        m = MAX(m, input_tensor->data[stride_i + a][j]);
[ba0c332]94      }
95      output_tensor->data[i][j] = m;
96    }
97  }
98}
Note: See TracBrowser for help on using the repository browser.