21 #define td_set_data(td,v,dtype) do { \
28 #define td_get_data(td,v,dtype) do { \
29 *((dtype *) v) = (td)->data._
35 #define td_typecast_to(td,itype,otype) do { \
36 itype in_val = (td)->data._
37 otype out_val = (otype) in_val; \
41 #ifdef FLOAT16_SUPPORT
42 #define td_typecast_to_fromf16(td,otype) do { \
43 float16 in_val = (td)->data._float16; \
44 otype out_val = (otype) in_val; \
48 #define td_typecast_to_fromf16(td,itype) do { \
49 nns_loge ("Your nnstreamer binary is built without -DFLOAT16_SUPPORT option; thus float16 is not supported.\n"); \
54 #define td_typecast(td,otype) do { \
55 switch ((td)->type) { \
56 case _NNS_INT32: td_typecast_to (td, int32_t, otype); break; \
57 case _NNS_UINT32: td_typecast_to (td, uint32_t, otype); break; \
58 case _NNS_INT16: td_typecast_to (td, int16_t, otype); break; \
59 case _NNS_UINT16: td_typecast_to (td, uint16_t, otype); break; \
60 case _NNS_INT8: td_typecast_to (td, int8_t, otype); break; \
61 case _NNS_UINT8: td_typecast_to (td, uint8_t, otype); break; \
62 case _NNS_FLOAT64: td_typecast_to (td, double, otype); break; \
63 case _NNS_FLOAT32: td_typecast_to (td, float, otype); break; \
64 case _NNS_FLOAT16: td_typecast_to_fromf16 (td, otype); break; \
65 case _NNS_INT64: td_typecast_to (td, int64_t, otype); break; \
66 case _NNS_UINT64: td_typecast_to (td, uint64_t, otype); break; \
67 default: g_assert (0); break; \
81 g_return_val_if_fail (td != NULL,
FALSE);
82 g_return_val_if_fail (value != NULL,
FALSE);
113 #ifdef FLOAT16_SUPPORT
118 (
"NNStreamer requires -DFLOAT16_SUPPORT as a build option to enable float16 type. This binary does not have float16 feature enabled; thus, float16 type is not supported in this instance.\n");
145 g_return_val_if_fail (td != NULL,
FALSE);
146 g_return_val_if_fail (value != NULL,
FALSE);
174 #ifdef FLOAT16_SUPPORT
179 (
"NNStreamer requires -DFLOAT16_SUPPORT as a build option to enable float16 type. This binary does not have float16 feature enabled; thus, float16 type is not supported in this instance.\n");
207 g_return_val_if_fail (td != NULL,
FALSE);
252 #ifdef FLOAT16_SUPPORT
256 (
"NNStreamer requires -DFLOAT16_SUPPORT as a build option to enable float16 type. This binary does not have float16 feature enabled; thus, float16 type is not supported in this instance.\n");
295 g_return_val_if_fail (input != NULL,
FALSE);
296 g_return_val_if_fail (output != NULL,
FALSE);
318 gdouble value, average;
323 g_return_val_if_fail (raw != NULL,
FALSE);
324 g_return_val_if_fail (length > 0,
FALSE);
328 num = length / element_size;
331 *
result = (gdouble *) g_try_malloc0 (
sizeof (gdouble));
333 nns_loge (
"Failed to allocate memory for calculating average");
337 for (i = 0; i < num; ++i) {
339 data = (guint8 *) raw + element_size * i;
342 average = (value - average) / (i + 1) + average;
363 gdouble value, average;
364 gulong ch, i, num, offset;
368 g_return_val_if_fail (raw != NULL,
FALSE);
369 g_return_val_if_fail (length > 0,
FALSE);
370 g_return_val_if_fail (dim[0] > 0,
FALSE);
374 num = length / element_size;
378 *results = (gdouble *) g_try_malloc0 (
sizeof (gdouble) * offset);
379 if (*results == NULL) {
380 nns_loge (
"Failed to allocate memory for calculating average");
384 for (ch = 0; ch < offset; ++ch) {
386 for (i = 0; i < num; ++i) {
388 data = (guint8 *) raw + element_size * ((i * offset) + ch);
390 average = (value - average) / (i + 1) + average;
393 (*results)[ch] = average;
410 gdouble * average, gdouble **
result)
417 g_return_val_if_fail (raw != NULL,
FALSE);
418 g_return_val_if_fail (length > 0,
FALSE);
422 num = length / element_size;
423 *
result = (gdouble *) g_try_malloc0 (
sizeof (gdouble));
425 nns_loge (
"Failed to allocate memory for calculating standard deviation");
430 for (i = 0; i < num; ++i) {
432 data = (guint8 *) raw + element_size * i;
435 std += pow (value - *average, 2) / num;
438 std = (std != 0.0) ? sqrt (std) : (1e-10);
459 gulong ch, i, num, offset;
463 g_return_val_if_fail (raw != NULL,
FALSE);
464 g_return_val_if_fail (length > 0,
FALSE);
465 g_return_val_if_fail (dim[0] > 0,
FALSE);
469 num = length / element_size;
473 *results = (gdouble *) g_try_malloc0 (
sizeof (gdouble) * offset);
474 if (*results == NULL) {
475 nns_loge (
"Failed to allocate memory for calculating standard deviation");
479 for (ch = 0; ch < offset; ++ch) {
481 for (i = 0; i < num; ++i) {
483 data = (guint8 *) raw + element_size * ((i * offset) + ch);
485 std += pow (value - averages[ch], 2) / num;
488 std = (std != 0.0) ? sqrt (std) : (1e-10);
489 (*results)[ch] = std;