[4c33f81] | 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 |
---|
| 25 | extern "C" { |
---|
| 26 | #endif |
---|
| 27 | |
---|
[40520ea] | 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 | */ |
---|
| 42 | typedef 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 */ |
---|
[4c33f81] | 49 | } aubio_tensor_t; |
---|
| 50 | |
---|
[f7838fc] | 51 | /** create a new tensor |
---|
| 52 | |
---|
| 53 | \param ndim number of dimensions |
---|
| 54 | \param shape array of dimensions |
---|
| 55 | |
---|
| 56 | \return new ::aubio_tensor_t |
---|
| 57 | |
---|
| 58 | */ |
---|
[5010e61] | 59 | aubio_tensor_t *new_aubio_tensor(uint_t ndim, uint_t *shape); |
---|
[4c33f81] | 60 | |
---|
[f7838fc] | 61 | /** destroy a tensor |
---|
| 62 | |
---|
| 63 | \param c tensor to destroy |
---|
| 64 | |
---|
| 65 | */ |
---|
[4c33f81] | 66 | void del_aubio_tensor(aubio_tensor_t *c); |
---|
| 67 | |
---|
[f7838fc] | 68 | /** view tensor as a vector |
---|
| 69 | |
---|
| 70 | \param c tensor to view as ::fvec_t |
---|
| 71 | \param o pointer to use to store view |
---|
| 72 | |
---|
| 73 | \return 0 on success, non-zero otherwise |
---|
| 74 | |
---|
| 75 | */ |
---|
[4c33f81] | 76 | uint_t aubio_tensor_as_fvec(aubio_tensor_t *c, fvec_t *o); |
---|
[f7838fc] | 77 | |
---|
| 78 | /** view vector as a tensor |
---|
| 79 | |
---|
| 80 | \param o ::fvec_t to view as a tensor |
---|
| 81 | \param c pointer to use to store view |
---|
| 82 | |
---|
| 83 | \return 0 on success, non-zero otherwise |
---|
| 84 | |
---|
| 85 | */ |
---|
[4c33f81] | 86 | uint_t aubio_fvec_as_tensor(fvec_t *o, aubio_tensor_t *c); |
---|
| 87 | |
---|
[f7838fc] | 88 | /** view tensor as a matrix |
---|
| 89 | |
---|
| 90 | \param c tensor to view as ::fmat_t |
---|
| 91 | \param o pointer to use to store view |
---|
| 92 | |
---|
| 93 | \return 0 on success, non-zero otherwise |
---|
| 94 | |
---|
| 95 | */ |
---|
[4c33f81] | 96 | uint_t aubio_tensor_as_fmat(aubio_tensor_t *c, fmat_t *o); |
---|
[f7838fc] | 97 | |
---|
| 98 | /** view matrix as a tensor |
---|
| 99 | |
---|
| 100 | \param o ::fmat_t to view as a tensor |
---|
| 101 | \param c pointer to use to store view |
---|
| 102 | |
---|
| 103 | \return 0 on success, non-zero otherwise |
---|
| 104 | |
---|
| 105 | */ |
---|
[4c33f81] | 106 | uint_t aubio_fmat_as_tensor(fmat_t *o, aubio_tensor_t *c); |
---|
| 107 | |
---|
[f7838fc] | 108 | /** view i-th row of tensor t as a tensor |
---|
| 109 | |
---|
| 110 | \param t tensor to get maximum from |
---|
| 111 | \param i index of row to retrieve |
---|
| 112 | \param st subtensor to fill in |
---|
| 113 | |
---|
| 114 | \return 0 on success, non-zero otherwise |
---|
| 115 | */ |
---|
[7e0b641] | 116 | uint_t aubio_tensor_get_subtensor(aubio_tensor_t *t, uint_t i, |
---|
| 117 | aubio_tensor_t *st); |
---|
| 118 | |
---|
[f7838fc] | 119 | /** find the maximum value of a tensor |
---|
| 120 | |
---|
| 121 | \param t tensor to get maximum from |
---|
| 122 | |
---|
| 123 | \return maximum value of all elements in tensor |
---|
| 124 | */ |
---|
[4c33f81] | 125 | smpl_t aubio_tensor_max(aubio_tensor_t *t); |
---|
| 126 | |
---|
[f7838fc] | 127 | /** check if sizes of 2 tensor match |
---|
| 128 | |
---|
| 129 | \param t first tensor to check size with |
---|
| 130 | \param s second tensor to check size with |
---|
| 131 | |
---|
| 132 | \return 1 if tensors have the same size, 0 otherwise |
---|
| 133 | */ |
---|
[1343aca] | 134 | uint_t aubio_tensor_have_same_size(aubio_tensor_t *t, aubio_tensor_t *s); |
---|
| 135 | |
---|
[f7838fc] | 136 | /** print the content of a tensor |
---|
| 137 | |
---|
| 138 | \param t tensor to print |
---|
| 139 | |
---|
| 140 | */ |
---|
[1343aca] | 141 | void aubio_tensor_print(aubio_tensor_t *t); |
---|
| 142 | |
---|
[f7838fc] | 143 | /** get a string representing the dimensions of this tensor |
---|
| 144 | |
---|
| 145 | \param t tensor to get shape string from |
---|
| 146 | |
---|
| 147 | \return string of characters containing the dimensions of t |
---|
| 148 | */ |
---|
[1343aca] | 149 | const char_t *aubio_tensor_get_shape_string(aubio_tensor_t *t); |
---|
[4c33f81] | 150 | |
---|
[6006760] | 151 | void aubio_tensor_matmul(aubio_tensor_t *a, aubio_tensor_t *b, |
---|
| 152 | aubio_tensor_t *c); |
---|
| 153 | |
---|
[4c33f81] | 154 | #ifdef __cplusplus |
---|
| 155 | } |
---|
| 156 | #endif |
---|
| 157 | |
---|
| 158 | #endif /* AUBIO_TENSOR_H */ |
---|