[ML] add condition for changing default value in dimension array 48/296448/1
authorYelin Jeong <yelini.jeong@samsung.com>
Fri, 28 Jul 2023 02:25:13 +0000 (11:25 +0900)
committerYelin Jeong <yelini.jeong@samsung.com>
Fri, 28 Jul 2023 02:40:37 +0000 (11:40 +0900)
To remove unnecessary initiazlied value 1 in dimension array,
ml-api will save '1' only if the user explicitly defined it.
So, some conditions may need to be changed.

Change-Id: Iafb626d4c7b2322cd7e5e8d42525fc194a7b3456
Signed-off-by: Yelin Jeong <yelini.jeong@samsung.com>
src/ml/ml_tensors_data_manager.cc

index 2870b2e..937cb2f 100644 (file)
@@ -105,7 +105,7 @@ PlatformResult TensorsData::GetTensorRawData(
   // Check if update is partial due to location change
   bool partial = false;
   for (int i = 0; i < util::kWebApiMLTensorRankLimit; i++) {
-    if (location[i] >= dim[i]) {
+    if (location[i] >= dim[i] && location[i] > 0) {
       // Input data starts outside of current data
       LoggerE("Requested data location is invalid on [%d]: %u", i, location[i]);
       return PlatformResult{ErrorCode::INVALID_VALUES_ERR, "Requested data location is invalid"};
@@ -204,7 +204,7 @@ PlatformResult TensorsData::SetTensorRawData(
   // Check if update is partial due to location change
   bool partial = false;
   for (int i = 0; i < util::kWebApiMLTensorRankLimit; i++) {
-    if (location[i] >= dim[i]) {
+    if (location[i] >= dim[i] && location[i] > 0) {
       // Input data starts outside of current data
       LoggerE("Input data location is invalid on [%d]: %u", i, location[i]);
       return PlatformResult{ErrorCode::INVALID_VALUES_ERR, "Input data location is invalid"};
@@ -222,7 +222,9 @@ PlatformResult TensorsData::SetTensorRawData(
       LoggerE("Input data will not fit in TensorData [%d]: %u > %u", i, size_rel[i], dim[i]);
       return PlatformResult{ErrorCode::INVALID_VALUES_ERR, "Input data will not fit in TensorData"};
     } else {
-      data_to_be_updated_size *= size[i];
+      if (size[i] != 0) {
+        data_to_be_updated_size *= size[i];
+      }
       if (size_rel[i] < dim[i]) {
         partial = true;
       }