int ml_tensors_data_set_tensor_data (ml_tensors_data_h data, unsigned int index, const void *raw_data, const size_t data_size);
/**
+ * @brief Copies the tensor data frame.
+ * @since_tizen 9.0
+ * @remarks The @a out should be released using ml_tensors_data_destroy().
+ * @param[in] in The handle of tensors data to be cloned.
+ * @param[out] out The handle of tensors data.
+ * @return @c 0 on success. Otherwise a negative error value.
+ * @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
+ * @retval #ML_ERROR_INVALID_PARAMETER Given parameter is invalid.
+ * @retval #ML_ERROR_OUT_OF_MEMORY Failed to allocate required memory.
+ */
+int ml_tensors_data_clone (const ml_tensors_data_h in, ml_tensors_data_h *out);
+
+/**
+ * @brief Gets the tensors information of given tensor data frame.
+ * @since_tizen 9.0
+ * @remarks The @a info should be released using ml_tensors_info_destroy().
+ * @param[in] data The handle of tensors data.
+ * @param[out] info The handle of tensors information.
+ * @return @c 0 on success. Otherwise a negative error value.
+ * @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
+ * @retval #ML_ERROR_INVALID_PARAMETER Given parameter is invalid.
+ * @retval #ML_ERROR_OUT_OF_MEMORY Failed to allocate required memory.
+ */
+int ml_tensors_data_get_info (const ml_tensors_data_h data, ml_tensors_info_h *info);
+
+/**
* @brief Returns a human-readable string describing the last error.
* @details This returns a human-readable, null-terminated string describing
* the most recent error that occurred from a call to one of the
}
/**
+ * @brief Creates new tensors-info handle and copies tensors information.
+ */
+int
+_ml_tensors_info_create_from (const ml_tensors_info_h in,
+ ml_tensors_info_h * out)
+{
+ ml_tensors_info_s *_info;
+ int status;
+
+ if (!in || !out)
+ return ML_ERROR_INVALID_PARAMETER;
+
+ _info = (ml_tensors_info_s *) in;
+
+ if (_info->is_extended)
+ status = ml_tensors_info_create_extended (out);
+ else
+ status = ml_tensors_info_create (out);
+
+ if (status == ML_ERROR_NONE)
+ status = ml_tensors_info_clone (*out, in);
+
+ return status;
+}
+
+/**
* @brief Allocates a tensors information handle with default value.
*/
int
{
ml_tensors_data_s *_data;
ml_tensors_info_s *_info;
- gint i;
+ guint i;
check_feature_state (ML_FEATURE);
_info = (ml_tensors_info_s *) info;
if (_info != NULL) {
- if (_info->is_extended)
- ml_tensors_info_create_extended (&_data->info);
- else
- ml_tensors_info_create (&_data->info);
- ml_tensors_info_clone (_data->info, info);
+ /* Ignore error case when creating internal info handle (single-shot). */
+ _ml_tensors_info_create_from (info, &_data->info);
G_LOCK_UNLESS_NOLOCK (*_info);
_data->num_tensors = _info->info.num_tensors;
}
/**
+ * @brief Gets the tensors information of given tensor data frame.
+ */
+int
+ml_tensors_data_get_info (const ml_tensors_data_h data,
+ ml_tensors_info_h * info)
+{
+ int status;
+ ml_tensors_data_s *_data;
+
+ check_feature_state (ML_FEATURE);
+
+ if (data == NULL) {
+ _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
+ "The parameter, data, is NULL. It should be a valid ml_tensors_data_h handle, which is usually created by ml_tensors_data_create ().");
+ }
+
+ if (info == NULL) {
+ _ml_error_report_return (ML_ERROR_INVALID_PARAMETER,
+ "The parameter, info, is NULL. It should be a valid pointer to a space that can hold a ml_tensors_info_h handle. E.g., ml_tensors_info_h info; ml_tensors_data_get_info (data, &info);.");
+ }
+
+ _data = (ml_tensors_data_s *) data;
+ G_LOCK_UNLESS_NOLOCK (*_data);
+
+ status = _ml_tensors_info_create_from (_data->info, info);
+ if (status != ML_ERROR_NONE) {
+ _ml_error_report_continue
+ ("Failed to get the tensor information from data handle.");
+ }
+
+ G_UNLOCK_UNLESS_NOLOCK (*_data);
+ return status;
+}
+
+/**
* @brief Allocates a tensor data frame with the given tensors info. (more info in nnstreamer.h)
*/
int
{
gint status = ML_ERROR_STREAMS_PIPE;
ml_tensors_data_s *_data = NULL;
- gint i;
+ guint i;
bool valid;
check_feature_state (ML_FEATURE);
} ml_tensors_data_s;
/**
+ * @brief Creates new tensors-info handle and copies tensors information.
+ */
+int _ml_tensors_info_create_from (const ml_tensors_info_h in, ml_tensors_info_h *out);
+
+/**
* @brief Initializes the tensors information with default value.
* @since_tizen 5.5
* @param[in] info The tensors info pointer to be initialized.
int _ml_tensors_data_clone_no_alloc (const ml_tensors_data_s * data_src, ml_tensors_data_h * data);
/**
- * @brief Copies the tensor data frame.
- * @since_tizen 8.0
- * @param[in] in The handle of tensors data to be cloned.
- * @param[out] out The handle of tensors data. The caller is responsible for freeing the allocated data with ml_tensors_data_destroy().
- * @return @c 0 on success. Otherwise a negative error value.
- * @retval #ML_ERROR_NONE Successful.
- * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
- * @retval #ML_ERROR_INVALID_PARAMETER Given parameter is invalid.
- * @retval #ML_ERROR_OUT_OF_MEMORY Failed to allocate required memory.
- * @todo Consider adding new API from tizen 8.0.
- */
-int ml_tensors_data_clone (const ml_tensors_data_h in, ml_tensors_data_h *out);
-
-/**
* @brief Replaces string.
* This function deallocates the input source string.
* This is copied from nnstreamer/tensor_common.c by the nnstreamer maintainer.
}
/**
+ * @brief Test utility functions - get tensors-info from data handle.
+ */
+TEST (nnstreamer_capi_util, data_get_info_01_p)
+{
+ int status;
+ ml_tensors_info_h in_info, out_info;
+ ml_tensors_data_h data;
+ ml_tensor_dimension dim = { 5, 1, 1, 1 };
+
+ ml_tensors_info_create (&in_info);
+ ml_tensors_info_set_count (in_info, 1);
+ ml_tensors_info_set_tensor_type (in_info, 0, ML_TENSOR_TYPE_INT32);
+ ml_tensors_info_set_tensor_dimension (in_info, 0, dim);
+ ml_tensors_data_create (in_info, &data);
+
+ status = ml_tensors_data_get_info (data, &out_info);
+ EXPECT_EQ (status, ML_ERROR_NONE);
+
+ EXPECT_TRUE (ml_tensors_info_is_equal (in_info, out_info));
+
+ ml_tensors_info_destroy (in_info);
+ ml_tensors_info_destroy (out_info);
+ ml_tensors_data_destroy (data);
+}
+
+/**
+ * @brief Test utility functions - get tensors-info from data handle.
+ */
+TEST (nnstreamer_capi_util, data_get_info_02_n)
+{
+ int status;
+ ml_tensors_info_h out_info;
+
+ status = ml_tensors_data_get_info (nullptr, &out_info);
+ EXPECT_EQ (status, ML_ERROR_INVALID_PARAMETER);
+}
+
+/**
+ * @brief Test utility functions - get tensors-info from data handle.
+ */
+TEST (nnstreamer_capi_util, data_get_info_03_n)
+{
+ int status;
+ ml_tensors_info_h in_info;
+ ml_tensors_data_h data;
+ ml_tensor_dimension dim = { 5, 1, 1, 1 };
+
+ ml_tensors_info_create (&in_info);
+ ml_tensors_info_set_count (in_info, 1);
+ ml_tensors_info_set_tensor_type (in_info, 0, ML_TENSOR_TYPE_INT32);
+ ml_tensors_info_set_tensor_dimension (in_info, 0, dim);
+ ml_tensors_data_create (in_info, &data);
+
+ status = ml_tensors_data_get_info (data, nullptr);
+ EXPECT_EQ (status, ML_ERROR_INVALID_PARAMETER);
+
+ ml_tensors_info_destroy (in_info);
+ ml_tensors_data_destroy (data);
+}
+
+/**
* @brief Test to replace string.
*/
TEST (nnstreamer_capi_util, replaceStr01)