source: src/ai/tensor.h @ d3d72b7

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

[tensor] add buffer field, improve documentation

  • Property mode set to 100644
File size: 2.0 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#ifndef AUBIO_TENSOR_H
22#define AUBIO_TENSOR_H
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28/** \file
29
30  Tensor for real-valued data.
31
32*/
33
34#define AUBIO_TENSOR_MAXDIM 10
35
36/** Tensor for real-valued data
37
38  This object holds a tensor of real-valued data, ::smpl_t, with up to
39  AUBIO_TENSOR_MAXDIM dimentsions.
40
41*/
42typedef struct
43{
44  uint_t ndim;     /**< number of dimensions */
45  uint_t shape[AUBIO_TENSOR_MAXDIM]; /**< dimensions array */
46  uint_t size;     /**< total number of elements */
47  smpl_t *buffer;  /**< buffer of values */
48  smpl_t **data;   /**< pointer to rows, or NULL when subtensor */
49} aubio_tensor_t;
50
51aubio_tensor_t *new_aubio_tensor(uint_t ndim, uint_t *shape);
52
53void del_aubio_tensor(aubio_tensor_t *c);
54
55uint_t aubio_tensor_as_fvec(aubio_tensor_t *c, fvec_t *o);
56uint_t aubio_fvec_as_tensor(fvec_t *o, aubio_tensor_t *c);
57
58uint_t aubio_tensor_as_fmat(aubio_tensor_t *c, fmat_t *o);
59uint_t aubio_fmat_as_tensor(fmat_t *o, aubio_tensor_t *c);
60
61smpl_t aubio_tensor_max(aubio_tensor_t *t);
62
63#define AUBIO_ASSERT_EQUAL_SHAPE(t1, t2) { \
64    AUBIO_ASSERT(t1 && t2); \
65    AUBIO_ASSERT(t1->ndim == t2->ndim); \
66    uint_t nn; \
67    for (nn = 0; nn < t1->ndim; nn++) \
68      AUBIO_ASSERT(t1->shape[nn] == t2->shape[nn]); \
69    }
70
71#ifdef __cplusplus
72}
73#endif
74
75#endif /* AUBIO_TENSOR_H */
Note: See TracBrowser for help on using the repository browser.