* @param param The parameter string in the format of d1:d2:d3:d4, d1:d2:d3, d1:d2, or d1, where dN is a positive integer and d1 is the innermost dimension; i.e., dim[d4][d3][d2][d1];
*/
int
-get_tensor_dimension (const gchar * param, uint32_t dim[NNS_TENSOR_RANK_LIMIT])
+get_tensor_dimension (const gchar * param,
+ uint32_t dim[NNS_TENSOR_SIZE_LIMIT][NNS_TENSOR_RANK_LIMIT],
+ int rank[NNS_TENSOR_SIZE_LIMIT])
{
- gchar **strv = g_strsplit (param, ":", NNS_TENSOR_RANK_LIMIT);
- int i, retval = 0;
+ int i, j = 0;
guint64 val;
+ gchar **_strv = g_strsplit (param, ",./", -1);
+ gint num_tensor = g_strv_length (_strv);
- g_assert (strv != NULL);
+ for (i = 0; i < num_tensor; i++) {
+ gchar **strv = g_strsplit (_strv[i], ":", NNS_TENSOR_RANK_LIMIT);
- for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) {
- if (strv[i] == NULL)
- break;
- val = g_ascii_strtoull (strv[i], NULL, 10);
- dim[i] = val;
- retval = i + 1;
+ g_assert (strv != NULL);
+
+ for (j = 0; j < NNS_TENSOR_RANK_LIMIT; j++) {
+ if (strv[j] == NULL)
+ break;
+ val = g_ascii_strtoull (strv[j], NULL, 10);
+ dim[i][j] = val;
+ rank[i] = j + 1;
+ }
+ for (; j < NNS_TENSOR_RANK_LIMIT; j++)
+ dim[i][j] = 1;
+ g_strfreev (strv);
}
- for (; i < NNS_TENSOR_RANK_LIMIT; i++)
- dim[i] = 1;
- g_strfreev (strv);
- return retval;
+ g_strfreev (_strv);
+
+ return num_tensor;
}
/**
GstTensor_TensorsMeta * meta, int *framerate_num, int *framerate_denom)
{
int num = 0;
- int rank = 0;
+ int rank[NNS_TENSOR_SIZE_LIMIT];
const gchar *strval;
gint fn = 0, fd = 0;
gchar **strv;
meta->num_tensors = num;
- if (gst_structure_get_int (str, "rank", (int *) &rank)) {
- if (rank != NNS_TENSOR_RANK_LIMIT) {
+ strval = gst_structure_get_string (str, "rank");
+
+ strv = g_strsplit (strval, ",./", -1);
+ counter = 0;
+ while (strv[counter]) {
+ rank[counter] = g_ascii_strtod (strv[counter], NULL);
+ if (rank[counter] != NNS_TENSOR_RANK_LIMIT) {
err_print ("rank value of other/tensors incorrect.\n");
- rank = 0;
+ rank[counter] = 0;
+ return 0;
}
+ counter++;
}
- if (0 == rank)
- return 0;
+
+ g_strfreev (strv);
if (gst_structure_get_fraction (str, "framerate", &fn, &fd)) {
if (framerate_num)
}
strval = gst_structure_get_string (str, "dimensions");
- strv = g_strsplit (strval, ",", -1);
- counter = 0;
- while (strv[counter]) {
- int ret;
- if (counter >= num) {
- err_print
- ("The number of dimensions does not match the number of tensors.\n");
- return 0;
- }
- ret = get_tensor_dimension (ftrim (strv[counter]), meta->dims[counter]);
- if (ret > NNS_TENSOR_RANK_LIMIT || ret < 1)
- return 0;
- counter++;
- }
+ counter = get_tensor_dimension (strval, meta->dims, rank);
+
if (counter != num) {
err_print
("The number of dimensions does not match the number of tensors.\n");
return 0;
}
- g_strfreev (strv);
strval = gst_structure_get_string (str, "types");
strv = g_strsplit (strval, ",", -1);
g_assert (!(prop->inputConfigured & _TFC_DIMENSION) && value);
/* Once configures, it cannot be changed in runtime */
{
- int rank = get_tensor_dimension (g_value_get_string (value),
- prop->inputDimension[0]);
- g_assert (rank > 0 && rank <= NNS_TENSOR_RANK_LIMIT);
+ int i;
+ prop->inputTensorSize =
+ get_tensor_dimension (g_value_get_string (value),
+ prop->inputDimension, prop->inputTensorRank);
+ for (i = 0; i < prop->inputTensorSize; i++) {
+ g_assert (prop->inputTensorRank[i] > 0
+ && prop->inputTensorRank[i] <= NNS_TENSOR_RANK_LIMIT);
+ silent_debug ("Input Prop: %d:%d:%d:%d Rank %d\n",
+ prop->inputDimension[i][0], prop->inputDimension[i][1],
+ prop->inputDimension[i][2], prop->inputDimension[i][3],
+ prop->inputTensorRank[i]);
+ }
prop->inputConfigured |= _TFC_DIMENSION;
- silent_debug ("Input Prop: %d:%d:%d:%d Rank %d\n",
- prop->inputDimension[0][0], prop->inputDimension[0][1],
- prop->inputDimension[0][2], prop->inputDimension[0][3], rank);
}
break;
case PROP_OUTPUT:
g_assert (!(prop->outputConfigured & _TFC_DIMENSION) && value);
/* Once configures, it cannot be changed in runtime */
{
- int rank = get_tensor_dimension (g_value_get_string (value),
- prop->outputDimension[0]);
- g_assert (rank > 0 && rank <= NNS_TENSOR_RANK_LIMIT);
+ int i;
+ prop->outputTensorSize =
+ get_tensor_dimension (g_value_get_string (value),
+ prop->outputDimension, prop->outputTensorRank);
+ for (i = 0; i < prop->outputTensorSize; i++) {
+ g_assert (prop->outputTensorRank[i] > 0
+ && prop->outputTensorRank[i] <= NNS_TENSOR_RANK_LIMIT);
+ silent_debug ("Output Prop: %d:%d:%d:%d Rank %d\n",
+ prop->outputDimension[i][0], prop->outputDimension[i][1],
+ prop->outputDimension[i][2], prop->outputDimension[i][3],
+ prop->outputTensorRank[i]);
+ }
prop->outputConfigured |= _TFC_DIMENSION;
- silent_debug ("Output Prop: %d:%d:%d:%d Rank %d\n",
- prop->outputDimension[0][0], prop->outputDimension[0][1],
- prop->outputDimension[0][2], prop->outputDimension[0][3], rank);
}
break;
case PROP_INPUTTYPE:
* @return The Rank.
* @param param The parameter string in the format of d1:d2:d3:d4, d1:d2:d3, d1:d2, or d1, where dN is a positive integer and d1 is the innermost dimension; i.e., dim[d4][d3][d2][d1];
*/
-extern int get_tensor_dimension (const gchar * param, tensor_dim dim);
+extern int get_tensor_dimension (const gchar * param,
+ uint32_t dim[NNS_TENSOR_SIZE_LIMIT][NNS_TENSOR_RANK_LIMIT],
+ int rank[NNS_TENSOR_SIZE_LIMIT]);
/**
* @brief Count the number of elemnts of a tensor
tensor_dim inputDimension[NNS_TENSOR_SIZE_LIMIT]; /**< The list of dimensions of each input tensors */
tensor_type inputType[NNS_TENSOR_SIZE_LIMIT]; /**< The list of types for each input tensors */
+ int inputTensorRank[NNS_TENSOR_SIZE_LIMIT]; /**< The list of types for each input tensors */
int inputCapNegotiated; /**< @todo check if this is really needed */
int inputTensorSize; /**< The number of input tensors */
tensor_dim outputDimension[NNS_TENSOR_SIZE_LIMIT]; /**< The list of dimensions of each output tensors */
tensor_type outputType[NNS_TENSOR_SIZE_LIMIT]; /**< The list of types for each output tensors */
+ int outputTensorRank[NNS_TENSOR_SIZE_LIMIT]; /**< The list of types for each input tensors */
int outputCapNegotiated; /**< @todo check if this is really needed */
int outputTensorSize; /**< The number of output tensors */
* @see https://github.sec.samsung.net/STAR/nnstreamer
* @bug No known bugs.
*
- * Copyright (C) 2018 Samsung Electronics Co., Ltd.
+ * @brief Unit test module for NNStreamer common library
+ * @bug No known bugs except for NYI items
+ *
+ * Copyright 2018 Samsung Electronics
*
*/
*/
TEST (common_get_tensor_dimension, case1)
{
- uint32_t dim[NNS_TENSOR_RANK_LIMIT];
- int rank = get_tensor_dimension ("345:123:433:177", dim);
- EXPECT_EQ (rank, 4);
- EXPECT_EQ (dim[0], 345);
- EXPECT_EQ (dim[1], 123);
- EXPECT_EQ (dim[2], 433);
- EXPECT_EQ (dim[3], 177);
+ uint32_t dim[NNS_TENSOR_SIZE_LIMIT][NNS_TENSOR_RANK_LIMIT];
+ int rank[NNS_TENSOR_RANK_LIMIT];
+ int num_tensors = get_tensor_dimension ("345:123:433:177", dim, rank);
+ EXPECT_EQ (num_tensors, 1);
+ EXPECT_EQ (rank[0], 4);
+ EXPECT_EQ (dim[0][0], 345);
+ EXPECT_EQ (dim[0][1], 123);
+ EXPECT_EQ (dim[0][2], 433);
+ EXPECT_EQ (dim[0][3], 177);
}
/**
*/
TEST (common_get_tensor_dimension, case2)
{
- uint32_t dim[NNS_TENSOR_RANK_LIMIT];
- int rank = get_tensor_dimension ("345:123:433", dim);
- EXPECT_EQ (rank, 3);
- EXPECT_EQ (dim[0], 345);
- EXPECT_EQ (dim[1], 123);
- EXPECT_EQ (dim[2], 433);
- EXPECT_EQ (dim[3], 1);
+ uint32_t dim[NNS_TENSOR_SIZE_LIMIT][NNS_TENSOR_RANK_LIMIT];
+ int rank[NNS_TENSOR_RANK_LIMIT];
+ int num_tensors = get_tensor_dimension ("345:123:433", dim, rank);
+ EXPECT_EQ (num_tensors, 1);
+ EXPECT_EQ (rank[0], 3);
+ EXPECT_EQ (dim[0][0], 345);
+ EXPECT_EQ (dim[0][1], 123);
+ EXPECT_EQ (dim[0][2], 433);
+ EXPECT_EQ (dim[0][3], 1);
}
/**
*/
TEST (common_get_tensor_dimension, case3)
{
- uint32_t dim[NNS_TENSOR_RANK_LIMIT];
- int rank = get_tensor_dimension ("345:123", dim);
- EXPECT_EQ (rank, 2);
- EXPECT_EQ (dim[0], 345);
- EXPECT_EQ (dim[1], 123);
- EXPECT_EQ (dim[2], 1);
- EXPECT_EQ (dim[3], 1);
+ uint32_t dim[NNS_TENSOR_SIZE_LIMIT][NNS_TENSOR_RANK_LIMIT];
+ int rank[NNS_TENSOR_RANK_LIMIT];
+ int num_tensors = get_tensor_dimension ("345:123", dim, rank);
+ EXPECT_EQ (num_tensors, 1);
+ EXPECT_EQ (rank[0], 2);
+ EXPECT_EQ (dim[0][0], 345);
+ EXPECT_EQ (dim[0][1], 123);
+ EXPECT_EQ (dim[0][2], 1);
+ EXPECT_EQ (dim[0][3], 1);
}
/**
*/
TEST (common_get_tensor_dimension, case4)
{
- uint32_t dim[NNS_TENSOR_RANK_LIMIT];
- int rank = get_tensor_dimension ("345", dim);
- EXPECT_EQ (rank, 1);
- EXPECT_EQ (dim[0], 345);
- EXPECT_EQ (dim[1], 1);
- EXPECT_EQ (dim[2], 1);
- EXPECT_EQ (dim[3], 1);
+ uint32_t dim[NNS_TENSOR_SIZE_LIMIT][NNS_TENSOR_RANK_LIMIT];
+ int rank[NNS_TENSOR_RANK_LIMIT];
+ int num_tensors = get_tensor_dimension ("345", dim, rank);
+ EXPECT_EQ (num_tensors, 1);
+ EXPECT_EQ (rank[0], 1);
+ EXPECT_EQ (dim[0][0], 345);
+ EXPECT_EQ (dim[0][1], 1);
+ EXPECT_EQ (dim[0][2], 1);
+ EXPECT_EQ (dim[0][3], 1);
}
/**