| 1 | #cxx . . $ `<file>/melder/NUM.h`/pragma once |
| 2 | /* NUM.h |
| 3 | * |
| 4 | * Copyright (C) 1992-2024 Paul Boersma |
| 5 | * |
| 6 | * This code 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 2 of the License, or (at |
| 9 | * your option) any later version. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 14 | * See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | /* |
| 21 | The following functions are called in inline functions, |
| 22 | so they have to be declared first. |
| 23 | */ |
| 24 | |
| 25 | template <typename T> |
| 26 | bool NUMisEmptycxx . . $ NUMisEmpty(3c471b8d64252e9b). (vectorcxx . . $ vector#<T> const& x) noexcept { |
| 27 | return x.sizecxx . . $ vector#size. == 0; // note: testing on x.at is incorrect, because the capacity may be large when the size is 0 |
| 28 | } |
| 29 | template <typename T> |
| 30 | bool NUMisEmptycxx . . $ NUMisEmpty(4ebd83fa8de8f2f9). (vectorviewcxx . . $ vectorview#<T> const& x) noexcept { |
| 31 | return x.sizecxx . . $ vectorview#size. == 0; // note: testing on x.at is incorrect, because the capacity may be large when the size is 0 |
| 32 | } |
| 33 | template <typename T> |
| 34 | bool NUMisEmptycxx . . $ NUMisEmpty(d2f4442a12a6e0e9). (constvectorcxx . . $ constvector#<T> const& x) noexcept { |
| 35 | return x.sizecxx . . $ constvector#size. == 0; // note: testing on x.at is incorrect, because the capacity may be large when the size is 0 |
| 36 | } |
| 37 | template <typename T> |
| 38 | bool NUMisEmptycxx . . $ NUMisEmpty(cc1ac9a2a7378777). (constvectorviewcxx . . $ constvectorview#<T> const& x) noexcept { |
| 39 | return x.sizecxx . . $ constvectorview#size. == 0; // note: testing on x.at is incorrect, because the capacity may be large when the size is 0 |
| 40 | } |
| 41 | |
| 42 | template <typename T> |
| 43 | bool NUMisEmptycxx . . $ NUMisEmpty(43b61114f729c675). (matrixcxx . . $ matrix#<T> const& x) noexcept { |
| 44 | const integercxx . . $ integer# numberOfCells = x.nrowcxx . . $ matrix#nrow. *cxx . . $ `operator*`(b464376f9cf8932a). x.ncolcxx . . $ matrix#ncol.; |
| 45 | return numberOfCells == 0; // note: a matrix with 0 rows and 6 columns is a valid empty matrix, to which e.g. a row can be added |
| 46 | } |
| 47 | template <typename T> |
| 48 | bool NUMisEmptycxx . . $ NUMisEmpty(d1d1b198a4d2bdd0). (constmatrixcxx . . $ constmatrix#<T> const& x) noexcept { |
| 49 | const integercxx . . $ integer# numberOfCells = x.nrowcxx . . $ constmatrix#nrow. *cxx . . $ `operator*`(b464376f9cf8932a). x.ncolcxx . . $ constmatrix#ncol.; |
| 50 | return numberOfCells == 0; // note: a matrix with 0 rows and 6 columns is a valid empty matrix, to which e.g. a row can be added |
| 51 | } |
| 52 | template <typename T> |
| 53 | bool NUMisEmptycxx . . $ NUMisEmpty(696686ed6cdf6bd6). (matrixviewcxx . . $ matrixview#<T> const& x) noexcept { |
| 54 | const integercxx . . $ integer# numberOfCells = x.nrowcxx . . $ matrixview#nrow. *cxx . . $ `operator*`(b464376f9cf8932a). x.ncolcxx . . $ matrixview#ncol.; |
| 55 | return numberOfCells == 0; // note: a matrix with 0 rows and 6 columns is a valid empty matrix, to which e.g. a row can be added |
| 56 | } |
| 57 | template <typename T> |
| 58 | bool NUMisEmptycxx . . $ NUMisEmpty(939f42bb6b0c0c9c). (constmatrixviewcxx . . $ constmatrixview#<T> const& x) noexcept { |
| 59 | const integercxx . . $ integer# numberOfCells = x.nrowcxx . . $ constmatrixview#nrow. *cxx . . $ `operator*`(b464376f9cf8932a). x.ncolcxx . . $ constmatrixview#ncol.; |
| 60 | return numberOfCells == 0; // note: a matrix with 0 rows and 6 columns is a valid empty matrix, to which e.g. a row can be added |
| 61 | } |
| 62 | |
| 63 | inline bool NUMisEmptycxx . . $ NUMisEmpty(72eec41a35d7e37c). (constSTRVECcxx . . $ constSTRVEC# const& x) noexcept { |
| 64 | return x.sizecxx . . $ _conststringvector#size. == 0; |
| 65 | } |
| 66 | |
| 67 | extern MelderRealRangecxx . . $ MelderRealRange# NUMextrema_ecxx . . $ NUMextrema_e(276b80eee54cd772). (constVECVUcxx . . $ constVECVU# const& vec); |
| 68 | extern MelderRealRangecxx . . $ MelderRealRange# NUMextrema_ucxx . . $ NUMextrema_u(453fd68922d5429d). (constVECVUcxx . . $ constVECVU# const& vec) noexcept; |
| 69 | extern MelderRealRangecxx . . $ MelderRealRange# NUMextrema_ecxx . . $ NUMextrema_e(409218941a87bbaf). (constMATVUcxx . . $ constMATVU# const& mat); |
| 70 | extern MelderRealRangecxx . . $ MelderRealRange# NUMextrema_ucxx . . $ NUMextrema_u(422efbc4a34c6b38). (constMATVUcxx . . $ constMATVU# const& mat) noexcept; |
| 71 | extern MelderIntegerRangecxx . . $ MelderIntegerRange# NUMextrema_ecxx . . $ NUMextrema_e(cfa463b8968d2917). (constINTVECVUcxx . . $ constINTVECVU# const& vec); |
| 72 | extern MelderIntegerRangecxx . . $ MelderIntegerRange# NUMextrema_ucxx . . $ NUMextrema_u(3682e4cc51b95972). (constINTVECVUcxx . . $ constINTVECVU# const& vec) noexcept; |
| 73 | |
| 74 | /* |
| 75 | From here on, the functions appear in alphabetical order. |
| 76 | */ |
| 77 | |
| 78 | extern double NUMcenterOfGravitycxx . . $ NUMcenterOfGravity(4bb9c3e3a8dd5442). (constVECVUcxx . . $ constVECVU# const& x) noexcept; |
| 79 | |
| 80 | inline integercxx . . $ integer# NUMcountDefinedcxx . . $ NUMcountDefined(a7a82c2bc2b2c948). (constVECVUcxx . . $ constVECVU# const& vec) noexcept { |
| 81 | integercxx . . $ integer# result = 0; |
| 82 | for (integercxx . . $ integer# i = 1; i <= vec.sizecxx . . $ constvectorview#size.; i ++) |
| 83 | if (isdefinedcxx . . $ isdefined(f8197d536af80c96). (vec [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).i])) |
| 84 | result += 1; |
| 85 | return result; |
| 86 | } |
| 87 | inline bool NUMdefinedcxx . . $ NUMdefined(b433243621879d5a). (constVECVUcxx . . $ constVECVU# const& vec) noexcept { |
| 88 | for (integercxx . . $ integer# i = 1; i <= vec.sizecxx . . $ constvectorview#size.; i ++) |
| 89 | if (isundefcxx . . $ isundef(f8197d536af80c96). (vec [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).i])) |
| 90 | return false; |
| 91 | return true; |
| 92 | } |
| 93 | inline bool NUMdefinedcxx . . $ NUMdefined(22df7c734db6567e). (constMATVUcxx . . $ constMATVU# const& mat) noexcept { |
| 94 | for (integercxx . . $ integer# irow = 1; irow <= mat.nrowcxx . . $ constmatrixview#nrow.; irow ++) |
| 95 | for (integercxx . . $ integer# icol = 1; icol <= mat.ncolcxx . . $ constmatrixview#ncol.; icol ++) |
| 96 | if (isundefcxx . . $ isundef(f8197d536af80c96). (mat [cxx . . $ constmatrixview#`operator[]`(7a6174ed67b49158).irow] [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).icol])) |
| 97 | return false; |
| 98 | return true; |
| 99 | } |
| 100 | |
| 101 | inline bool NUMequalcxx . . $ NUMequal(828b76dce88fac). (double x, double y) { |
| 102 | /* |
| 103 | Any defined value is unequal to --undefined--, |
| 104 | but any undefined value (inf or NaN) *is* equal to --undefined--. |
| 105 | This is different from how "==" works in C, hence the following complication. |
| 106 | */ |
| 107 | return x == y || (isundefcxx . . $ isundef(f8197d536af80c96). (x) && isundefcxx . . $ isundef(f8197d536af80c96). (y)); |
| 108 | } |
| 109 | inline bool NUMequalcxx . . $ NUMequal(90cec1884aa6bdb1). (integercxx . . $ integer# x, integercxx . . $ integer# y) { |
| 110 | return x == y; |
| 111 | } |
| 112 | inline bool NUMequalcxx . . $ NUMequal(f2cb034b043a1ce9). (bool x, bool y) { |
| 113 | return x == y; |
| 114 | } |
| 115 | inline bool NUMequalcxx . . $ NUMequal(4ed805b44025c28a). (bytecxx . . $ byte# x, bytecxx . . $ byte# y) { |
| 116 | return x == y; |
| 117 | } |
| 118 | inline bool NUMequalcxx . . $ NUMequal(30b64aeee28aa6cb). (dcomplexcxx . . $ dcomplex# x, dcomplexcxx . . $ dcomplex# y) { |
| 119 | return x.realcxx . . $ std/complex#real(21b6c25e127938e2).() == y.realcxx . . $ std/complex#real(21b6c25e127938e2).() && x.imagcxx . . $ std/complex#imag(21b6c25e127938e2).() == y.imagcxx . . $ std/complex#imag(21b6c25e127938e2).(); // |
| 120 | } |
| 121 | template <typename T> |
| 122 | bool NUMequalcxx . . $ NUMequal(aec8f09262437d). (constvectorcxx . . $ constvector#<T> const& x, constvectorcxx . . $ constvector#<T> const& y) noexcept { |
| 123 | const integercxx . . $ integer# n = x.sizecxx . . $ constvector#size.; |
| 124 | if (y.sizecxx . . $ constvector#size. != n) |
| 125 | return false; |
| 126 | for (integercxx . . $ integer# i = 1; i <= n; i ++) |
| 127 | if (! NUMequalcxx . . $ NUMequal(aec8f09262437d). (x [i], y [i])) |
| 128 | return false; |
| 129 | return true; |
| 130 | } |
| 131 | template <typename T> |
| 132 | bool NUMequalcxx . . $ NUMequal(573ecd7333c34ff6). (vectorcxx . . $ vector#<T> const& x, constvectorcxx . . $ constvector#<T> const& y) noexcept { |
| 133 | return NUMequalcxx . . $ NUMequal(573ecd7333c34ff6). (constvectorcxx . . $ constvector#<T> (x), y); |
| 134 | } |
| 135 | template <typename T> |
| 136 | bool NUMequalcxx . . $ NUMequal(8b2a2df94cf3ee9c). (constvectorcxx . . $ constvector#<T> const& x, vectorcxx . . $ vector#<T> const& y) noexcept { |
| 137 | return NUMequalcxx . . $ NUMequal(8b2a2df94cf3ee9c). (x, constvectorcxx . . $ constvector#<T> (y)); |
| 138 | } |
| 139 | template <typename T> |
| 140 | bool NUMequalcxx . . $ NUMequal(6596de982874463a). (vectorcxx . . $ vector#<T> const& x, vectorcxx . . $ vector#<T> const& y) noexcept { |
| 141 | return NUMequalcxx . . $ NUMequal(6596de982874463a). (constvectorcxx . . $ constvector#<T> (x), constvectorcxx . . $ constvector#<T> (y)); |
| 142 | } |
| 143 | |
| 144 | template <typename T> |
| 145 | bool NUMequalcxx . . $ NUMequal(b417ddf31732047c). (constmatrixcxx . . $ constmatrix#<T> const& x, constmatrixcxx . . $ constmatrix#<T> const& y) noexcept { |
| 146 | const integercxx . . $ integer# nrow = x.nrowcxx . . $ constmatrix#nrow., ncol = x.ncolcxx . . $ constmatrix#ncol.; |
| 147 | if (y.nrowcxx . . $ constmatrix#nrow. != nrow || y.ncolcxx . . $ constmatrix#ncol. != ncol) |
| 148 | return false; |
| 149 | for (integercxx . . $ integer# irow = 1; irow <= nrow; irow ++) |
| 150 | for (integercxx . . $ integer# icol = 1; icol <= ncol; icol ++) |
| 151 | if (! NUMequalcxx . . $ NUMequal(b417ddf31732047c). (x [irow] [icol], y [irow] [icol])) |
| 152 | return false; |
| 153 | return true; |
| 154 | } |
| 155 | template <typename T> |
| 156 | bool NUMequalcxx . . $ NUMequal(a41870062bd8b088). (matrixcxx . . $ matrix#<T> const& x, constmatrixcxx . . $ constmatrix#<T> const& y) noexcept { |
| 157 | return NUMequalcxx . . $ NUMequal(a41870062bd8b088). (constmatrixcxx . . $ constmatrix#<T> (x), y); |
| 158 | } |
| 159 | template <typename T> |
| 160 | bool NUMequalcxx . . $ NUMequal(a17c65eb3cd01802). (constmatrixcxx . . $ constmatrix#<T> const& x, matrixcxx . . $ matrix#<T> const& y) noexcept { |
| 161 | return NUMequalcxx . . $ NUMequal(a17c65eb3cd01802). (x, constmatrixcxx . . $ constmatrix#<T> (y)); |
| 162 | } |
| 163 | template <typename T> |
| 164 | bool NUMequalcxx . . $ NUMequal(bcd99c6dca37547). (matrixcxx . . $ matrix#<T> const& x, matrixcxx . . $ matrix#<T> const& y) noexcept { |
| 165 | return NUMequalcxx . . $ NUMequal(bcd99c6dca37547). (constmatrixcxx . . $ constmatrix#<T> (x), constmatrixcxx . . $ constmatrix#<T> (y)); |
| 166 | } |
| 167 | |
| 168 | inline bool NUMequalcxx . . $ NUMequal(a0b5f47107c5438c). (constSTRVECcxx . . $ constSTRVEC# x, constSTRVECcxx . . $ constSTRVEC# y) noexcept { |
| 169 | const integercxx . . $ integer# n = x.sizecxx . . $ _conststringvector#size.; |
| 170 | if (y.sizecxx . . $ _conststringvector#size. != n) |
| 171 | return false; |
| 172 | for (integercxx . . $ integer# i = 1; i <= n; i ++) |
| 173 | if (! Melder_equcxx . . $ `melder/melder_str32.h:124:9`! (x [cxx . . $ _conststringvector#`operator[]`(2065423e0524e64a).i], y [cxx . . $ _conststringvector#`operator[]`(2065423e0524e64a).i])) |
| 174 | return false; |
| 175 | return true; |
| 176 | } |
| 177 | |
| 178 | inline double NUMextremum_ecxx . . $ NUMextremum_e(fa513f1eb826a064). (constVECVUcxx . . $ constVECVU# const& vec) { |
| 179 | if (NUMisEmptycxx . . $ NUMisEmpty(cc1ac9a2a7378777). (vec)) |
| 180 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Cannot determine the extremum of an empty vector."); |
| 181 | double extremum = 0.0; |
| 182 | for (integercxx . . $ integer# i = 1; i <= vec.sizecxx . . $ constvectorview#size.; i ++) { |
| 183 | const double value = fabscxx . . $ fabs(fee4f1d22bc8e617). (vec [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).i]); |
| 184 | if (isundefcxx . . $ isundef(f8197d536af80c96). (value)) |
| 185 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Cannot determine the extremum of a vector: element ", i, U" is undefined."); |
| 186 | if (value > extremum) |
| 187 | extremum = value; |
| 188 | } |
| 189 | return extremum; |
| 190 | } |
| 191 | inline double NUMextremum_ucxx . . $ NUMextremum_u(4bb9c3e3a8dd5442). (constVECVUcxx . . $ constVECVU# const& vec) noexcept { |
| 192 | if (NUMisEmptycxx . . $ NUMisEmpty(cc1ac9a2a7378777). (vec)) |
| 193 | return undefinedcxx . . $ undefined.; |
| 194 | double extremum = 0.0; |
| 195 | for (integercxx . . $ integer# i = 1; i <= vec.sizecxx . . $ constvectorview#size.; i ++) { |
| 196 | const double value = fabscxx . . $ fabs(fee4f1d22bc8e617). (vec [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).i]); |
| 197 | if (isundefcxx . . $ isundef(f8197d536af80c96). (value)) |
| 198 | return undefinedcxx . . $ undefined.; |
| 199 | if (value > extremum) |
| 200 | extremum = value; |
| 201 | } |
| 202 | return extremum; |
| 203 | } |
| 204 | inline double NUMextremum_ecxx . . $ NUMextremum_e(7a3744b654164b28). (constMATVUcxx . . $ constMATVU# const& mat) { |
| 205 | const MelderRealRangecxx . . $ MelderRealRange# range = NUMextrema_ecxx . . $ NUMextrema_e(409218941a87bbaf). (mat); |
| 206 | return stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a). (fabscxx . . $ fabs(fee4f1d22bc8e617). (range.mincxx . . $ MelderRealRange#min.), fabscxx . . $ fabs(fee4f1d22bc8e617). (range.maxcxx . . $ MelderRealRange#max.)); |
| 207 | } |
| 208 | inline double NUMextremum_ucxx . . $ NUMextremum_u(7a3744b654164b28). (constMATVUcxx . . $ constMATVU# const& mat) { |
| 209 | const MelderRealRangecxx . . $ MelderRealRange# range = NUMextrema_ucxx . . $ NUMextrema_u(422efbc4a34c6b38). (mat); |
| 210 | if (isundefcxx . . $ isundef(dfa1b40f738f9ef2). (range)) |
| 211 | return undefinedcxx . . $ undefined.; |
| 212 | return stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a). (fabscxx . . $ fabs(fee4f1d22bc8e617). (range.mincxx . . $ MelderRealRange#min.), fabscxx . . $ fabs(fee4f1d22bc8e617). (range.maxcxx . . $ MelderRealRange#max.)); |
| 213 | } |
| 214 | |
| 215 | inline integercxx . . $ integer# NUMfindFirstcxx . . $ NUMfindFirst(5bcfdb87a5d5128). (constSTRVECcxx . . $ constSTRVEC# const& strvec, conststring32cxx . . $ conststring32# str) { |
| 216 | for (integercxx . . $ integer# i = 1; i <= strvec.sizecxx . . $ _conststringvector#size.; i ++) |
| 217 | if (Melder_equcxx . . $ `melder/melder_str32.h:124:9`! (strvec [cxx . . $ _conststringvector#`operator[]`(2065423e0524e64a).i], str)) |
| 218 | return i; |
| 219 | return 0; |
| 220 | } |
| 221 | inline integercxx . . $ integer# NUMfindFirst_caseInsensitivecxx . . $ NUMfindFirst_caseInsensitive(5bcfdb87a5d5128). (constSTRVECcxx . . $ constSTRVEC# const& strvec, conststring32cxx . . $ conststring32# str) { |
| 222 | for (integercxx . . $ integer# i = 1; i <= strvec.sizecxx . . $ _conststringvector#size.; i ++) |
| 223 | if (Melder_equ_caseInsensitivecxx . . $ `melder/melder_str32.h:127:9`! (strvec [cxx . . $ _conststringvector#`operator[]`(2065423e0524e64a).i], str)) |
| 224 | return i; |
| 225 | return 0; |
| 226 | } |
| 227 | inline integercxx . . $ integer# NUMfindLastcxx . . $ NUMfindLast(5bcfdb87a5d5128). (constSTRVECcxx . . $ constSTRVEC# const& strvec, conststring32cxx . . $ conststring32# str) { |
| 228 | for (integercxx . . $ integer# i = strvec.sizecxx . . $ _conststringvector#size.; i >= 1; i --) |
| 229 | if (Melder_equcxx . . $ `melder/melder_str32.h:124:9`! (strvec [cxx . . $ _conststringvector#`operator[]`(2065423e0524e64a).i], str)) |
| 230 | return i; |
| 231 | return 0; |
| 232 | } |
| 233 | inline integercxx . . $ integer# NUMfindLast_caseInsensitivecxx . . $ NUMfindLast_caseInsensitive(5bcfdb87a5d5128). (constSTRVECcxx . . $ constSTRVEC# const& strvec, conststring32cxx . . $ conststring32# str) { |
| 234 | for (integercxx . . $ integer# i = strvec.sizecxx . . $ _conststringvector#size.; i >= 1; i --) |
| 235 | if (Melder_equcxx . . $ `melder/melder_str32.h:124:9`! (strvec [cxx . . $ _conststringvector#`operator[]`(2065423e0524e64a).i], str)) |
| 236 | return i; |
| 237 | return 0; |
| 238 | } |
| 239 | |
| 240 | inline integercxx . . $ integer# NUMfindInSortedcxx . . $ NUMfindInSorted(5bcfdb87a5d5128). (constSTRVECcxx . . $ constSTRVEC# const& strvec, conststring32cxx . . $ conststring32# string) { |
| 241 | if (strvec.sizecxx . . $ _conststringvector#size. == 0) |
| 242 | return 0; |
| 243 | |
| 244 | const int atEnd = str32cmpcxx . . $ str32cmp(937dacc22d2a7919). (string, strvec [cxx . . $ _conststringvector#`operator[]`(2065423e0524e64a).strvec.sizecxx . . $ _conststringvector#size.]); |
| 245 | if (atEnd > 0) |
| 246 | return 0; |
| 247 | if (atEnd == 0) |
| 248 | return strvec.sizecxx . . $ _conststringvector#size.; |
| 249 | |
| 250 | const int atStart = str32cmpcxx . . $ str32cmp(937dacc22d2a7919). (string, strvec [cxx . . $ _conststringvector#`operator[]`(2065423e0524e64a).1]); |
| 251 | if (atStart < 0) |
| 252 | return 0; |
| 253 | if (atStart == 0) |
| 254 | return 1; |
| 255 | |
| 256 | integercxx . . $ integer# left = 1, right = strvec.sizecxx . . $ _conststringvector#size.; |
| 257 | while (left < right - 1) { |
| 258 | const integercxx . . $ integer# mid = (left + right) / 2; |
| 259 | const int here = str32cmpcxx . . $ str32cmp(937dacc22d2a7919). (string, strvec [cxx . . $ _conststringvector#`operator[]`(2065423e0524e64a).mid]); |
| 260 | if (here == 0) |
| 261 | return mid; |
| 262 | if (here > 0) |
| 263 | left = mid; |
| 264 | else |
| 265 | right = mid; |
| 266 | } |
| 267 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (right == left + 1); |
| 268 | return 0; |
| 269 | } |
| 270 | |
| 271 | extern double NUMinnercxx . . $ NUMinner(5e5adb47f563a3e3). (constVECVUcxx . . $ constVECVU# const& x, constVECVUcxx . . $ constVECVU# const& y) noexcept; |
| 272 | |
| 273 | inline bool NUMisSquarecxx . . $ NUMisSquare(22df7c734db6567e). (constMATVUcxx . . $ constMATVU# const& x) noexcept { |
| 274 | return x.nrowcxx . . $ constmatrixview#nrow. == x.ncolcxx . . $ constmatrixview#ncol.; |
| 275 | } |
| 276 | |
| 277 | inline bool NUMisSymmetriccxx . . $ NUMisSymmetric(22df7c734db6567e). (constMATVUcxx . . $ constMATVU# const& x) noexcept { |
| 278 | if (x.nrowcxx . . $ constmatrixview#nrow. != x.ncolcxx . . $ constmatrixview#ncol.) |
| 279 | return false; |
| 280 | const integercxx . . $ integer# n = x.nrowcxx . . $ constmatrixview#nrow.; |
| 281 | for (integercxx . . $ integer# irow = 1; irow <= n; irow ++) |
| 282 | for (integercxx . . $ integer# icol = irow + 1; icol < n; icol ++) |
| 283 | if (x [cxx . . $ constmatrixview#`operator[]`(7a6174ed67b49158).irow] [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).icol] != x [cxx . . $ constmatrixview#`operator[]`(7a6174ed67b49158).icol] [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).irow]) |
| 284 | return false; |
| 285 | return true; |
| 286 | } |
| 287 | |
| 288 | inline double NUMlengthcxx . . $ NUMlength(d232a409a91fe966). (conststring32cxx . . $ conststring32# str) noexcept { |
| 289 | return double (Melder_lengthcxx . . $ Melder_length(3fae411214b133ad). (str)); |
| 290 | } |
| 291 | |
| 292 | inline double NUMlog2cxx . . $ NUMlog2(fee4f1d22bc8e617). (double x) noexcept { |
| 293 | return logcxx . . $ log(fee4f1d22bc8e617). (x) * NUMlog2ecxx . . $ NUMlog2e.; |
| 294 | } |
| 295 | |
| 296 | extern double NUMmin_ecxx . . $ NUMmin_e(fa513f1eb826a064). (constVECVUcxx . . $ constVECVU# const& vec); // throw if empty or undefined element |
| 297 | extern double NUMmin_ucxx . . $ NUMmin_u(4bb9c3e3a8dd5442). (constVECVUcxx . . $ constVECVU# const& vec) noexcept; // undef if empty or undefined element |
| 298 | extern double NUMmin_removeUndefined_ecxx . . $ NUMmin_removeUndefined_e(fa513f1eb826a064). (constVECVUcxx . . $ constVECVU# const& vec); // throw if no defined elements |
| 299 | extern double NUMmin_removeUndefined_ucxx . . $ NUMmin_removeUndefined_u(4bb9c3e3a8dd5442). (constVECVUcxx . . $ constVECVU# const& vec) noexcept; // undef if no defined elements |
| 300 | extern integercxx . . $ integer# NUMmin_ecxx . . $ NUMmin_e(ff5c8185b8e92fd6). (constINTVECVUcxx . . $ constINTVECVU# const& vec); // throw if empty |
| 301 | extern integercxx . . $ integer# NUMmin_ucxx . . $ NUMmin_u(967b12debc2a64dd). (constINTVECVUcxx . . $ constINTVECVU# const& vec) noexcept; // intmax if empty |
| 302 | extern double NUMmin_ecxx . . $ NUMmin_e(7a3744b654164b28). (constMATVUcxx . . $ constMATVU# const& mat); // throw if empty or undefined element |
| 303 | extern double NUMmin_ucxx . . $ NUMmin_u(98ed2a492958fa8a). (constMATVUcxx . . $ constMATVU# const& mat) noexcept; // undef if empty or undefined element |
| 304 | extern double NUMmin_removeUndefined_ecxx . . $ NUMmin_removeUndefined_e(7a3744b654164b28). (constMATVUcxx . . $ constMATVU# const& mat); // throw if no defined elements |
| 305 | extern double NUMmin_removeUndefined_ucxx . . $ NUMmin_removeUndefined_u(98ed2a492958fa8a). (constMATVUcxx . . $ constMATVU# const& mat) noexcept; // undef if no defined elements |
| 306 | |
| 307 | extern double NUMmax_ecxx . . $ NUMmax_e(fa513f1eb826a064). (constVECVUcxx . . $ constVECVU# const& vec); // throw if empty or undefined element |
| 308 | extern double NUMmax_ucxx . . $ NUMmax_u(4bb9c3e3a8dd5442). (constVECVUcxx . . $ constVECVU# const& vec) noexcept; // undef if empty or undefined element |
| 309 | extern double NUMmax_removeUndefined_ecxx . . $ NUMmax_removeUndefined_e(fa513f1eb826a064). (constVECVUcxx . . $ constVECVU# const& vec); // throw if no defined elements |
| 310 | extern double NUMmax_removeUndefined_ucxx . . $ NUMmax_removeUndefined_u(4bb9c3e3a8dd5442). (constVECVUcxx . . $ constVECVU# const& vec) noexcept; // undef if no defined elements |
| 311 | extern integercxx . . $ integer# NUMmax_ecxx . . $ NUMmax_e(ff5c8185b8e92fd6). (constINTVECVUcxx . . $ constINTVECVU# const& vec); // throw if empty |
| 312 | extern integercxx . . $ integer# NUMmax_ucxx . . $ NUMmax_u(967b12debc2a64dd). (constINTVECVUcxx . . $ constINTVECVU# const& vec) noexcept; // intmin if empty |
| 313 | extern double NUMmax_ecxx . . $ NUMmax_e(7a3744b654164b28). (constMATVUcxx . . $ constMATVU# const& mat); // throw if empty or undefined element |
| 314 | extern double NUMmax_ucxx . . $ NUMmax_u(98ed2a492958fa8a). (constMATVUcxx . . $ constMATVU# const& mat) noexcept; // undef if empty or undefined element |
| 315 | extern double NUMmax_removeUndefined_ecxx . . $ NUMmax_removeUndefined_e(7a3744b654164b28). (constMATVUcxx . . $ constMATVU# const& mat); // throw if no defined elements |
| 316 | extern double NUMmax_removeUndefined_ucxx . . $ NUMmax_removeUndefined_u(98ed2a492958fa8a). (constMATVUcxx . . $ constMATVU# const& mat) noexcept; // undef if no defined elements |
| 317 | |
| 318 | extern double NUMminimumLengthcxx . . $ NUMminimumLength(ca1a6d5bd822b1c2). (constSTRVECcxx . . $ constSTRVEC# const& x) noexcept; |
| 319 | extern double NUMmaximumLengthcxx . . $ NUMmaximumLength(ca1a6d5bd822b1c2). (constSTRVECcxx . . $ constSTRVEC# const& x) noexcept; |
| 320 | |
| 321 | extern double NUMmeancxx . . $ NUMmean(4bb9c3e3a8dd5442). (constVECVUcxx . . $ constVECVU# const& vec) noexcept; |
| 322 | extern double NUMmeancxx . . $ NUMmean(98ed2a492958fa8a). (constMATVUcxx . . $ constMATVU# const& mat) noexcept; |
| 323 | |
| 324 | extern MelderGaussianStatscxx . . $ MelderGaussianStats# NUMmeanStdevcxx . . $ NUMmeanStdev(97af7fa66bc3d2dd). (constVECVUcxx . . $ constVECVU# const& vec) noexcept; |
| 325 | extern MelderGaussianStatscxx . . $ MelderGaussianStats# NUMmeanStdevcxx . . $ NUMmeanStdev(89994f7c2020bdc1). (constMATVUcxx . . $ constMATVU# const& mat) noexcept; |
| 326 | |
| 327 | double NUMnormcxx . . $ NUMnorm(885a97927582bd48). (constVECVUcxx . . $ constVECVU# const& x, double power) noexcept; |
| 328 | double NUMnormcxx . . $ NUMnorm(e5abd6d02bcd8f8). (constMATVUcxx . . $ constMATVU# const& x, double power) noexcept; |
| 329 | |
| 330 | integercxx . . $ integer# NUMnumberOfTokenscxx . . $ NUMnumberOfTokens(3fae411214b133ad). (conststring32cxx . . $ conststring32# str) noexcept; |
| 331 | |
| 332 | /* |
| 333 | Return zero for non-positive base. |
| 334 | */ |
| 335 | inline double NUMpowcxx . . $ NUMpow(d8e7e0733fa41c87). (double base, double exponent) { |
| 336 | return base <= 0.0 ? 0.0 : powcxx . . $ pow(b71928d39fde4295). (base, exponent); |
| 337 | } |
| 338 | |
| 339 | inline double NUMsqrt_ucxx . . $ NUMsqrt_u(447c67c6676f75c3). (const double x) { |
| 340 | #if defined (_WIN32) |
| 341 | if (! (x >= 0.0)) // NaN-safe |
| 342 | return undefined; |
| 343 | #endif |
| 344 | return sqrtcxx . . $ sqrt(fee4f1d22bc8e617). (x); |
| 345 | } |
| 346 | |
| 347 | inline double NUMsqrt_0cxx . . $ NUMsqrt_0(447c67c6676f75c3). (const double x) { |
| 348 | if (! (x >= 0.0)) // NaN-safe |
| 349 | return 0.0; |
| 350 | return sqrtcxx . . $ sqrt(fee4f1d22bc8e617). (x); |
| 351 | } |
| 352 | |
| 353 | inline double NUMsqrt_ecxx . . $ NUMsqrt_e(447c67c6676f75c3). (const double x) { |
| 354 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (x >= 0.0, |
| 355 | U"You cannot take the square root of a negative number (", x, U")."); |
| 356 | return sqrtcxx . . $ sqrt(fee4f1d22bc8e617). (x); |
| 357 | } |
| 358 | |
| 359 | inline double NUMsqrt_acxx . . $ NUMsqrt_a(447c67c6676f75c3). (const double x) { |
| 360 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (x >= 0.0); |
| 361 | return sqrtcxx . . $ sqrt(fee4f1d22bc8e617). (x); |
| 362 | } |
| 363 | |
| 364 | extern double NUMstdevcxx . . $ NUMstdev(4bb9c3e3a8dd5442). (constVECVUcxx . . $ constVECVU# const& vec) noexcept; |
| 365 | extern double NUMstdevcxx . . $ NUMstdev(98ed2a492958fa8a). (constMATVUcxx . . $ constMATVU# const& mat) noexcept; |
| 366 | |
| 367 | extern double NUMsumcxx . . $ NUMsum(4bb9c3e3a8dd5442). (constVECVUcxx . . $ constVECVU# const& vec) noexcept; |
| 368 | extern double NUMsumcxx . . $ NUMsum(98ed2a492958fa8a). (constMATVUcxx . . $ constMATVU# const& mat) noexcept; |
| 369 | |
| 370 | extern double NUMsum2cxx . . $ NUMsum2(fa513f1eb826a064). (constVECVUcxx . . $ constVECVU# const& vec); |
| 371 | extern double NUMsum2cxx . . $ NUMsum2(7a3744b654164b28). (constMATVUcxx . . $ constMATVU# const& mat); |
| 372 | |
| 373 | extern double NUMsumOfSquaredDifferencescxx . . $ NUMsumOfSquaredDifferences(207ff1b89ec3edee). (constVECVUcxx . . $ constVECVU# const& vec, double mean); |
| 374 | extern double NUMcorrelationcxx . . $ NUMcorrelation(453baa2d8fbe1ac4). (constVECVUcxx . . $ constVECVU# const& vec1, constVECVUcxx . . $ constVECVU# const& vec2); |
| 375 | |
| 376 | extern double NUMtotalLengthcxx . . $ NUMtotalLength(eab58d34c81ade32). (constSTRVECcxx . . $ constSTRVEC# const& x); |
| 377 | |
| 378 | extern double NUMvariancecxx . . $ NUMvariance(4bb9c3e3a8dd5442). (constVECVUcxx . . $ constVECVU# const& vec) noexcept; |
| 379 | extern double NUMvariancecxx . . $ NUMvariance(98ed2a492958fa8a). (constMATVUcxx . . $ constMATVU# const& mat) noexcept; |
| 380 | |
| 381 | /* End of file NUM.h */ |