From 79de867efd5d98c5eabe37322c6caada3dd44a8a Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Thu, 10 Jul 2025 17:04:21 -0400 Subject: [PATCH 1/3] revert calling private setter --- src/viam/sdk/spatialmath/orientation.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/viam/sdk/spatialmath/orientation.cpp b/src/viam/sdk/spatialmath/orientation.cpp index f87c17a36..2079da80c 100644 --- a/src/viam/sdk/spatialmath/orientation.cpp +++ b/src/viam/sdk/spatialmath/orientation.cpp @@ -51,7 +51,6 @@ void to_proto_impl::operator()(const Orientation& self, aa.set_z(a.z); aa.set_theta(a.theta); *orientation.mutable_axis_angles() = std::move(aa); - orientation.set_has_axis_angles(); } void operator()(const orientation_vector& ov) { @@ -61,7 +60,6 @@ void to_proto_impl::operator()(const Orientation& self, ovec.set_z(ov.z); ovec.set_theta(ov.theta); *orientation.mutable_vector_radians() = std::move(ovec); - orientation.set_has_vector_radians(); } void operator()(const orientation_vector_degrees& ovd) { @@ -71,7 +69,6 @@ void to_proto_impl::operator()(const Orientation& self, ovec.set_z(ovd.z); ovec.set_theta(ovd.theta); *orientation.mutable_vector_degrees() = std::move(ovec); - orientation.set_has_vector_degrees(); } void operator()(const euler_angles& ea) { @@ -80,7 +77,6 @@ void to_proto_impl::operator()(const Orientation& self, euler.set_roll(ea.roll); euler.set_yaw(ea.yaw); *orientation.mutable_euler_angles() = std::move(euler); - orientation.set_has_euler_angles(); } void operator()(const quaternion& q) { @@ -90,7 +86,6 @@ void to_proto_impl::operator()(const Orientation& self, quat.set_y(q.y); quat.set_z(q.z); *orientation.mutable_quaternion() = std::move(quat); - orientation.set_has_quaternion(); } app::v1::Orientation& orientation; From fd1fa9bd32670f320aad7b315cfbacc4d6b61e04 Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Mon, 25 Aug 2025 09:54:23 -0400 Subject: [PATCH 2/3] add ostream operator for tensor data types --- src/viam/sdk/services/mlmodel.cpp | 14 ++++++++++++++ src/viam/sdk/services/mlmodel.hpp | 4 ++++ .../sdk/services/private/mlmodel_server.cpp | 18 +++++------------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/viam/sdk/services/mlmodel.cpp b/src/viam/sdk/services/mlmodel.cpp index 28bc9c51d..8e02ee4f9 100644 --- a/src/viam/sdk/services/mlmodel.cpp +++ b/src/viam/sdk/services/mlmodel.cpp @@ -100,6 +100,20 @@ const char* MLModelService::tensor_info::data_type_to_string(const data_types da return nullptr; } +std::ostream& operator<<(std::ostream& os, MLModelService::tensor_info::data_types dt) { + const char* str = MLModelService::tensor_info::data_type_to_string(dt); + + if (str) { + os << str; + } else { + // Cast to unsigned because uint8_t is unsigned char, and 0-9 are whitespace or non printing + // characters + os << static_cast(static_cast>(dt)); + } + + return os; +} + MLModelService::tensor_info::data_types MLModelService::tensor_info::tensor_views_to_data_type( const tensor_views& view) { class visitor : public boost::static_visitor { diff --git a/src/viam/sdk/services/mlmodel.hpp b/src/viam/sdk/services/mlmodel.hpp index fec2ad0d3..7797e86bd 100644 --- a/src/viam/sdk/services/mlmodel.hpp +++ b/src/viam/sdk/services/mlmodel.hpp @@ -14,6 +14,8 @@ #pragma once +#include + #include #include #include @@ -177,5 +179,7 @@ struct API::traits { static API api(); }; +std::ostream& operator<<(std::ostream&, MLModelService::tensor_info::data_types); + } // namespace sdk } // namespace viam diff --git a/src/viam/sdk/services/private/mlmodel_server.cpp b/src/viam/sdk/services/private/mlmodel_server.cpp index ddd831b9e..680446568 100644 --- a/src/viam/sdk/services/private/mlmodel_server.cpp +++ b/src/viam/sdk/services/private/mlmodel_server.cpp @@ -48,10 +48,8 @@ ::grpc::Status MLModelServiceServer::Infer( const auto tensor_type = MLModelService::tensor_info::tensor_views_to_data_type(tensor); if (tensor_type != input.data_type) { std::ostringstream message; - using ut = std::underlying_type::type; message << "Tensor input `" << input.name << "` was the wrong type; expected type " - << static_cast(input.data_type) << " but got type " - << static_cast(tensor_type); + << input.data_type << " but got type " << tensor_type; return helper.fail(::grpc::INVALID_ARGUMENT, message.str().c_str()); } inputs.emplace(input.name, std::move(tensor)); @@ -74,11 +72,9 @@ ::grpc::Status MLModelServiceServer::Infer( MLModelService::tensor_info::tensor_views_to_data_type(tensor); if (tensor_type != input.data_type) { std::ostringstream message; - using ut = std::underlying_type::type; message << "Tensor input `" << input.name - << "` was the wrong type; expected type " - << static_cast(input.data_type) << " but got type " - << static_cast(tensor_type); + << "` was the wrong type; expected type " << input.data_type + << " but got type " << tensor_type; return helper.fail(::grpc::INVALID_ARGUMENT, message.str().c_str()); } inputs.emplace(std::move(input.name), std::move(tensor)); @@ -122,12 +118,8 @@ ::grpc::Status MLModelServiceServer::Metadata( MLModelService::tensor_info::data_type_to_string(s.data_type); if (!string_for_data_type) { std::ostringstream message; - message - << "Served MLModelService returned an unknown data type with value `" - << static_cast< - std::underlying_type::type>( - s.data_type) - << "` in its metadata"; + message << "Served MLModelService returned an unknown data type with value `" + << s.data_type << "` in its metadata"; return helper.fail(grpc::INTERNAL, message.str().c_str()); } new_entry.set_data_type(string_for_data_type); From a71cc43a6bf332dbbe8a5cd1646e532cb0a630f2 Mon Sep 17 00:00:00 2001 From: lia <167905060+lia-viam@users.noreply.github.com> Date: Mon, 25 Aug 2025 12:57:23 -0400 Subject: [PATCH 3/3] Update mlmodel.cpp --- src/viam/sdk/services/mlmodel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/viam/sdk/services/mlmodel.cpp b/src/viam/sdk/services/mlmodel.cpp index 8e02ee4f9..8a749b6d5 100644 --- a/src/viam/sdk/services/mlmodel.cpp +++ b/src/viam/sdk/services/mlmodel.cpp @@ -108,7 +108,7 @@ std::ostream& operator<<(std::ostream& os, MLModelService::tensor_info::data_typ } else { // Cast to unsigned because uint8_t is unsigned char, and 0-9 are whitespace or non printing // characters - os << static_cast(static_cast>(dt)); + os << static_cast(dt); } return os;