source: src/ai/tensor.h @ 3ff9654

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

[tensor] add copy

  • Property mode set to 100644
File size: 4.1 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/** \file
25
26  Tensor for real-valued data.
27
28*/
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34/** Maximum number of dimensions
35
36  This is defined as a constant so that ::aubio_tensor_t allocated
37  on the stack can be manipulated.
38
39 */
40#define AUBIO_TENSOR_MAXDIM 10
41
42/** Tensor for real-valued data
43
44  This object holds a tensor of real-valued data, ::smpl_t, with up to
45  AUBIO_TENSOR_MAXDIM dimentsions.
46
47  Todo:
48  - add array of strides
49  - add accessors macros
50  - consider removing data
51
52*/
53typedef struct
54{
55  uint_t ndim;     /**< number of dimensions */
56  uint_t shape[AUBIO_TENSOR_MAXDIM]; /**< dimensions array */
57  uint_t size;     /**< total number of elements */
58  smpl_t *buffer;  /**< buffer of values */
59  smpl_t **data;   /**< pointer to rows, or NULL when subtensor */
60} aubio_tensor_t;
61
62/** create a new tensor
63
64  \param ndim   number of dimensions
65  \param shape  array of dimensions
66
67  \return new ::aubio_tensor_t
68
69*/
70aubio_tensor_t *new_aubio_tensor(uint_t ndim, uint_t *shape);
71
72/** destroy a tensor
73
74  \param c  tensor to destroy
75
76*/
77void del_aubio_tensor(aubio_tensor_t *c);
78
79/** view tensor as a vector
80
81  \param c  tensor to view as ::fvec_t
82  \param o  pointer to use to store view
83
84  \return 0 on success, non-zero otherwise
85
86*/
87uint_t aubio_tensor_as_fvec(aubio_tensor_t *c, fvec_t *o);
88
89/** view vector as a tensor
90
91  \param o  ::fvec_t to view as a tensor
92  \param c  pointer to use to store view
93
94  \return 0 on success, non-zero otherwise
95
96*/
97uint_t aubio_fvec_as_tensor(fvec_t *o, aubio_tensor_t *c);
98
99/** view tensor as a matrix
100
101  \param c  tensor to view as ::fmat_t
102  \param o  pointer to use to store view
103
104  \return 0 on success, non-zero otherwise
105
106*/
107uint_t aubio_tensor_as_fmat(aubio_tensor_t *c, fmat_t *o);
108
109/** view matrix as a tensor
110
111  \param o  ::fmat_t to view as a tensor
112  \param c  pointer to use to store view
113
114  \return 0 on success, non-zero otherwise
115
116*/
117uint_t aubio_fmat_as_tensor(fmat_t *o, aubio_tensor_t *c);
118
119/** view i-th row of tensor t as a tensor
120
121  \param t tensor to get maximum from
122  \param i index of row to retrieve
123  \param st subtensor to fill in
124
125  \return 0 on success, non-zero otherwise
126*/
127uint_t aubio_tensor_get_subtensor(aubio_tensor_t *t, uint_t i,
128        aubio_tensor_t *st);
129
130/** find the maximum value of a tensor
131
132  \param t tensor to get maximum from
133
134  \return maximum value of all elements in tensor
135*/
136smpl_t aubio_tensor_max(aubio_tensor_t *t);
137
138/** check if sizes of 2 tensor match
139
140  \param t  first tensor to check size with
141  \param s  second tensor to check size with
142
143  \return 1 if tensors have the same size, 0 otherwise
144*/
145uint_t aubio_tensor_have_same_size(aubio_tensor_t *t, aubio_tensor_t *s);
146
147/** print the content of a tensor
148
149  \param t  tensor to print
150
151 */
152void aubio_tensor_print(aubio_tensor_t *t);
153
154/** get a string representing the dimensions of this tensor
155
156  \param t  tensor to get shape string from
157
158  \return string of characters containing the dimensions of t
159*/
160const char_t *aubio_tensor_get_shape_string(aubio_tensor_t *t);
161
162/** compute matrix multiplication A x B = C
163
164  \param a  left tensor
165  \param b  right tensor
166  \param c  output tensor
167
168*/
169void aubio_tensor_matmul(aubio_tensor_t *a, aubio_tensor_t *b,
170    aubio_tensor_t *c);
171
172/** copy tensor
173
174  \param s  source tensor
175  \param d  destination tensor
176
177*/
178void aubio_tensor_copy(aubio_tensor_t *s, aubio_tensor_t *d);
179
180#ifdef __cplusplus
181}
182#endif
183
184#endif /* AUBIO_TENSOR_H */
Note: See TracBrowser for help on using the repository browser.