1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15- #include < viam/sdk/services/private/mlmodel.hpp>
16-
15+ #include < boost/variant/get.hpp>
1716#include < memory>
1817#include < stack>
1918#include < stdexcept>
2019#include < type_traits>
2120#include < utility>
22-
23- #include < boost/variant/get.hpp>
24-
2521#include < viam/sdk/common/exception.hpp>
22+ #include < viam/sdk/services/private/mlmodel.hpp>
2623
2724namespace viam {
2825namespace sdk {
@@ -68,8 +65,7 @@ class copy_sdk_tensor_to_api_tensor_visitor : public boost::static_visitor<void>
6865 static_cast <int >((t.size () + 1 ) * sizeof (std::int16_t ) / sizeof (std::uint32_t ));
6966 target_->mutable_int16_tensor ()->mutable_data ()->Clear ();
7067 target_->mutable_int16_tensor ()->mutable_data ()->Resize (num32s, 0 );
71- std::memcpy (target_->mutable_int16_tensor ()->mutable_data ()->mutable_data (),
72- t.begin (),
68+ std::memcpy (target_->mutable_int16_tensor ()->mutable_data ()->mutable_data (), t.begin (),
7369 t.size () * sizeof (std::int16_t ));
7470 }
7571
@@ -79,8 +75,7 @@ class copy_sdk_tensor_to_api_tensor_visitor : public boost::static_visitor<void>
7975 static_cast <int >((t.size () + 1 ) * sizeof (std::uint16_t ) / sizeof (std::uint32_t ));
8076 target_->mutable_uint16_tensor ()->mutable_data ()->Clear ();
8177 target_->mutable_uint16_tensor ()->mutable_data ()->Resize (num32s, 0 );
82- std::memcpy (target_->mutable_uint16_tensor ()->mutable_data ()->mutable_data (),
83- t.begin (),
78+ std::memcpy (target_->mutable_uint16_tensor ()->mutable_data ()->mutable_data (), t.begin (),
8479 t.size () * sizeof (std::uint16_t ));
8580 }
8681
@@ -118,8 +113,7 @@ class copy_sdk_tensor_to_api_tensor_visitor : public boost::static_visitor<void>
118113};
119114
120115template <typename T>
121- MLModelService::tensor_views make_sdk_tensor_from_api_tensor_t (const T* data,
122- std::size_t size,
116+ MLModelService::tensor_views make_sdk_tensor_from_api_tensor_t (const T* data, std::size_t size,
123117 std::vector<std::size_t >&& shape,
124118 tensor_storage* ts) {
125119 if (!data || (size == 0 ) || shape.empty ()) {
@@ -184,63 +178,49 @@ MLModelService::tensor_views make_sdk_tensor_from_api_tensor(
184178 if (api_tensor.has_int8_tensor ()) {
185179 return make_sdk_tensor_from_api_tensor_t (
186180 reinterpret_cast <const std::int8_t *>(api_tensor.int8_tensor ().data ().data ()),
187- api_tensor.int8_tensor ().data ().size (),
188- std::move (shape),
189- storage);
181+ api_tensor.int8_tensor ().data ().size (), std::move (shape), storage);
190182 } else if (api_tensor.has_uint8_tensor ()) {
191183 return make_sdk_tensor_from_api_tensor_t (
192184 reinterpret_cast <const std::uint8_t *>(api_tensor.uint8_tensor ().data ().data ()),
193- api_tensor.uint8_tensor ().data ().size (),
194- std::move (shape),
195- storage);
185+ api_tensor.uint8_tensor ().data ().size (), std::move (shape), storage);
196186 } else if (api_tensor.has_int16_tensor ()) {
197187 // TODO: be deswizzle
198188 return make_sdk_tensor_from_api_tensor_t (
199189 reinterpret_cast <const std::int16_t *>(api_tensor.int16_tensor ().data ().data ()),
200- std::size_t {2 } * api_tensor.int16_tensor ().data ().size (),
201- std::move (shape),
202- storage);
190+ std::size_t {2 } * api_tensor.int16_tensor ().data ().size (), std::move (shape), storage);
203191 } else if (api_tensor.has_uint16_tensor ()) {
204192 // TODO: be deswizzle
205193 return make_sdk_tensor_from_api_tensor_t (
206194 reinterpret_cast <const std::uint16_t *>(api_tensor.uint16_tensor ().data ().data ()),
207- std::size_t {2 } * api_tensor.uint16_tensor ().data ().size (),
208- std::move (shape),
209- storage);
195+ std::size_t {2 } * api_tensor.uint16_tensor ().data ().size (), std::move (shape), storage);
210196 } else if (api_tensor.has_int32_tensor ()) {
211197 return make_sdk_tensor_from_api_tensor_t (api_tensor.int32_tensor ().data ().data (),
212198 api_tensor.int32_tensor ().data ().size (),
213- std::move (shape),
214- storage);
199+ std::move (shape), storage);
215200 } else if (api_tensor.has_uint32_tensor ()) {
216201 return make_sdk_tensor_from_api_tensor_t (api_tensor.uint32_tensor ().data ().data (),
217202 api_tensor.uint32_tensor ().data ().size (),
218- std::move (shape),
219- storage);
203+ std::move (shape), storage);
220204
221205 } else if (api_tensor.has_int64_tensor ()) {
222206 return make_sdk_tensor_from_api_tensor_t (api_tensor.int64_tensor ().data ().data (),
223207 api_tensor.int64_tensor ().data ().size (),
224- std::move (shape),
225- storage);
208+ std::move (shape), storage);
226209
227210 } else if (api_tensor.has_uint64_tensor ()) {
228211 return make_sdk_tensor_from_api_tensor_t (api_tensor.uint64_tensor ().data ().data (),
229212 api_tensor.uint64_tensor ().data ().size (),
230- std::move (shape),
231- storage);
213+ std::move (shape), storage);
232214
233215 } else if (api_tensor.has_float_tensor ()) {
234216 return make_sdk_tensor_from_api_tensor_t (api_tensor.float_tensor ().data ().data (),
235217 api_tensor.float_tensor ().data ().size (),
236- std::move (shape),
237- storage);
218+ std::move (shape), storage);
238219
239220 } else if (api_tensor.has_double_tensor ()) {
240221 return make_sdk_tensor_from_api_tensor_t (api_tensor.double_tensor ().data ().data (),
241222 api_tensor.double_tensor ().data ().size (),
242- std::move (shape),
243- storage);
223+ std::move (shape), storage);
244224 }
245225 throw Exception (ErrorCondition::k_not_supported, " Unsupported tensor data type" );
246226}
0 commit comments