Debian Codegraph @

lib/aggregators.c

raw symbols SCIP
1 /*
2 Copyright(C) 2020-2023 Sutou Kouhei <[email protected]>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "grn_db.h"cxx . . $ `<file>/lib/grn_db.h`/
20 #include "grn_aggregators.h"cxx . . $ `<file>/lib/grn_aggregators.h`/
21 #include "grn_bulk.h"cxx . . $ `<file>/lib/grn_bulk.h`/
22
23 #include <math.h>
24
25 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
26 numeric_aggregator_validate_targetcxx . . $ numeric_aggregator_validate_target(9e798f95a6c8217f).(grn_ctxcxx . . $ grn_ctx# *ctx,
27 grn_objcxx . . $ grn_obj# *target,
28 const char *tag)
29 {
30 if (grn_obj_is_number_family_scalar_columncxx . . $ grn_obj_is_number_family_scalar_column(a5760e5c319a06ee).(ctx, target)) {
31 return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
32 }
33
34 if (grn_obj_is_number_family_scalar_accessorcxx . . $ grn_obj_is_number_family_scalar_accessor(a5760e5c319a06ee).(ctx, target)) {
35 return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
36 }
37
38 grn_objcxx . . $ grn_obj# inspected;
39 GRN_TEXT_INITcxx . . $ `include/groonga/groonga.h:2750:9`!(&inspected, 0);
40 grn_inspect_limitedcxx . . $ grn_inspect_limited(88456f97fe0d41a).(ctx, &inspected, target);
41 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx,
42 GRN_INVALID_ARGUMENT,
43 "%s target must be numeric column: %.*s",
44 tag,
45 (int)GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(&inspected),
46 GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(&inspected));
47 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &inspected);
48 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
49 }
50
51 static void *
52 aggregator_sum_initcxx . . $ aggregator_sum_init(f5a333b9354b90e2).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_aggregator_datacxx . . $ grn_aggregator_data# *data)
53 {
54 const char *tag = "[aggregator][sum]";
55 grn_objcxx . . $ grn_obj# *args = grn_aggregator_data_get_argscxx . . $ grn_aggregator_data_get_args(d3ab768526586abf).(ctx, data);
56 size_t n_args = GRN_PTR_VECTOR_SIZEcxx . . $ `include/groonga/groonga.h:3265:9`!(args);
57 if (n_args != 1) {
58 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx,
59 GRN_INVALID_ARGUMENT,
60 "%s wrong number of arguments "
61 "(%" GRN_FMT_SIZEcxx . . $ `lib/grn.h:408:11`! " for 1)",
62 tag,
63 n_args);
64 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
65 }
66
67 grn_objcxx . . $ grn_obj# *target = GRN_PTR_VALUE_ATcxx . . $ `include/groonga/groonga.h:3150:9`!(args, 0);
68 if (!numeric_aggregator_validate_targetcxx . . $ numeric_aggregator_validate_target(9e798f95a6c8217f).(ctx, target, tag)) {
69 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
70 }
71
72 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
73 }
74
75 static grn_rccxx . . $ grn_rc#
76 aggregator_sum_updatecxx . . $ aggregator_sum_update(affc993b9be15484).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_aggregator_datacxx . . $ grn_aggregator_data# *data)
77 {
78 grn_objcxx . . $ grn_obj# *args = grn_aggregator_data_get_argscxx . . $ grn_aggregator_data_get_args(d3ab768526586abf).(ctx, data);
79 grn_objcxx . . $ grn_obj# *target = GRN_PTR_VALUE_ATcxx . . $ `include/groonga/groonga.h:3150:9`!(args, 0);
80 grn_objcxx . . $ grn_obj# current_value;
81 GRN_VOID_INITcxx . . $ `include/groonga/groonga.h:2749:9`!(&current_value);
82 grn_idcxx . . $ grn_id# source_id = grn_aggregator_data_get_source_idcxx . . $ grn_aggregator_data_get_source_id(4451b3d90d500a3d).(ctx, data);
83 grn_obj_get_valuecxx . . $ grn_obj_get_value(6e06fec66698a6a).(ctx, target, source_id, &current_value);
84
85 grn_objcxx . . $ grn_obj# *output_column = grn_aggregator_data_get_output_columncxx . . $ grn_aggregator_data_get_output_column(d3ab768526586abf).(ctx, data);
86 grn_idcxx . . $ grn_id# group_id = grn_aggregator_data_get_group_idcxx . . $ grn_aggregator_data_get_group_id(4451b3d90d500a3d).(ctx, data);
87 grn_obj_set_valuecxx . . $ grn_obj_set_value(16170250441fe8eb).(ctx, output_column, group_id, &current_value, GRN_OBJ_INCRcxx . . $ `include/groonga/groonga.h:1470:9`!);
88 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &current_value);
89
90 return ctx->rccxx . . $ _grn_ctx#rc.;
91 }
92
93 typedef structcxx . . $ $anonymous_type_9023fb391af8be51_0# {
94 uint32_tcxx . . $ uint32_t# n_valuescxx . . $ $anonymous_type_9023fb391af8be51_0#n_values.;
95 double meancxx . . $ $anonymous_type_9023fb391af8be51_0#mean.;
96 } aggregator_mean_valuecxx . . $ aggregator_mean_value#;
97
98 typedef structcxx . . $ $anonymous_type_9023fb391af8be51_1# {
99 grn_hashcxx . . $ grn_hash# *valuescxx . . $ $anonymous_type_9023fb391af8be51_1#values.;
100 } aggregator_mean_datacxx . . $ aggregator_mean_data#;
101
102 static void *
103 aggregator_mean_initcxx . . $ aggregator_mean_init(f5a333b9354b90e2).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_aggregator_datacxx . . $ grn_aggregator_data# *data)
104 {
105 const char *tag = "[aggregator][mean]";
106 grn_objcxx . . $ grn_obj# *args = grn_aggregator_data_get_argscxx . . $ grn_aggregator_data_get_args(d3ab768526586abf).(ctx, data);
107 size_t n_args = GRN_PTR_VECTOR_SIZEcxx . . $ `include/groonga/groonga.h:3265:9`!(args);
108 if (n_args != 1) {
109 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx,
110 GRN_INVALID_ARGUMENT,
111 "%s wrong number of arguments "
112 "(%" GRN_FMT_SIZEcxx . . $ `lib/grn.h:408:11`! " for 1)",
113 tag,
114 n_args);
115 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
116 }
117
118 grn_objcxx . . $ grn_obj# *target = GRN_PTR_VALUE_ATcxx . . $ `include/groonga/groonga.h:3150:9`!(args, 0);
119 if (!numeric_aggregator_validate_targetcxx . . $ numeric_aggregator_validate_target(9e798f95a6c8217f).(ctx, target, tag)) {
120 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
121 }
122
123 aggregator_mean_datacxx . . $ aggregator_mean_data# *mean_data = GRN_CALLOCcxx . . $ `lib/grn_alloc.h:42:9`!(sizeof(aggregator_mean_data));
124 if (!mean_data) {
125 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx,
126 GRN_NO_MEMORY_AVAILABLE,
127 "%s failed to allocate: %s",
128 tag,
129 ctx->errbuf);
130 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
131 }
132
133 mean_data->valuescxx . . $ $anonymous_type_9023fb391af8be51_1#values. = grn_hash_createcxx . . $ grn_hash_create(db1bba7e0d64660).(ctx,
134 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!,
135 sizeof(grn_idcxx . . $ grn_id#),
136 sizeof(aggregator_mean_valuecxx . . $ aggregator_mean_value#),
137 GRN_OBJ_TABLE_HASH_KEYcxx . . $ `include/groonga/groonga.h:688:9`!);
138 if (!mean_data->valuescxx . . $ $anonymous_type_9023fb391af8be51_1#values.) {
139 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx,
140 GRN_NO_MEMORY_AVAILABLE,
141 "%s failed to create hash table: %s",
142 tag,
143 ctx->errbuf);
144 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(mean_data);
145 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
146 }
147
148 return mean_data;
149 }
150
151 static grn_rccxx . . $ grn_rc#
152 aggregator_mean_updatecxx . . $ aggregator_mean_update(affc993b9be15484).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_aggregator_datacxx . . $ grn_aggregator_data# *data)
153 {
154 const char *tag = "[aggregator][mean]";
155 aggregator_mean_datacxx . . $ aggregator_mean_data# *mean_data =
156 grn_aggregator_data_get_user_datacxx . . $ grn_aggregator_data_get_user_data(f5a333b9354b90e2).(ctx, data);
157 grn_idcxx . . $ grn_id# group_id = grn_aggregator_data_get_group_idcxx . . $ grn_aggregator_data_get_group_id(4451b3d90d500a3d).(ctx, data);
158 void *value;
159 int added;
160 grn_idcxx . . $ grn_id# value_id = grn_hash_addcxx . . $ grn_hash_add(251a256fc515235e).(ctx,
161 mean_data->valuescxx . . $ $anonymous_type_9023fb391af8be51_1#values.,
162 &group_id,
163 sizeof(grn_idcxx . . $ grn_id#),
164 &value,
165 &added);
166 if (value_id == GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!) {
167 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx,
168 GRN_INVALID_ARGUMENT,
169 "%s failed to add ID: <%u>: %s",
170 tag,
171 group_id,
172 ctx->errbuf);
173 return ctx->rccxx . . $ _grn_ctx#rc.;
174 }
175
176 aggregator_mean_valuecxx . . $ aggregator_mean_value# *mean_value = value;
177 if (added) {
178 mean_value->n_valuescxx . . $ $anonymous_type_9023fb391af8be51_0#n_values. = 0;
179 mean_value->meancxx . . $ $anonymous_type_9023fb391af8be51_0#mean. = 0.0;
180 }
181
182 grn_objcxx . . $ grn_obj# *args = grn_aggregator_data_get_argscxx . . $ grn_aggregator_data_get_args(d3ab768526586abf).(ctx, data);
183 grn_objcxx . . $ grn_obj# *target = GRN_PTR_VALUE_ATcxx . . $ `include/groonga/groonga.h:3150:9`!(args, 0);
184 grn_objcxx . . $ grn_obj# current_value;
185 GRN_VOID_INITcxx . . $ `include/groonga/groonga.h:2749:9`!(&current_value);
186 grn_idcxx . . $ grn_id# source_id = grn_aggregator_data_get_source_idcxx . . $ grn_aggregator_data_get_source_id(4451b3d90d500a3d).(ctx, data);
187 grn_obj_get_valuecxx . . $ grn_obj_get_value(6e06fec66698a6a).(ctx, target, source_id, &current_value);
188 double current_value_float = grn_bulk_get_floatcxx . . $ grn_bulk_get_float(7f87a4555b184b5c).(ctx, &current_value);
189 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &current_value);
190
191 mean_value->n_valuescxx . . $ $anonymous_type_9023fb391af8be51_0#n_values.++;
192 mean_value->meancxx . . $ $anonymous_type_9023fb391af8be51_0#mean. +=
193 (current_value_float - mean_value->meancxx . . $ $anonymous_type_9023fb391af8be51_0#mean.) / mean_value->n_valuescxx . . $ $anonymous_type_9023fb391af8be51_0#n_values.;
194
195 return ctx->rccxx . . $ _grn_ctx#rc.;
196 }
197
198 static grn_rccxx . . $ grn_rc#
199 aggregator_mean_fincxx . . $ aggregator_mean_fin(affc993b9be15484).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_aggregator_datacxx . . $ grn_aggregator_data# *data)
200 {
201 aggregator_mean_datacxx . . $ aggregator_mean_data# *mean_data =
202 grn_aggregator_data_get_user_datacxx . . $ grn_aggregator_data_get_user_data(f5a333b9354b90e2).(ctx, data);
203
204 grn_objcxx . . $ grn_obj# *output_column = grn_aggregator_data_get_output_columncxx . . $ grn_aggregator_data_get_output_column(d3ab768526586abf).(ctx, data);
205 grn_objcxx . . $ grn_obj# mean_float;
206 GRN_FLOAT_INITcxx . . $ `include/groonga/groonga.h:2864:9`!(&mean_float, 0);
207 GRN_HASH_EACH_BEGINcxx . . $ `include/groonga/hash.h:141:9`!(ctx, mean_data->values, cursor, id)
208 {
209 void *key;
210 unsigned int key_size;
211 void *value;
212 grn_hash_cursor_get_key_valuecxx . . $ grn_hash_cursor_get_key_value(c02614ac44805bc8).(ctx, cursor, &key, &key_size, &value);
213 grn_idcxx . . $ grn_id# group_id = *((grn_idcxx . . $ grn_id# *)key);
214 aggregator_mean_valuecxx . . $ aggregator_mean_value# *mean_value = value;
215 GRN_FLOAT_SETcxx . . $ `include/groonga/groonga.h:2934:9`!(ctx, &mean_float, mean_value->mean);
216 grn_obj_set_valuecxx . . $ grn_obj_set_value(16170250441fe8eb).(ctx, output_column, group_id, &mean_float, GRN_OBJ_SETcxx . . $ `include/groonga/groonga.h:1466:9`!);
217 }
218 GRN_HASH_EACH_ENDcxx . . $ `include/groonga/hash.h:159:9`!(ctx, cursor);
219 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &mean_float);
220
221 grn_hash_closecxx . . $ grn_hash_close(c005d027d163fb0b).(ctx, mean_data->valuescxx . . $ $anonymous_type_9023fb391af8be51_1#values.);
222 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(mean_data);
223
224 return ctx->rccxx . . $ _grn_ctx#rc.;
225 }
226
227 typedef structcxx . . $ $anonymous_type_9023fb391af8be51_2# {
228 uint32_tcxx . . $ uint32_t# n_valuescxx . . $ $anonymous_type_9023fb391af8be51_2#n_values.;
229 double meancxx . . $ $anonymous_type_9023fb391af8be51_2#mean.;
230 double m2cxx . . $ $anonymous_type_9023fb391af8be51_2#m2.;
231 } aggregator_sd_valuecxx . . $ aggregator_sd_value#;
232
233 typedef structcxx . . $ $anonymous_type_9023fb391af8be51_3# {
234 grn_hashcxx . . $ grn_hash# *valuescxx . . $ $anonymous_type_9023fb391af8be51_3#values.;
235 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! unbiasedcxx . . $ $anonymous_type_9023fb391af8be51_3#unbiased.;
236 } aggregator_sd_datacxx . . $ aggregator_sd_data#;
237
238 static void *
239 aggregator_sd_initcxx . . $ aggregator_sd_init(f5a333b9354b90e2).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_aggregator_datacxx . . $ grn_aggregator_data# *data)
240 {
241 const char *tag = "[aggregator][sd]";
242 grn_objcxx . . $ grn_obj# *args = grn_aggregator_data_get_argscxx . . $ grn_aggregator_data_get_args(d3ab768526586abf).(ctx, data);
243 size_t n_args = GRN_PTR_VECTOR_SIZEcxx . . $ `include/groonga/groonga.h:3265:9`!(args);
244 if (!(1 <= n_args && n_args <= 2)) {
245 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx,
246 GRN_INVALID_ARGUMENT,
247 "%s wrong number of arguments "
248 "(%" GRN_FMT_SIZEcxx . . $ `lib/grn.h:408:11`! " for 1..2)",
249 tag,
250 n_args);
251 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
252 }
253
254 grn_objcxx . . $ grn_obj# *target = GRN_PTR_VALUE_ATcxx . . $ `include/groonga/groonga.h:3150:9`!(args, 0);
255 if (!numeric_aggregator_validate_targetcxx . . $ numeric_aggregator_validate_target(9e798f95a6c8217f).(ctx, target, tag)) {
256 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
257 }
258
259 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! unbiased = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
260 if (n_args >= 2) {
261 grn_objcxx . . $ grn_obj# *options = GRN_PTR_VALUE_ATcxx . . $ `include/groonga/groonga.h:3150:9`!(args, 1);
262 grn_rccxx . . $ grn_rc# rc = grn_proc_options_parsecxx . . $ grn_proc_options_parse(b3b87877968531ef).(ctx,
263 options,
264 tag,
265 "unbiased",
266 GRN_PROC_OPTION_VALUE_BOOLcxx . . $ GRN_PROC_OPTION_VALUE_BOOL.,
267 &unbiased,
268 falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!);
269 if (rc != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
270 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
271 }
272 }
273
274 aggregator_sd_datacxx . . $ aggregator_sd_data# *sd_data = GRN_CALLOCcxx . . $ `lib/grn_alloc.h:42:9`!(sizeof(aggregator_sd_data));
275 if (!sd_data) {
276 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx,
277 GRN_NO_MEMORY_AVAILABLE,
278 "%s failed to allocate: %s",
279 tag,
280 ctx->errbuf);
281 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
282 }
283
284 sd_data->valuescxx . . $ $anonymous_type_9023fb391af8be51_3#values. = grn_hash_createcxx . . $ grn_hash_create(db1bba7e0d64660).(ctx,
285 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!,
286 sizeof(grn_idcxx . . $ grn_id#),
287 sizeof(aggregator_sd_valuecxx . . $ aggregator_sd_value#),
288 GRN_OBJ_TABLE_HASH_KEYcxx . . $ `include/groonga/groonga.h:688:9`!);
289 if (!sd_data->valuescxx . . $ $anonymous_type_9023fb391af8be51_3#values.) {
290 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx,
291 GRN_NO_MEMORY_AVAILABLE,
292 "%s failed to create hash table: %s",
293 tag,
294 ctx->errbuf);
295 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(sd_data);
296 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
297 }
298 sd_data->unbiasedcxx . . $ $anonymous_type_9023fb391af8be51_3#unbiased. = unbiased;
299
300 return sd_data;
301 }
302
303 static grn_rccxx . . $ grn_rc#
304 aggregator_sd_updatecxx . . $ aggregator_sd_update(affc993b9be15484).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_aggregator_datacxx . . $ grn_aggregator_data# *data)
305 {
306 const char *tag = "[aggregator][sd]";
307 aggregator_sd_datacxx . . $ aggregator_sd_data# *sd_data = grn_aggregator_data_get_user_datacxx . . $ grn_aggregator_data_get_user_data(f5a333b9354b90e2).(ctx, data);
308 grn_idcxx . . $ grn_id# group_id = grn_aggregator_data_get_group_idcxx . . $ grn_aggregator_data_get_group_id(4451b3d90d500a3d).(ctx, data);
309 void *value;
310 int added;
311 grn_idcxx . . $ grn_id# value_id = grn_hash_addcxx . . $ grn_hash_add(251a256fc515235e).(ctx,
312 sd_data->valuescxx . . $ $anonymous_type_9023fb391af8be51_3#values.,
313 &group_id,
314 sizeof(grn_idcxx . . $ grn_id#),
315 &value,
316 &added);
317 if (value_id == GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!) {
318 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx,
319 GRN_INVALID_ARGUMENT,
320 "%s failed to add ID: <%u>: %s",
321 tag,
322 group_id,
323 ctx->errbuf);
324 return ctx->rccxx . . $ _grn_ctx#rc.;
325 }
326
327 aggregator_sd_valuecxx . . $ aggregator_sd_value# *sd_value = value;
328 if (added) {
329 sd_value->n_valuescxx . . $ $anonymous_type_9023fb391af8be51_2#n_values. = 0;
330 sd_value->meancxx . . $ $anonymous_type_9023fb391af8be51_2#mean. = 0.0;
331 sd_value->m2cxx . . $ $anonymous_type_9023fb391af8be51_2#m2. = 0.0;
332 }
333
334 grn_objcxx . . $ grn_obj# *args = grn_aggregator_data_get_argscxx . . $ grn_aggregator_data_get_args(d3ab768526586abf).(ctx, data);
335 grn_objcxx . . $ grn_obj# *target = GRN_PTR_VALUE_ATcxx . . $ `include/groonga/groonga.h:3150:9`!(args, 0);
336 grn_objcxx . . $ grn_obj# current_value;
337 GRN_VOID_INITcxx . . $ `include/groonga/groonga.h:2749:9`!(&current_value);
338 grn_idcxx . . $ grn_id# source_id = grn_aggregator_data_get_source_idcxx . . $ grn_aggregator_data_get_source_id(4451b3d90d500a3d).(ctx, data);
339 grn_obj_get_valuecxx . . $ grn_obj_get_value(6e06fec66698a6a).(ctx, target, source_id, &current_value);
340 double current_value_float = grn_bulk_get_floatcxx . . $ grn_bulk_get_float(7f87a4555b184b5c).(ctx, &current_value);
341 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &current_value);
342
343 const double mean_previous = sd_value->meancxx . . $ $anonymous_type_9023fb391af8be51_2#mean.;
344 const double m2_previous = sd_value->m2cxx . . $ $anonymous_type_9023fb391af8be51_2#m2.;
345 sd_value->n_valuescxx . . $ $anonymous_type_9023fb391af8be51_2#n_values.++;
346 sd_value->meancxx . . $ $anonymous_type_9023fb391af8be51_2#mean. += (current_value_float - mean_previous) / sd_value->n_valuescxx . . $ $anonymous_type_9023fb391af8be51_2#n_values.;
347 /* Welfold's online algorithm */
348 sd_value->m2cxx . . $ $anonymous_type_9023fb391af8be51_2#m2. = m2_previous + ((current_value_float - mean_previous) *
349 (current_value_float - sd_value->meancxx . . $ $anonymous_type_9023fb391af8be51_2#mean.));
350
351 return ctx->rccxx . . $ _grn_ctx#rc.;
352 }
353
354 static grn_rccxx . . $ grn_rc#
355 aggregator_sd_fincxx . . $ aggregator_sd_fin(affc993b9be15484).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_aggregator_datacxx . . $ grn_aggregator_data# *data)
356 {
357 aggregator_sd_datacxx . . $ aggregator_sd_data# *sd_data = grn_aggregator_data_get_user_datacxx . . $ grn_aggregator_data_get_user_data(f5a333b9354b90e2).(ctx, data);
358
359 grn_objcxx . . $ grn_obj# *output_column = grn_aggregator_data_get_output_columncxx . . $ grn_aggregator_data_get_output_column(d3ab768526586abf).(ctx, data);
360 grn_objcxx . . $ grn_obj# sd_float;
361 GRN_FLOAT_INITcxx . . $ `include/groonga/groonga.h:2864:9`!(&sd_float, 0);
362 GRN_HASH_EACH_BEGINcxx . . $ `include/groonga/hash.h:141:9`!(ctx, sd_data->values, cursor, id)
363 {
364 void *key;
365 unsigned int key_size;
366 void *value;
367 grn_hash_cursor_get_key_valuecxx . . $ grn_hash_cursor_get_key_value(c02614ac44805bc8).(ctx, cursor, &key, &key_size, &value);
368 grn_idcxx . . $ grn_id# group_id = *((grn_idcxx . . $ grn_id# *)key);
369 aggregator_sd_valuecxx . . $ aggregator_sd_value# *sd_value = value;
370 double sd;
371 if (sd_data->unbiasedcxx . . $ $anonymous_type_9023fb391af8be51_3#unbiased.) {
372 if (sd_value->n_valuescxx . . $ $anonymous_type_9023fb391af8be51_2#n_values. > 1) {
373 sd = sqrt(sd_value->m2cxx . . $ $anonymous_type_9023fb391af8be51_2#m2. / (sd_value->n_valuescxx . . $ $anonymous_type_9023fb391af8be51_2#n_values. - 1));
374 } else {
375 sd = NANcxx . . $ `<external>/11263917310783833665/math.h:102:12`!;
376 }
377 } else {
378 sd = sqrt(sd_value->m2cxx . . $ $anonymous_type_9023fb391af8be51_2#m2. / sd_value->n_valuescxx . . $ $anonymous_type_9023fb391af8be51_2#n_values.);
379 }
380 GRN_FLOAT_SETcxx . . $ `include/groonga/groonga.h:2934:9`!(ctx, &sd_float, sd);
381 grn_obj_set_valuecxx . . $ grn_obj_set_value(16170250441fe8eb).(ctx, output_column, group_id, &sd_float, GRN_OBJ_SETcxx . . $ `include/groonga/groonga.h:1466:9`!);
382 }
383 GRN_HASH_EACH_ENDcxx . . $ `include/groonga/hash.h:159:9`!(ctx, cursor);
384 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &sd_float);
385
386 grn_hash_closecxx . . $ grn_hash_close(c005d027d163fb0b).(ctx, sd_data->valuescxx . . $ $anonymous_type_9023fb391af8be51_3#values.);
387 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(sd_data);
388
389 return ctx->rccxx . . $ _grn_ctx#rc.;
390 }
391
392 grn_rccxx . . $ grn_rc#
393 grn_db_init_builtin_aggregatorscxx . . $ grn_db_init_builtin_aggregators(2b4fa601bf4f1e5b).(grn_ctxcxx . . $ grn_ctx# *ctx)
394 {
395 grn_aggregator_createcxx . . $ grn_aggregator_create(69e8a9db27d92518).(ctx,
396 "aggregator_sum",
397 -1,
398 aggregator_sum_initcxx . . $ aggregator_sum_init(f5a333b9354b90e2).,
399 aggregator_sum_updatecxx . . $ aggregator_sum_update(affc993b9be15484).,
400 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
401
402 grn_aggregator_createcxx . . $ grn_aggregator_create(69e8a9db27d92518).(ctx,
403 "aggregator_mean",
404 -1,
405 aggregator_mean_initcxx . . $ aggregator_mean_init(f5a333b9354b90e2).,
406 aggregator_mean_updatecxx . . $ aggregator_mean_update(affc993b9be15484).,
407 aggregator_mean_fincxx . . $ aggregator_mean_fin(affc993b9be15484).);
408
409 grn_aggregator_createcxx . . $ grn_aggregator_create(69e8a9db27d92518).(ctx,
410 "aggregator_sd",
411 -1,
412 aggregator_sd_initcxx . . $ aggregator_sd_init(f5a333b9354b90e2).,
413 aggregator_sd_updatecxx . . $ aggregator_sd_update(affc993b9be15484).,
414 aggregator_sd_fincxx . . $ aggregator_sd_fin(affc993b9be15484).);
415
416 return GRN_SUCCESScxx . . $ GRN_SUCCESS.;
417 }