source: src/ai/maxpool1d.c @ 97985d4

feature/cnnfeature/crepe
Last change on this file since 97985d4 was 97985d4, checked in by Paul Brossier <piem@piem.org>, 3 years ago

[maxpool1d] update to new tensor members

  • Property mode set to 100644
File size: 2.5 KB
Line 
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{
60  AUBIO_DBG("maxpool1d: input (%d, %d) ¤ maxpool1d (pool_size = (%d)) ->"
61      " (%d, %d) (no params)\n",
62      input_tensor->shape[0],
63      input_tensor->shape[1],
64      c->pool_size,
65      input_tensor->shape[0] / c->pool_size,
66      input_tensor->shape[1]);
67}
68
69uint_t aubio_maxpool1d_get_output_shape(aubio_maxpool1d_t *c,
70    aubio_tensor_t *input, uint_t *shape)
71{
72  AUBIO_ASSERT(c);
73  AUBIO_ASSERT(shape && sizeof(shape) == 2*sizeof(uint_t));
74  AUBIO_ASSERT(input);
75  shape[0] = input->shape[0] / c->pool_size;
76  shape[1] = input->shape[1];
77
78  aubio_maxpool1d_debug(c, input);
79
80  return AUBIO_OK;
81}
82
83void aubio_maxpool1d_do(aubio_maxpool1d_t *c, aubio_tensor_t *input_tensor,
84    aubio_tensor_t *output_tensor)
85{
86  uint_t i, j, a;
87  AUBIO_ASSERT(c && input_tensor && output_tensor);
88
89  //aubio_maxpool1d_debug(c, input_tensor);
90
91  for (j = 0; j < output_tensor->shape[1]; j++) {
92    for (i = 0; i < output_tensor->shape[0]; i++) {
93      smpl_t m = -FLT_MAX;
94      for (a = 0; a < c->pool_size; a++) {
95        m = MAX(m, input_tensor->data[i * c->pool_size + a][j]);
96      }
97      output_tensor->data[i][j] = m;
98    }
99  }
100}
Note: See TracBrowser for help on using the repository browser.