}
/**
+ * @brief Copy tensor info
+ * @note GstTensorInfo::name should be freed with g_free()
+ */
+void
+gst_tensor_info_copy (GstTensorInfo * dest, const GstTensorInfo * src)
+{
+ guint i;
+
+ g_return_if_fail (dest != NULL);
+ g_return_if_fail (src != NULL);
+
+ dest->name = (src->name) ? g_strdup (src->name) : NULL;
+ dest->type = src->type;
+
+ for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) {
+ dest->dimension[i] = src->dimension[i];
+ }
+}
+
+/**
* @brief Get data size of single tensor
* @param info tensor info structure
* @return data size
}
/**
+ * @brief Copy tensor info
+ * @note GstTensorInfo::name should be freed with g_free()
+ */
+void
+gst_tensors_info_copy (GstTensorsInfo * dest, const GstTensorsInfo * src)
+{
+ guint i;
+
+ g_return_if_fail (dest != NULL);
+ g_return_if_fail (src != NULL);
+
+ dest->num_tensors = src->num_tensors;
+
+ for (i = 0; i < src->num_tensors; i++) {
+ gst_tensor_info_copy (&dest->info[i], &src->info[i]);
+ }
+}
+
+/**
* @brief Parse the string of dimensions
* @param info tensors info structure
* @param dim_string string of dimensions
gst_tensor_info_is_equal (const GstTensorInfo * i1, const GstTensorInfo * i2);
/**
+ * @brief Copy tensor info
+ * @note GstTensorInfo::name should be freed with g_free()
+ */
+extern void
+gst_tensor_info_copy (GstTensorInfo * dest, const GstTensorInfo * src);
+
+/**
* @brief Get data size of single tensor
* @param info tensor info structure
* @return data size
gst_tensors_info_is_equal (const GstTensorsInfo * i1, const GstTensorsInfo * i2);
/**
+ * @brief Copy tensor info
+ * @note GstTensorInfo::name should be freed with g_free()
+ */
+extern void
+gst_tensors_info_copy (GstTensorsInfo * dest, const GstTensorsInfo * src);
+
+/**
* @brief Parse the string of dimensions
* @param info tensors info structure
* @param dim_string string of dimensions
pt_data *data = (pt_data *) malloc (sizeof (pt_data));
int i;
+ assert (data);
+ memset (data, 0, sizeof (pt_data));
+
data->id = 0;
data->counter = 0;
data->info[0].dimension[0] = TSIZE;
GstTensorsInfo * info)
{
pt_data *data = private_data;
- int i;
assert (data);
assert (NNS_TENSOR_RANK_LIMIT >= 3);
info->num_tensors = 3;
- for (i = 0; i < info->num_tensors; ++i) {
- memcpy (info->info[i].dimension, data->info[i].dimension,
- sizeof (tensor_dim));
- info->info[i].type = data->info[i].type;
- }
+ /** @todo use common function to copy tensor info */
+ info->info[0] = data->info[0];
+ info->info[1] = data->info[1];
+ info->info[2] = data->info[2];
return 0;
}
GstTensorsInfo * info)
{
pt_data *data = private_data;
- int i;
assert (data);
assert (NNS_TENSOR_RANK_LIMIT >= 3);
info->num_tensors = 2;
- for (i = 0; i < info->num_tensors; ++i) {
- memcpy (info->info[i].dimension, data->info[i].dimension,
- sizeof (tensor_dim));
- info->info[i].type = data->info[i].type;
- }
+ /** @todo use common function to copy tensor info */
+ info->info[0] = data->info[0];
+ info->info[1] = data->info[1];
return 0;
}
pt_data *data = (pt_data *) malloc (sizeof (pt_data));
int i;
+ assert (data);
+ memset (data, 0, sizeof (pt_data));
+
data->id = 0;
data->counter = 0;
data->info[0].dimension[0] = TSIZE;
GstTensorsInfo * info)
{
pt_data *data = private_data;
- int i;
assert (data);
assert (NNS_TENSOR_RANK_LIMIT >= 3);
info->num_tensors = 2;
- for (i = 0; i < info->num_tensors; ++i) {
- memcpy (info->info[i].dimension, data->info[i].dimension,
- sizeof (tensor_dim));
- info->info[i].type = data->info[i].type;
- }
+ /** @todo use common function to copy tensor info */
+ info->info[0] = data->info[0];
+ info->info[1] = data->info[1];
return 0;
}
GstTensorsInfo * info)
{
pt_data *data = private_data;
- int i;
assert (data);
assert (NNS_TENSOR_RANK_LIMIT >= 3);
info->num_tensors = 1;
- for (i = 0; i < info->num_tensors; ++i) {
- memcpy (info->info[i].dimension, data->info[i].dimension,
- sizeof (tensor_dim));
- info->info[i].type = data->info[i].type;
- }
+ /** @todo use common function to copy tensor info */
+ info->info[0] = data->info[0];
return 0;
}
pt_data *data = (pt_data *) malloc (sizeof (pt_data));
int i;
+ assert (data);
+ memset (data, 0, sizeof (pt_data));
+
data->id = 0;
data->info.dimension[0] = D1;
data->info.dimension[1] = D2;
assert (NNS_TENSOR_RANK_LIMIT >= 3);
info->num_tensors = 1;
- memcpy (info->info[0].dimension, data->info.dimension, sizeof (tensor_dim));
- info->info[0].type = data->info.type;
+ /** @todo use common function to copy tensor info */
+ info->info[0] = data->info;
return 0;
}
assert (NNS_TENSOR_RANK_LIMIT >= 3);
info->num_tensors = 1;
- memcpy (info->info[0].dimension, data->info.dimension, sizeof (tensor_dim));
- info->info[0].type = data->info.type;
+ /** @todo use common function to copy tensor info */
+ info->info[0] = data->info;
return 0;
}
}
/**
+ * @brief Test to copy tensor info.
+ */
+TEST (common_tensor_info, copy_tensor)
+{
+ GstTensorInfo src, dest;
+ gchar *test_name = g_strdup ("test-tensor");
+
+ gst_tensor_info_init (&src);
+ gst_tensor_info_init (&dest);
+
+ src = { test_name, _NNS_FLOAT32, { 1, 2, 3, 4 } };
+ gst_tensor_info_copy (&dest, &src);
+
+ EXPECT_TRUE (dest.name != src.name);
+ EXPECT_TRUE (g_str_equal (dest.name, test_name));
+ EXPECT_EQ (dest.type, src.type);
+ EXPECT_EQ (dest.dimension[0], src.dimension[0]);
+ EXPECT_EQ (dest.dimension[1], src.dimension[1]);
+ EXPECT_EQ (dest.dimension[2], src.dimension[2]);
+ EXPECT_EQ (dest.dimension[3], src.dimension[3]);
+
+ src = { NULL, _NNS_INT32, { 5, 6, 7, 8 } };
+ gst_tensor_info_copy (&dest, &src);
+
+ EXPECT_TRUE (dest.name == NULL);
+ EXPECT_EQ (dest.type, src.type);
+ EXPECT_EQ (dest.dimension[0], src.dimension[0]);
+ EXPECT_EQ (dest.dimension[1], src.dimension[1]);
+ EXPECT_EQ (dest.dimension[2], src.dimension[2]);
+ EXPECT_EQ (dest.dimension[3], src.dimension[3]);
+
+ g_free (test_name);
+}
+
+/**
+ * @brief Test to copy tensor info.
+ */
+TEST (common_tensor_info, copy_tensors)
+{
+ GstTensorsInfo src, dest;
+ gchar *test_name = g_strdup ("test-tensors");
+ guint i;
+
+ gst_tensors_info_init (&src);
+ gst_tensors_info_init (&dest);
+
+ src.num_tensors = 2;
+ src.info[0] = { test_name, _NNS_INT32, { 1, 2, 3, 4 } };
+ src.info[1] = { test_name, _NNS_FLOAT32, { 5, 6, 7, 8 } };
+ gst_tensors_info_copy (&dest, &src);
+
+ EXPECT_EQ (dest.num_tensors, src.num_tensors);
+
+ for (i = 0; i < src.num_tensors; i++) {
+ EXPECT_TRUE (dest.info[i].name != src.info[i].name);
+ EXPECT_TRUE (g_str_equal (dest.info[i].name, test_name));
+ EXPECT_EQ (dest.info[i].type, src.info[i].type);
+ EXPECT_EQ (dest.info[i].dimension[0], src.info[i].dimension[0]);
+ EXPECT_EQ (dest.info[i].dimension[1], src.info[i].dimension[1]);
+ EXPECT_EQ (dest.info[i].dimension[2], src.info[i].dimension[2]);
+ EXPECT_EQ (dest.info[i].dimension[3], src.info[i].dimension[3]);
+ }
+
+ g_free (test_name);
+}
+
+/**
* @brief Test for dimensions string in tensors info.
*/
TEST (common_tensors_info_string, dimensions)