| 1 | /* VEC.cpp |
| 2 | * |
| 3 | * Copyright (C) 2017-2021,2023,2025,2026 Paul Boersma |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or (at |
| 8 | * your option) any later version. |
| 9 | * |
| 10 | * This code is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 | * See the GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #include "melder.h"cxx . . $ `<file>/melder/melder.h`/ |
| 20 | #include "../dwsys/NUM2.h"cxx . . $ `<file>/dwsys/NUM2.h`/ /* for NUMsort2 */ |
| 21 | #include "../external/blake3/blake3.h"cxx . . $ `<file>/external/blake3/blake3.h`/ |
| 22 | |
| 23 | #ifdef macintosh |
| 24 | #include "macport_on.h" |
| 25 | #include <Accelerate/Accelerate.h> |
| 26 | #include "macport_off.h" |
| 27 | #endif |
| 28 | |
| 29 | #if defined (macintosh) |
| 30 | void _add_macfast_VEC_out (VECVU const& target, constVECVU const& x, constVECVU const& y) noexcept { |
| 31 | integer n = target.size; |
| 32 | vDSP_vaddD (& x [1], x.stride, & y [1], y.stride, & target [1], target.stride, integer_to_uinteger_a (n)); |
| 33 | /* |
| 34 | Speed if always vDSP_vaddD: |
| 35 | //9.3,1.26,0.21, 0.10,0.42,0.70, 1.17,1.97,5.32 |
| 36 | Speed if always explicit loop: |
| 37 | 0.61,1.99,4.32, 4.39,2.61,1.51, 0.85,0.50,0.41 |
| 38 | Combined: |
| 39 | 6.1,1.19,0.23, 0.13,0.41,0.70, 1.19,2.02,2.45 |
| 40 | */ |
| 41 | } |
| 42 | #endif |
| 43 | |
| 44 | autoVECcxx . . $ autoVEC# from_to_VECcxx . . $ from_to_VEC(bb39e454971b6b6b). (double from, double to) { |
| 45 | const integercxx . . $ integer# numberOfElements = Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! (to - from + 1.0); |
| 46 | if (numberOfElements < 1) |
| 47 | return autoVECcxx . . $ autovector#autovector(49f6e7a06ebc5aa8). (); |
| 48 | autoVECcxx . . $ autoVEC# result = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (numberOfElements); |
| 49 | for (integercxx . . $ integer# i = 1; i <= numberOfElements; i ++) |
| 50 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = from + (double) (i - 1); |
| 51 | return resultcxx . . $ autovector#autovector(d33c649a3aceae2f).; |
| 52 | } |
| 53 | autoINTVECcxx . . $ autoINTVEC# from_to_INTVECcxx . . $ from_to_INTVEC(88a9f61b58bd0d55). (integercxx . . $ integer# from, integercxx . . $ integer# to) { |
| 54 | const integercxx . . $ integer# numberOfElements = to - from + 1; |
| 55 | if (numberOfElements < 1) |
| 56 | return autoINTVECcxx . . $ autovector#autovector(49f6e7a06ebc5aa8). (); |
| 57 | autoINTVECcxx . . $ autoINTVEC# result = raw_INTVECcxx . . $ raw_INTVEC(dab5d3ef28d6a25). (numberOfElements); |
| 58 | for (integercxx . . $ integer# i = 1; i <= numberOfElements; i ++) |
| 59 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = from + (i - 1); |
| 60 | return resultcxx . . $ autovector#autovector(d33c649a3aceae2f).; |
| 61 | } |
| 62 | |
| 63 | autoVECcxx . . $ autoVEC# from_to_by_VECcxx . . $ from_to_by_VEC(c9230c0f16871aa6). (double from, double to, double by) { |
| 64 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (by != 0.0, |
| 65 | U"from_to_by#: cannot have a step (“by”) of zero."); |
| 66 | /* |
| 67 | The following algorithm works for both positive and negative `by`. |
| 68 | */ |
| 69 | const integercxx . . $ integer# numberOfElements = Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! ((to - from) / by + 1.0); |
| 70 | if (numberOfElements < 1) |
| 71 | return autoVECcxx . . $ autovector#autovector(49f6e7a06ebc5aa8). (); |
| 72 | autoVECcxx . . $ autoVEC# result = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (numberOfElements); |
| 73 | for (integercxx . . $ integer# i = 1; i <= numberOfElements; i ++) |
| 74 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = from + (double) (i - 1) * by; |
| 75 | return resultcxx . . $ autovector#autovector(d33c649a3aceae2f).; |
| 76 | } |
| 77 | autoINTVECcxx . . $ autoINTVEC# from_to_by_INTVECcxx . . $ from_to_by_INTVEC(26d8fd33408a476b). (integercxx . . $ integer# from, integercxx . . $ integer# to, integercxx . . $ integer# by) { |
| 78 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (by != 0, |
| 79 | U"from_to_by#: cannot have a step (“by”) of zero."); |
| 80 | /* |
| 81 | The following algorithm works for both positive and negative `by`. |
| 82 | */ |
| 83 | const integercxx . . $ integer# numberOfElements = (to - from) / by + 1; |
| 84 | if (numberOfElements < 1) |
| 85 | return autoINTVECcxx . . $ autovector#autovector(49f6e7a06ebc5aa8). (); |
| 86 | autoINTVECcxx . . $ autoINTVEC# result = raw_INTVECcxx . . $ raw_INTVEC(dab5d3ef28d6a25). (numberOfElements); |
| 87 | for (integercxx . . $ integer# i = 1; i <= numberOfElements; i ++) |
| 88 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = from + (i - 1) * by; |
| 89 | return resultcxx . . $ autovector#autovector(d33c649a3aceae2f).; |
| 90 | } |
| 91 | /*@praat |
| 92 | assert from_to_count# (0, 10, 5) = { 0, 2.5, 5, 7.5, 10 } |
| 93 | @*/ |
| 94 | autoVECcxx . . $ autoVEC# from_to_count_VECcxx . . $ from_to_count_VEC(628d1e52f0365a5a). (double from, double to, integercxx . . $ integer# count) { |
| 95 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (count >= 2, |
| 96 | U"from_to_count#: cannot have fewer than two elements."); |
| 97 | autoVECcxx . . $ autoVEC# result = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (count); |
| 98 | const double by = (to - from) / (count - 1); |
| 99 | for (integercxx . . $ integer# i = 1; i < count; i ++) |
| 100 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = from + (double) (i - 1) * by; |
| 101 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).count] = to; |
| 102 | return resultcxx . . $ autovector#autovector(d33c649a3aceae2f).; |
| 103 | } |
| 104 | autoINTVECcxx . . $ autoINTVEC# from_to_count_INTVECcxx . . $ from_to_count_INTVEC(26d8fd33408a476b). (integercxx . . $ integer# from, integercxx . . $ integer# to, integercxx . . $ integer# count) { |
| 105 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (count >= 2, |
| 106 | U"from_to_count#: cannot have fewer than two elements."); |
| 107 | autoINTVECcxx . . $ autoINTVEC# result = raw_INTVECcxx . . $ raw_INTVEC(dab5d3ef28d6a25). (count); |
| 108 | const integercxx . . $ integer# by = (to - from) / (count - 1); |
| 109 | for (integercxx . . $ integer# i = 1; i < count; i ++) |
| 110 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = from + (i - 1) * by; |
| 111 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).count] = to; |
| 112 | return resultcxx . . $ autovector#autovector(d33c649a3aceae2f).; |
| 113 | } |
| 114 | |
| 115 | autoVECcxx . . $ autoVEC# between_by_VECcxx . . $ between_by_VEC(c9230c0f16871aa6). (double from, double to, double by) { |
| 116 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (by != 0.0, |
| 117 | U"between_by#: cannot have a step (“by”) of zero."); |
| 118 | /* |
| 119 | The following algorithm works for both positive and negative `by`. |
| 120 | */ |
| 121 | const integercxx . . $ integer# numberOfElements = Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! ((to - from) / by + 1.0); |
| 122 | if (numberOfElements < 1) |
| 123 | return autoVECcxx . . $ autovector#autovector(49f6e7a06ebc5aa8). (); |
| 124 | const double spaceNeeded = (numberOfElements - 1) * by; |
| 125 | const double spaceOnEdges = (to - from) - spaceNeeded; |
| 126 | const double first = from + 0.5 * spaceOnEdges; |
| 127 | autoVECcxx . . $ autoVEC# result = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (numberOfElements); |
| 128 | for (integercxx . . $ integer# i = 1; i <= numberOfElements; i ++) |
| 129 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = first + (double) (i - 1) * by; |
| 130 | return resultcxx . . $ autovector#autovector(d33c649a3aceae2f).; |
| 131 | } |
| 132 | |
| 133 | /*@praat |
| 134 | assert between_count# (0, 10, 5) = { 1, 3, 5, 7, 9 } |
| 135 | @*/ |
| 136 | autoVECcxx . . $ autoVEC# between_count_VECcxx . . $ between_count_VEC(628d1e52f0365a5a). (double from, double to, integercxx . . $ integer# count) { |
| 137 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (count >= 0, |
| 138 | U"between_count#: cannot have fewer than zero elements."); |
| 139 | if (count < 1) |
| 140 | return autoVECcxx . . $ autovector#autovector(49f6e7a06ebc5aa8). (); |
| 141 | const double by = (to - from) / count; |
| 142 | autoVECcxx . . $ autoVEC# result = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (count); |
| 143 | for (integercxx . . $ integer# i = 1; i <= count; i ++) |
| 144 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = from + (double) (i - 0.5) * by; |
| 145 | return resultcxx . . $ autovector#autovector(d33c649a3aceae2f).; |
| 146 | } |
| 147 | |
| 148 | void mul_VEC_outcxx . . $ mul_VEC_out(2bf483c07f98b4df). (VECVUcxx . . $ VECVU# const& target, constVECVUcxx . . $ constVECVU# const& vec, constMATVUcxx . . $ constMATVU# const& mat) { |
| 149 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mat.nrow == vec.size); |
| 150 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (target.size == mat.ncol); |
| 151 | if ((true)) { |
| 152 | for (integercxx . . $ integer# icol = 1; icol <= mat.ncolcxx . . $ constmatrixview#ncol.; icol ++) { |
| 153 | target [cxx . . $ vectorview#`operator[]`(8a4599b8835d1ce1).icol] = 0.0; |
| 154 | for (integercxx . . $ integer# irow = 1; irow <= mat.nrowcxx . . $ constmatrixview#nrow.; irow ++) |
| 155 | target [cxx . . $ vectorview#`operator[]`(8a4599b8835d1ce1).icol] += vec [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).irow] * mat [cxx . . $ constmatrixview#`operator[]`(7a6174ed67b49158).irow] [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).icol]; |
| 156 | } |
| 157 | } else if ((false)) { |
| 158 | for (integercxx . . $ integer# icol = 1; icol <= mat.ncolcxx . . $ constmatrixview#ncol.; icol ++) { |
| 159 | PAIRWISE_SUMcxx . . $ `melder/PAIRWISE_SUM.h:406:9`! (longdouble, sum, integer, vec.size, |
| 160 | const double *px = & vec [1]; |
| 161 | const double *py = & mat [1] [icol], |
| 162 | (longdouble) *px * (longdouble) *py, |
| 163 | (px += vec.stride, py += mat.rowStride) // this goes way beyond the confines of mat |
| 164 | ) |
| 165 | target [cxx . . $ vectorview#`operator[]`(8a4599b8835d1ce1).icol] = double (sum); |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | autoVECcxx . . $ autoVEC# mul_VECcxx . . $ mul_VEC(b377616a3b7e3ea0). (constVECVUcxx . . $ constVECVU# const& vec, constMATVUcxx . . $ constMATVU# const& mat) { |
| 171 | autoVECcxx . . $ autoVEC# result = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (mat.ncolcxx . . $ constmatrixview#ncol.); |
| 172 | mul_VEC_outcxx . . $ mul_VEC_out(2bf483c07f98b4df). (resultcxx . . $ vectorview#vectorview(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).(), vec, mat); |
| 173 | return resultcxx . . $ autovector#autovector(d33c649a3aceae2f).; |
| 174 | } |
| 175 | |
| 176 | void mul_VEC_outcxx . . $ mul_VEC_out(82b3fcbc7daf2365). (VECVUcxx . . $ VECVU# const& target, constMATVUcxx . . $ constMATVU# const& mat, constVECVUcxx . . $ constVECVU# const& vec) { |
| 177 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (vec.size == mat.ncol); |
| 178 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (target.size == mat.nrow); |
| 179 | for (integercxx . . $ integer# i = 1; i <= mat.nrowcxx . . $ constmatrixview#nrow.; i ++) { |
| 180 | if ((false)) { |
| 181 | target [cxx . . $ vectorview#`operator[]`(8a4599b8835d1ce1).i] = 0.0; |
| 182 | for (integercxx . . $ integer# j = 1; j <= vec.sizecxx . . $ constvectorview#size.; j ++) |
| 183 | target [cxx . . $ vectorview#`operator[]`(8a4599b8835d1ce1).i] += mat [cxx . . $ constmatrixview#`operator[]`(7a6174ed67b49158).i] [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).j] * vec [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).j]; |
| 184 | } else { |
| 185 | target [cxx . . $ vectorview#`operator[]`(8a4599b8835d1ce1).i] = NUMinnercxx . . $ NUMinner(5e5adb47f563a3e3). (mat.rowcxx . . $ constmatrixview#row(7a6174ed67b49158). (i), vec); |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | autoVECcxx . . $ autoVEC# mul_VECcxx . . $ mul_VEC(9a5f078c2b4f07dc). (constMATVUcxx . . $ constMATVU# const& mat, constVECVUcxx . . $ constVECVU# const& vec) { |
| 191 | autoVECcxx . . $ autoVEC# result = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (mat.nrowcxx . . $ constmatrixview#nrow.); |
| 192 | mul_VEC_outcxx . . $ mul_VEC_out(82b3fcbc7daf2365). (result.allcxx . . $ autovector#all(a26726dad87555bb).(), mat, vec); |
| 193 | return resultcxx . . $ autovector#autovector(d33c649a3aceae2f).; |
| 194 | } |
| 195 | |
| 196 | void power_VEC_outcxx . . $ power_VEC_out(adc2d003ad97e5e1). (VECVUcxx . . $ VECVU# const& target, constVECVUcxx . . $ constVECVU# const& vec, double power) { |
| 197 | if (power == 2.0) { |
| 198 | for (integercxx . . $ integer# i = 1; i <= target.sizecxx . . $ vectorview#size.; i ++) |
| 199 | target [cxx . . $ vectorview#`operator[]`(8a4599b8835d1ce1).i] = vec [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).i] * vec [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).i]; |
| 200 | } else if (power < 0.0) { |
| 201 | if (power == -1.0) { |
| 202 | for (integercxx . . $ integer# i = 1; i <= target.sizecxx . . $ vectorview#size.; i ++) { |
| 203 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (vec [i] != 0.0, |
| 204 | U"Cannot raise zero to a negative power."); |
| 205 | target [cxx . . $ vectorview#`operator[]`(8a4599b8835d1ce1).i] = 1.0 / vec [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).i]; |
| 206 | } |
| 207 | } else if (power == -2.0) { |
| 208 | for (integercxx . . $ integer# i = 1; i <= target.sizecxx . . $ vectorview#size.; i ++) { |
| 209 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (vec [i] != 0.0, |
| 210 | U"Cannot raise zero to a negative power."); |
| 211 | target [cxx . . $ vectorview#`operator[]`(8a4599b8835d1ce1).i] = 1.0 / (vec [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).i] * vec [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).i]); |
| 212 | } |
| 213 | } else { |
| 214 | for (integercxx . . $ integer# i = 1; i <= target.sizecxx . . $ vectorview#size.; i ++) { |
| 215 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (vec [i] != 0.0, |
| 216 | U"Cannot raise zero to a negative power."); |
| 217 | target [cxx . . $ vectorview#`operator[]`(8a4599b8835d1ce1).i] = powcxx . . $ pow(b71928d39fde4295). (vec [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).i], power); |
| 218 | } |
| 219 | } |
| 220 | } else { |
| 221 | for (integercxx . . $ integer# i = 1; i <= target.sizecxx . . $ vectorview#size.; i ++) |
| 222 | target [cxx . . $ vectorview#`operator[]`(8a4599b8835d1ce1).i] = powcxx . . $ pow(b71928d39fde4295). (vec [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).i], power); |
| 223 | } |
| 224 | } |
| 225 | void power_VEC_inoutcxx . . $ power_VEC_inout(cb3d2a9455fe8b3e). (VECVUcxx . . $ VECVU# const& vec, double power) { |
| 226 | power_VEC_outcxx . . $ power_VEC_out(adc2d003ad97e5e1). (vec, veccxx . . $ constvectorview#constvectorview(5c6f246bf1d99401)., power); |
| 227 | } |
| 228 | |
| 229 | autoVECcxx . . $ autoVEC# splitByWhitespace_VECcxx . . $ splitByWhitespace_VEC(be643ff064625b8d). (conststring32cxx . . $ conststring32# string) { |
| 230 | if (! string) |
| 231 | return autoVECcxx . . $ autovector#autovector(49f6e7a06ebc5aa8).(); // accept null pointer input |
| 232 | const integercxx . . $ integer# n = NUMnumberOfTokenscxx . . $ NUMnumberOfTokens(3fae411214b133ad). (string); |
| 233 | if (n == 0) |
| 234 | return autoVECcxx . . $ autovector#autovector(49f6e7a06ebc5aa8).(); |
| 235 | autoVECcxx . . $ autoVEC# resultcxx . . $ autovector#autovector(d91e89fbd57cd1). (n, MelderArraycxx . . $ MelderArray/::kInitializationTypecxx . . $ MelderArray/kInitializationType#::ZEROcxx . . $ MelderArray/kInitializationType#ZERO.); |
| 236 | |
| 237 | integercxx . . $ integer# itoken = 0; |
| 238 | const char32cxx . . $ char32# *p = & string [0]; |
| 239 | for (;;) { |
| 240 | Melder_skipHorizontalOrVerticalSpacecxx . . $ Melder_skipHorizontalOrVerticalSpace(1babf4dbe7380927). (& p); |
| 241 | if (*p == U'\0') |
| 242 | break; |
| 243 | const char32cxx . . $ char32# *beginOfInk = p; |
| 244 | p ++; // step over first nonspace |
| 245 | p = Melder_findEndOfInkcxx . . $ Melder_findEndOfInk(5553299aa8c4fee9). (p); |
| 246 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).++ itoken] = Melder_atofcxx . . $ Melder_atof(13d725aae188c0cd). (beginOfInk); |
| 247 | } |
| 248 | return resultcxx . . $ autovector#autovector(d33c649a3aceae2f).; |
| 249 | } |
| 250 | |
| 251 | /* |
| 252 | Acceptable ranges e.g. "1 4 2 3:7 4:3 3:5:2" --> |
| 253 | 1, 4, 2, 3, 4, 5, 6, 7, 4, 3, 3, 4, 5, 4, 3, 2 |
| 254 | Overlap is allowed. Ranges can go up and down. |
| 255 | */ |
| 256 | autoINTVECcxx . . $ autoINTVEC# splitByWhitespaceWithRanges_INTVECcxx . . $ splitByWhitespaceWithRanges_INTVEC(40f9f82be0ce91de). (conststring32cxx . . $ conststring32# ranges) { |
| 257 | autoINTVECcxx . . $ autoINTVEC# elements = raw_INTVECcxx . . $ raw_INTVEC(dab5d3ef28d6a25). (0); |
| 258 | integercxx . . $ integer# previousElement = 0; |
| 259 | const char32cxx . . $ char32# *p = & ranges [0]; |
| 260 | for (;;) { |
| 261 | while (Melder_isHorizontalSpacecxx . . $ Melder_isHorizontalSpace(b8d0204ce8416907). (*p)) |
| 262 | p ++; |
| 263 | if (*p == U'\0') |
| 264 | break; |
| 265 | if (Melder_isAsciiDecimalNumbercxx . . $ Melder_isAsciiDecimalNumber(b8d0204ce8416907). (*p) || *p == '-' && Melder_isAsciiDecimalNumbercxx . . $ Melder_isAsciiDecimalNumber(b8d0204ce8416907). (p [1])) { |
| 266 | const integercxx . . $ integer# currentElement = Melder_atoicxx . . $ Melder_atoi(c94c67ff4219bf83). (p); |
| 267 | * elements.appendcxx . . $ autovector#append(155dc7f103cdb9db).() = currentElement; |
| 268 | previousElement = currentElement; |
| 269 | do { |
| 270 | p ++; |
| 271 | } while (Melder_isAsciiDecimalNumbercxx . . $ Melder_isAsciiDecimalNumber(b8d0204ce8416907). (*p)); |
| 272 | } else if (*p == U':') { |
| 273 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (previousElement != 0, |
| 274 | U"The range should not start with a colon."); |
| 275 | do { |
| 276 | p ++; |
| 277 | } while (Melder_isHorizontalSpacecxx . . $ Melder_isHorizontalSpace(b8d0204ce8416907). (*p)); |
| 278 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (*p != U'\0', |
| 279 | U"The range should not end with a colon."); |
| 280 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (Melder_isAsciiDecimalNumber (*p) || *p == '-' && Melder_isAsciiDecimalNumber (p [1]), |
| 281 | U"End of range should be a whole number."); |
| 282 | const integercxx . . $ integer# currentElement = Melder_atoicxx . . $ Melder_atoi(c94c67ff4219bf83). (p); |
| 283 | if (currentElement > previousElement) |
| 284 | for (integercxx . . $ integer# ielement = previousElement + 1; ielement <= currentElement; ielement ++) |
| 285 | * elements.appendcxx . . $ autovector#append(155dc7f103cdb9db).() = ielement; |
| 286 | else |
| 287 | for (integercxx . . $ integer# ielement = previousElement - 1; ielement >= currentElement; ielement --) |
| 288 | * elements.appendcxx . . $ autovector#append(155dc7f103cdb9db).() = ielement; |
| 289 | previousElement = currentElement; |
| 290 | do { |
| 291 | p ++; |
| 292 | } while (Melder_isAsciiDecimalNumbercxx . . $ Melder_isAsciiDecimalNumber(b8d0204ce8416907). (*p)); |
| 293 | } else { |
| 294 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Start of range should be a whole number."); |
| 295 | } |
| 296 | } |
| 297 | return elementscxx . . $ autovector#autovector(d33c649a3aceae2f).; |
| 298 | } |
| 299 | |
| 300 | autoVECcxx . . $ autoVEC# cast_VECcxx . . $ cast_VEC(f68cd76b4341e935). (constINTVECcxx . . $ constINTVEC# const& intvec) { |
| 301 | autoVECcxx . . $ autoVEC# result = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (intvec.sizecxx . . $ constvector#size.); |
| 302 | for (integercxx . . $ integer# i = 1; i <= intvec.sizecxx . . $ constvector#size.; i ++) |
| 303 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = intvec [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i]; |
| 304 | return resultcxx . . $ autovector#autovector(d33c649a3aceae2f).; |
| 305 | } |
| 306 | |
| 307 | autoINTVECcxx . . $ autoINTVEC# ifloor_INTVECcxx . . $ ifloor_INTVEC(8e12c8178b2404dc). (constVECcxx . . $ constVEC# const& vec) { |
| 308 | autoINTVECcxx . . $ autoINTVEC# result = raw_INTVECcxx . . $ raw_INTVEC(dab5d3ef28d6a25). (vec.sizecxx . . $ constvector#size.); |
| 309 | for (integercxx . . $ integer# i = 1; i <= vec.sizecxx . . $ constvector#size.; i ++) |
| 310 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! (vec [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i]); |
| 311 | return resultcxx . . $ autovector#autovector(d33c649a3aceae2f).; |
| 312 | } |
| 313 | |
| 314 | autoINTVECcxx . . $ autoINTVEC# iround_INTVECcxx . . $ iround_INTVEC(8e12c8178b2404dc). (constVECcxx . . $ constVEC# const& vec) { |
| 315 | autoINTVECcxx . . $ autoINTVEC# result = raw_INTVECcxx . . $ raw_INTVEC(dab5d3ef28d6a25). (vec.sizecxx . . $ constvector#size.); |
| 316 | for (integercxx . . $ integer# i = 1; i <= vec.sizecxx . . $ constvector#size.; i ++) |
| 317 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = Melder_iroundcxx . . $ `melder/melder_ftoi.h:78:9`! (vec [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i]); |
| 318 | return resultcxx . . $ autovector#autovector(d33c649a3aceae2f).; |
| 319 | } |
| 320 | |
| 321 | autoINTVECcxx . . $ autoINTVEC# iceiling_INTVECcxx . . $ iceiling_INTVEC(8e12c8178b2404dc). (constVECcxx . . $ constVEC# const& vec) { |
| 322 | autoINTVECcxx . . $ autoINTVEC# result = raw_INTVECcxx . . $ raw_INTVEC(dab5d3ef28d6a25). (vec.sizecxx . . $ constvector#size.); |
| 323 | for (integercxx . . $ integer# i = 1; i <= vec.sizecxx . . $ constvector#size.; i ++) |
| 324 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = Melder_iceilingcxx . . $ `melder/melder_ftoi.h:45:9`! (vec [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i]); |
| 325 | return resultcxx . . $ autovector#autovector(d33c649a3aceae2f).; |
| 326 | } |
| 327 | |
| 328 | void to_INTVEC_outcxx . . $ to_INTVEC_out(6ad8d2059d77987c). (INTVECVUcxx . . $ INTVECVU# const& x) noexcept { |
| 329 | for (integercxx . . $ integer# i = 1; i <= x.sizecxx . . $ vectorview#size.; i ++) |
| 330 | x [cxx . . $ vectorview#`operator[]`(8a4599b8835d1ce1).i] = i; |
| 331 | } |
| 332 | |
| 333 | autoVECcxx . . $ autoVEC# to_VECcxx . . $ to_VEC(5c642365c0b1e00d). (double to) { |
| 334 | const integercxx . . $ integer# numberOfElements = Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! (to); |
| 335 | autoVECcxx . . $ autoVEC# result = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (numberOfElements); |
| 336 | for (integercxx . . $ integer# i = 1; i <= numberOfElements; i ++) |
| 337 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = (double) i; |
| 338 | return resultcxx . . $ autovector#autovector(d33c649a3aceae2f).; |
| 339 | } |
| 340 | autoINTVECcxx . . $ autoINTVEC# to_INTVECcxx . . $ to_INTVEC(dab5d3ef28d6a25). (integercxx . . $ integer# to) { |
| 341 | const integercxx . . $ integer# numberOfElements = to; |
| 342 | autoINTVECcxx . . $ autoINTVEC# result = raw_INTVECcxx . . $ raw_INTVEC(dab5d3ef28d6a25). (numberOfElements); |
| 343 | for (integercxx . . $ integer# i = 1; i <= numberOfElements; i ++) |
| 344 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = i; |
| 345 | return resultcxx . . $ autovector#autovector(d33c649a3aceae2f).; |
| 346 | } |
| 347 | |
| 348 | extern autoVECcxx . . $ autoVEC# blake3_VECcxx . . $ blake3_VEC(81359d2d5440d947). (constMATVUcxx . . $ constMATVU# const& mat) { |
| 349 | blake3_hasher hasher; |
| 350 | blake3_hasher_init (& hasher); |
| 351 | for (integercxx . . $ integer# irow = 1; irow <= mat.nrowcxx . . $ constmatrixview#nrow.; irow ++) |
| 352 | for (integercxx . . $ integer# icol = 1; icol <= mat.ncolcxx . . $ constmatrixview#ncol.; icol ++) { |
| 353 | const double value_float = mat [cxx . . $ constmatrixview#`operator[]`(7a6174ed67b49158).irow] [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).icol]; |
| 354 | const uint64cxx . . $ uint64# value_int = * (uint64cxx . . $ uint64# *) & value_float; |
| 355 | uint8cxx . . $ uint8# bytes [8]; |
| 356 | bytes [0] = (uint8cxx . . $ uint8#) (value_int >> 0); // little-endian |
| 357 | bytes [1] = (uint8cxx . . $ uint8#) (value_int >> 8); // little-endian |
| 358 | bytes [2] = (uint8cxx . . $ uint8#) (value_int >> 16); // little-endian |
| 359 | bytes [3] = (uint8cxx . . $ uint8#) (value_int >> 24); // little-endian |
| 360 | bytes [4] = (uint8cxx . . $ uint8#) (value_int >> 32); // little-endian |
| 361 | bytes [5] = (uint8cxx . . $ uint8#) (value_int >> 40); // little-endian |
| 362 | bytes [6] = (uint8cxx . . $ uint8#) (value_int >> 48); // little-endian |
| 363 | bytes [7] = (uint8cxx . . $ uint8#) (value_int >> 56); // little-endian |
| 364 | blake3_hasher_update (& hasher, bytes, 8); |
| 365 | } |
| 366 | uint8cxx . . $ uint8# output [32]; |
| 367 | blake3_hasher_finalize (& hasher, output, 32); // 256 bits |
| 368 | autoVECcxx . . $ autoVEC# result = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (8); |
| 369 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] = ((uint32cxx . . $ uint32#) output [0] << 0) | ((uint32cxx . . $ uint32#) output [1] << 8) |
| 370 | | ((uint32cxx . . $ uint32#) output [2] << 16) | ((uint32cxx . . $ uint32#) output [3] << 24); |
| 371 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).2] = ((uint32cxx . . $ uint32#) output [4] << 0) | ((uint32cxx . . $ uint32#) output [5] << 8) |
| 372 | | ((uint32cxx . . $ uint32#) output [6] << 16) | ((uint32cxx . . $ uint32#) output [7] << 24); |
| 373 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).3] = ((uint32cxx . . $ uint32#) output [8] << 0) | ((uint32cxx . . $ uint32#) output [9] << 8) |
| 374 | | ((uint32cxx . . $ uint32#) output [10] << 16) | ((uint32cxx . . $ uint32#) output [11] << 24); |
| 375 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).4] = ((uint32cxx . . $ uint32#) output [12] << 0) | ((uint32cxx . . $ uint32#) output [13] << 8) |
| 376 | | ((uint32cxx . . $ uint32#) output [14] << 16) | ((uint32cxx . . $ uint32#) output [15] << 24); |
| 377 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).5] = ((uint32cxx . . $ uint32#) output [16] << 0) | ((uint32cxx . . $ uint32#) output [17] << 8) |
| 378 | | ((uint32cxx . . $ uint32#) output [18] << 16) | ((uint32cxx . . $ uint32#) output [19] << 24); |
| 379 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).6] = ((uint32cxx . . $ uint32#) output [20] << 0) | ((uint32cxx . . $ uint32#) output [21] << 8) |
| 380 | | ((uint32cxx . . $ uint32#) output [22] << 16) | ((uint32cxx . . $ uint32#) output [23] << 24); |
| 381 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).7] = ((uint32cxx . . $ uint32#) output [24] << 0) | ((uint32cxx . . $ uint32#) output [25] << 8) |
| 382 | | ((uint32cxx . . $ uint32#) output [26] << 16) | ((uint32cxx . . $ uint32#) output [27] << 24); |
| 383 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).8] = ((uint32cxx . . $ uint32#) output [28] << 0) | ((uint32cxx . . $ uint32#) output [29] << 8) |
| 384 | | ((uint32cxx . . $ uint32#) output [30] << 16) | ((uint32cxx . . $ uint32#) output [31] << 24); |
| 385 | return resultcxx . . $ autovector#autovector(d33c649a3aceae2f).; |
| 386 | } |
| 387 | |
| 388 | /* End of file VEC.cpp */ |