tensor: Add helper function to stringify a tensor data type

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8523>
This commit is contained in:
Olivier Crête 2024-11-22 21:32:18 -05:00 committed by GStreamer Marge Bot
parent ba05421ab2
commit 5c188d90c0
3 changed files with 78 additions and 0 deletions

View File

@ -1385,6 +1385,20 @@ dimension is dynamic.</doc>
</parameter>
</parameters>
</method>
<function name="data_type_get_name" c:identifier="gst_tensor_data_type_get_name" version="1.28">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.c">Get a string version of the data type</doc>
<source-position filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h"/>
<return-value transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.c">a constant string with the name of the data type</doc>
<type name="utf8" c:type="const gchar*"/>
</return-value>
<parameters>
<parameter name="data_type" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.c">a #GstTensorDataType</doc>
<type name="TensorDataType" c:type="GstTensorDataType"/>
</parameter>
</parameters>
</function>
</record>
<enumeration name="TensorDataType" version="1.26" c:type="GstTensorDataType">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h">Describe the type of data contain in the tensor.</doc>
@ -1891,6 +1905,20 @@ metadata type.</doc>
<type name="MtdType" c:type="GstAnalyticsMtdType"/>
</return-value>
</function>
<function name="tensor_data_type_get_name" c:identifier="gst_tensor_data_type_get_name" moved-to="Tensor.data_type_get_name" version="1.28">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.c">Get a string version of the data type</doc>
<source-position filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.h"/>
<return-value transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.c">a constant string with the name of the data type</doc>
<type name="utf8" c:type="const gchar*"/>
</return-value>
<parameters>
<parameter name="data_type" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensor.c">a #GstTensorDataType</doc>
<type name="TensorDataType" c:type="GstTensorDataType"/>
</parameter>
</parameters>
</function>
<function name="tensor_meta_api_get_type" c:identifier="gst_tensor_meta_api_get_type" version="1.26" introspectable="0">
<source-position filename="../subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensormeta.h"/>
<return-value transfer-ownership="none">

View File

@ -209,3 +209,50 @@ gst_tensor_get_dims (GstTensor * tensor, gsize * num_dims)
*num_dims = tensor->num_dims;
return tensor->dims;
}
/**
* gst_tensor_data_type_get_name:
* @data_type: a #GstTensorDataType
*
* Get a string version of the data type
*
* Returns: a constant string with the name of the data type
*
* Since: 1.28
*/
const gchar *
gst_tensor_data_type_get_name (GstTensorDataType data_type)
{
switch (data_type) {
case GST_TENSOR_DATA_TYPE_INT4:
return "int4";
case GST_TENSOR_DATA_TYPE_INT8:
return "int8";
case GST_TENSOR_DATA_TYPE_INT16:
return "int16";
case GST_TENSOR_DATA_TYPE_INT32:
return "int32";
case GST_TENSOR_DATA_TYPE_INT64:
return "int64";
case GST_TENSOR_DATA_TYPE_UINT4:
return "uint4";
case GST_TENSOR_DATA_TYPE_UINT8:
return "uint8";
case GST_TENSOR_DATA_TYPE_UINT16:
return "uint16";
case GST_TENSOR_DATA_TYPE_UINT32:
return "uint32";
case GST_TENSOR_DATA_TYPE_UINT64:
return "uint64";
case GST_TENSOR_DATA_TYPE_FLOAT16:
return "float16";
case GST_TENSOR_DATA_TYPE_FLOAT32:
return "float32";
case GST_TENSOR_DATA_TYPE_FLOAT64:
return "float64";
case GST_TENSOR_DATA_TYPE_BFLOAT16:
return "bfloat16";
default:
return NULL;
}
}

View File

@ -149,6 +149,9 @@ gsize * gst_tensor_get_dims (GstTensor * tensor, gsize * num_dims);
GST_ANALYTICS_META_API
GType gst_tensor_get_type (void);
GST_ANALYTICS_META_API
const gchar *gst_tensor_data_type_get_name (GstTensorDataType data_type);
G_END_DECLS
#endif /* __GST_TENSOR_H__ */