2 * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using Tizen.MachineLearning.Inference;
21 namespace Tizen.MachineLearning.Inference.Test
23 public static class TensorsInfoTest
25 const string TAG = "Nnstreamer";
27 public static bool BasicTensorTest_Success00()
29 int[] in_dim = new int[4] { 3, 224, 224, 1 };
31 TensorsInfo tensorsInfo = new TensorsInfo();
32 tensorsInfo.AddTensorInfo(TensorType.UInt8, in_dim);
35 if (tensorsInfo.GetTensorType(0) != TensorType.UInt8)
38 int[] in_res = tensorsInfo.GetDimension(0);
39 for (int i = 0; i < 4; ++i)
41 if (in_dim[i] != in_res[i])
46 public static bool BasicTensorTest_Success01()
48 TensorsInfo tensorsInfo;
49 TensorsData tensorsData;
50 int[] in_dim = new int[4] { 10, 1, 1, 1 };
51 byte[] buffer_in = new byte[] { 17, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
54 tensorsInfo = new TensorsInfo();
55 tensorsInfo.AddTensorInfo(TensorType.UInt8, in_dim);
56 Log.Info(TAG, "Current Count: " + tensorsInfo.Count);
58 tensorsData = tensorsInfo.GetTensorsData();
59 tensorsData.SetTensorData(0, buffer_in);
61 buffer_out = tensorsData.GetTensorData(0);
63 if (buffer_in.Length != buffer_out.Length)
65 Log.Error(TAG, "The size of buffers is different");
69 for (int i = 0; i < buffer_in.Length; ++i)
71 if (buffer_in[i] != buffer_out[i])
73 Log.Error(TAG, "The value of " + i.ToString() + " th element is different");
81 public static bool BasicTensorTest_Success02()
83 TensorsInfo tensorsInfo;
84 TensorsData tensorsData;
85 int[] in_dim = new int[4] { 10, 1, 1, 1 };
86 byte[] buffer_in = new byte[] { 17, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
89 tensorsInfo = new TensorsInfo();
90 tensorsInfo.AddTensorInfo(TensorType.UInt8, in_dim);
92 tensorsData = tensorsInfo.GetTensorsData();
93 tensorsData.SetTensorData(0, buffer_in);
94 buffer_out = tensorsData.GetTensorData(0);
96 if (buffer_in.Length != buffer_out.Length)
98 Log.Error(TAG, "The size of buffers is different");
102 for (int i = 0; i < buffer_in.Length; ++i)
104 if (buffer_in[i] != buffer_out[i])
106 Log.Error(TAG, "The value of " + i.ToString() + " th element is different");
110 tensorsData.Dispose();
113 int[] in2_dim = new int[4] { 5, 1, 1, 1 };
114 byte[] buffer_in2 = new byte[] { 10, 20, 30, 40, 50 };
118 tensorsInfo.AddTensorInfo(TensorType.UInt8, in2_dim);
120 tensorsData = tensorsInfo.GetTensorsData();
121 tensorsData.SetTensorData(0, buffer_in);
122 buffer_out = tensorsData.GetTensorData(0);
123 tensorsData.SetTensorData(1, buffer_in2);
124 buffer_out2 = tensorsData.GetTensorData(1);
126 if (buffer_in2.Length != buffer_out2.Length)
128 Log.Error(TAG, "The size of buffers is different");
132 for (int i = 0; i < buffer_in2.Length; ++i)
134 if (buffer_in2[i] != buffer_out2[i])
136 Log.Error(TAG, "The value of " + i.ToString() + " th element is different");