From ebfd7284c921a343d8c5b70f0291a5db4a71126f Mon Sep 17 00:00:00 2001 From: Kinar Date: Thu, 5 Oct 2023 04:25:18 -0700 Subject: [PATCH] Fixed some issues with documentation --- .../components/containers/embedding_result.h | 8 +++---- .../containers/embedding_result_converter.cc | 22 +++++++++++-------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/mediapipe/tasks/c/components/containers/embedding_result.h b/mediapipe/tasks/c/components/containers/embedding_result.h index 448bf2eef..2a8082a7a 100644 --- a/mediapipe/tasks/c/components/containers/embedding_result.h +++ b/mediapipe/tasks/c/components/containers/embedding_result.h @@ -29,12 +29,12 @@ extern "C" { // contain data, based on whether or not the embedder was configured to perform // scalar quantization. struct Embedding { - // Floating-point embedding. Empty/nullptr if the embedder was configured to perform - // scalar-quantization. + // Floating-point embedding. Empty/nullptr if the embedder was configured to + // perform scalar-quantization. float* float_embedding; - // Scalar-quantized embedding. Empty/nullptr if the embedder was not configured to - // perform scalar quantization. + // Scalar-quantized embedding. Empty/nullptr if the embedder was not + // configured to perform scalar quantization. char* quantized_embedding; // Keep the count of embedding values. diff --git a/mediapipe/tasks/c/components/containers/embedding_result_converter.cc b/mediapipe/tasks/c/components/containers/embedding_result_converter.cc index 3db085a73..94cf0e9de 100644 --- a/mediapipe/tasks/c/components/containers/embedding_result_converter.cc +++ b/mediapipe/tasks/c/components/containers/embedding_result_converter.cc @@ -36,25 +36,29 @@ void CppConvertToEmbeddingResult( for (uint32_t i = 0; i < out->embeddings_count; ++i) { auto embedding_in = in.embeddings[i]; auto& embedding_out = out->embeddings[i]; - + // Handling float embeddings if (!embedding_in.float_embedding.empty()) { embedding_out.values_count = embedding_in.float_embedding.size(); - embedding_out.float_embedding = - embedding_out.values_count ? new float[embedding_out.values_count] - : nullptr; + embedding_out.float_embedding = new float[embedding_out.values_count]; + std::copy(embedding_in.float_embedding.begin(), embedding_in.float_embedding.end(), embedding_out.float_embedding); + embedding_out.quantized_embedding = nullptr; - } else if (!embedding_in.quantized_embedding.empty()) { + + } + // Handling quantized embeddings + else if (!embedding_in.quantized_embedding.empty()) { embedding_out.values_count = embedding_in.quantized_embedding.size(); - embedding_out.quantized_embedding = - embedding_out.values_count ? new char[embedding_out.values_count] - : nullptr; + embedding_out.quantized_embedding = new char[embedding_out.values_count]; + std::copy(embedding_in.quantized_embedding.begin(), embedding_in.quantized_embedding.end(), embedding_out.quantized_embedding); + embedding_out.float_embedding = nullptr; + } embedding_out.head_index = embedding_in.head_index; @@ -76,7 +80,7 @@ void CppCloseEmbeddingResult(EmbeddingResult* in) { free(embedding_in.head_name); } delete[] in->embeddings; - in.head_name = nullptr; + in->embeddings = nullptr; } } // namespace mediapipe::tasks::c::components::containers