Doxygen Book
tensor_data.c File Reference

Internal functions to handle various tensor type and value. More...

#include <math.h>
#include "tensor_data.h"
#include "nnstreamer_log.h"
#include "nnstreamer_plugin_api.h"
Include dependency graph for tensor_data.c:

Go to the source code of this file.

Macros

#define td_set_data(td, v, dtype)
 Macro to set data in struct. More...
 
#define td_get_data(td, v, dtype)
 
#define td_typecast_to(td, itype, otype)
 
#define td_typecast_to_fromf16(td, itype)
 
#define td_typecast(td, otype)
 

Functions

 while (0)
 dtype = *((dtype *) v); \ More...
 
gboolean gst_tensor_data_get (tensor_data_s *td, gpointer value)
 Get tensor element value. More...
 
gboolean gst_tensor_data_typecast (tensor_data_s *td, tensor_type type)
 Typecast tensor element data. More...
 
gboolean gst_tensor_data_raw_typecast (gpointer input, tensor_type in_type, gpointer output, tensor_type out_type)
 Typecast tensor element value. More...
 
gboolean gst_tensor_data_raw_average (gpointer raw, gsize length, tensor_type type, gdouble **result)
 Calculate average value of the tensor. More...
 
gboolean gst_tensor_data_raw_average_per_channel (gpointer raw, gsize length, tensor_type type, tensor_dim dim, gdouble **results)
 Calculate average value of the tensor per channel (the first dim). More...
 
gboolean gst_tensor_data_raw_std (gpointer raw, gsize length, tensor_type type, gdouble *average, gdouble **result)
 Calculate standard deviation of the tensor. More...
 
gboolean gst_tensor_data_raw_std_per_channel (gpointer raw, gsize length, tensor_type type, tensor_dim dim, gdouble *averages, gdouble **results)
 Calculate standard deviation of the tensor per channel (the first dim). More...
 

Detailed Description

Internal functions to handle various tensor type and value.

Copyright (c) 2021 Samsung Electronics Co., Ltd. All Rights Reserved.

Date
10 Mar 2021
See also
http://github.com/nnstreamer/nnstreamer
Author
Jaeyun Jung jy121.nosp@m.0.ju.nosp@m.ng@sa.nosp@m.msun.nosp@m.g.com
Bug:
No known bugs except for NYI items

Definition in file tensor_data.c.

Macro Definition Documentation

◆ td_get_data

#define td_get_data (   td,
  v,
  dtype 
)
Value:
do { \
*((dtype *) v) = (td)->data._

◆ td_set_data

#define td_set_data (   td,
  v,
  dtype 
)
Value:
do { \
(td)->data._

Macro to set data in struct.

Definition at line 21 of file tensor_data.c.

◆ td_typecast

#define td_typecast (   td,
  otype 
)
Value:
do { \
switch ((td)->type) { \
case _NNS_INT32: td_typecast_to (td, int32_t, otype); break; \
case _NNS_UINT32: td_typecast_to (td, uint32_t, otype); break; \
case _NNS_INT16: td_typecast_to (td, int16_t, otype); break; \
case _NNS_UINT16: td_typecast_to (td, uint16_t, otype); break; \
case _NNS_INT8: td_typecast_to (td, int8_t, otype); break; \
case _NNS_UINT8: td_typecast_to (td, uint8_t, otype); break; \
case _NNS_FLOAT64: td_typecast_to (td, double, otype); break; \
case _NNS_FLOAT32: td_typecast_to (td, float, otype); break; \
case _NNS_FLOAT16: td_typecast_to_fromf16 (td, otype); break; \
case _NNS_INT64: td_typecast_to (td, int64_t, otype); break; \
case _NNS_UINT64: td_typecast_to (td, uint64_t, otype); break; \
default: g_assert (0); break; \
} \
} while (0)

◆ td_typecast_to

#define td_typecast_to (   td,
  itype,
  otype 
)
Value:
do { \
itype in_val = (td)->data._

◆ td_typecast_to_fromf16

#define td_typecast_to_fromf16 (   td,
  itype 
)
Value:
do { \
nns_loge ("Your nnstreamer binary is built without -DFLOAT16_SUPPORT option; thus float16 is not supported.\n"); \
g_assert (0); \
} while (0)

Function Documentation

◆ gst_tensor_data_get()

gboolean gst_tensor_data_get ( tensor_data_s td,
gpointer  value 
)

Get tensor element value.

Parameters
tdstruct for tensor data
valuepointer of tensor element value
Returns
TRUE if no error

Definition at line 143 of file tensor_data.c.

Here is the caller graph for this function:

◆ gst_tensor_data_raw_average()

gboolean gst_tensor_data_raw_average ( gpointer  raw,
gsize  length,
tensor_type  type,
gdouble **  result 
)

Calculate average value of the tensor.

Parameters
rawpointer of raw tensor data
lengthbyte size of raw tensor data
typetensor type
resultdouble pointer for average value of given tensor. Caller should release allocated memory.
Returns
TRUE if no error

Definition at line 315 of file tensor_data.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_data_raw_average_per_channel()

gboolean gst_tensor_data_raw_average_per_channel ( gpointer  raw,
gsize  length,
tensor_type  type,
tensor_dim  dim,
gdouble **  results 
)

Calculate average value of the tensor per channel (the first dim).

Parameters
rawpointer of raw tensor data
lengthbyte size of raw tensor data
typetensor type
tensor_dimtensor dimension
resultsdouble array contains average values of each channel. Caller should release allocated array.
Returns
TRUE if no error

Definition at line 360 of file tensor_data.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_data_raw_std()

gboolean gst_tensor_data_raw_std ( gpointer  raw,
gsize  length,
tensor_type  type,
gdouble *  average,
gdouble **  result 
)

Calculate standard deviation of the tensor.

Parameters
rawpointer of raw tensor data
lengthbyte size of raw tensor data
typetensor type
averageaverage value of given tensor
resultdouble pointer for standard deviation of given tensor. Caller should release allocated memory.
Returns
TRUE if no error

Definition at line 409 of file tensor_data.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_data_raw_std_per_channel()

gboolean gst_tensor_data_raw_std_per_channel ( gpointer  raw,
gsize  length,
tensor_type  type,
tensor_dim  dim,
gdouble *  averages,
gdouble **  results 
)

Calculate standard deviation of the tensor per channel (the first dim).

Parameters
rawpointer of raw tensor data
lengthbyte size of raw tensor data
typetensor type
tensor_dimtensor dimension
averagesaverage values of given tensor per-channel
resultsdouble array contains standard deviation of each channel. Caller should release allocated array.
Returns
TRUE if no error

Definition at line 455 of file tensor_data.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_data_raw_typecast()

gboolean gst_tensor_data_raw_typecast ( gpointer  input,
tensor_type  in_type,
gpointer  output,
tensor_type  out_type 
)

Typecast tensor element value.

Parameters
inputpointer of input tensor data
in_typeinput tensor type
outputpointer of output tensor data
out_typeoutput tensor type
Returns
TRUE if no error

Definition at line 290 of file tensor_data.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_tensor_data_typecast()

gboolean gst_tensor_data_typecast ( tensor_data_s td,
tensor_type  type 
)

Typecast tensor element data.

Parameters
tdstruct for tensor data
typetensor type to be transformed
Returns
TRUE if no error

Definition at line 203 of file tensor_data.c.

Here is the caller graph for this function:

◆ while()

while ( )

dtype = *((dtype *) v); \

Definition at line 23 of file tensor_data.c.

g_assert
g_assert(sizeof(DTYPE_UNSIGNED)==sizeof(DTYPE_SIGNED))
td_typecast_to_fromf16
#define td_typecast_to_fromf16(td, itype)
_NNS_UINT64
@ _NNS_UINT64
Definition: tensor_typedef.h:149
data
svtc_1 data
Definition: gsttensor_if.c:844
_NNS_INT64
@ _NNS_INT64
Definition: tensor_typedef.h:148
td_typecast_to
#define td_typecast_to(td, itype, otype)
_NNS_FLOAT16
@ _NNS_FLOAT16
Definition: tensor_typedef.h:150
_NNS_UINT16
@ _NNS_UINT16
Definition: tensor_typedef.h:143
_NNS_FLOAT32
@ _NNS_FLOAT32
Definition: tensor_typedef.h:147
_NNS_INT32
@ _NNS_INT32
Definition: tensor_typedef.h:140
_NNS_INT16
@ _NNS_INT16
Definition: tensor_typedef.h:142
_NNS_FLOAT64
@ _NNS_FLOAT64
Definition: tensor_typedef.h:146
_NNS_UINT32
@ _NNS_UINT32
Definition: tensor_typedef.h:141
_NNS_INT8
@ _NNS_INT8
Definition: tensor_typedef.h:144
_NNS_UINT8
@ _NNS_UINT8
Definition: tensor_typedef.h:145
type
svtc_1 type
Definition: gsttensor_if.c:843