diff --git a/packages/react-native-executorch/common/rnexecutorch/TokenizerModule.h b/packages/react-native-executorch/common/rnexecutorch/TokenizerModule.h index 77c94b4bf..5431abe71 100644 --- a/packages/react-native-executorch/common/rnexecutorch/TokenizerModule.h +++ b/packages/react-native-executorch/common/rnexecutorch/TokenizerModule.h @@ -11,11 +11,16 @@ class TokenizerModule { public: explicit TokenizerModule(std::string source, std::shared_ptr callInvoker); - std::vector encode(std::string s) const; - std::string decode(std::vector vec, bool skipSpecialTokens) const; - std::string idToToken(int32_t tokenId) const; - int32_t tokenToId(std::string token) const; - std::size_t getVocabSize() const; + [[nodiscard("Registered non-void function")]] std::vector + encode(std::string s) const; + [[nodiscard("Registered non-void function")]] std::string + decode(std::vector vec, bool skipSpecialTokens) const; + [[nodiscard("Registered non-void function")]] std::string + idToToken(int32_t tokenId) const; + [[nodiscard("Registered non-void function")]] int32_t + tokenToId(std::string token) const; + [[nodiscard("Registered non-void function")]] std::size_t + getVocabSize() const; std::size_t getMemoryLowerBound() const noexcept; private: diff --git a/packages/react-native-executorch/common/rnexecutorch/host_objects/ModelHostObject.h b/packages/react-native-executorch/common/rnexecutorch/host_objects/ModelHostObject.h index 4caf5c132..d4b107004 100644 --- a/packages/react-native-executorch/common/rnexecutorch/host_objects/ModelHostObject.h +++ b/packages/react-native-executorch/common/rnexecutorch/host_objects/ModelHostObject.h @@ -31,15 +31,11 @@ template class ModelHostObject : public JsiHostObject { if constexpr (meta::DerivedFromOrSameAs) { addFunctions( JSI_EXPORT_FUNCTION(ModelHostObject, unload, "unload")); - } - if constexpr (meta::DerivedFromOrSameAs) { addFunctions(JSI_EXPORT_FUNCTION(ModelHostObject, promiseHostFunction<&Model::forwardJS>, "forward")); - } - if constexpr (meta::DerivedFromOrSameAs) { addFunctions(JSI_EXPORT_FUNCTION( ModelHostObject, promiseHostFunction<&Model::getInputShape>, "getInputShape")); @@ -86,13 +82,6 @@ template class ModelHostObject : public JsiHostObject { } if constexpr (meta::SameAs) { - addFunctions(JSI_EXPORT_FUNCTION(ModelHostObject, - promiseHostFunction<&Model::encode>, - "encode")); - - addFunctions(JSI_EXPORT_FUNCTION(ModelHostObject, - promiseHostFunction<&Model::decode>, - "decode")); addFunctions(JSI_EXPORT_FUNCTION( ModelHostObject, promiseHostFunction<&Model::getVocabSize>, "getVocabSize")); @@ -105,10 +94,6 @@ template class ModelHostObject : public JsiHostObject { } if constexpr (meta::SameAs) { - addFunctions(JSI_EXPORT_FUNCTION(ModelHostObject, - promiseHostFunction<&Model::generate>, - "generate")); - addFunctions(JSI_EXPORT_FUNCTION( ModelHostObject, synchronousHostFunction<&Model::interrupt>, "interrupt")); diff --git a/packages/react-native-executorch/common/rnexecutorch/models/BaseModel.h b/packages/react-native-executorch/common/rnexecutorch/models/BaseModel.h index 983dc9b74..dd3ecbb5c 100644 --- a/packages/react-native-executorch/common/rnexecutorch/models/BaseModel.h +++ b/packages/react-native-executorch/common/rnexecutorch/models/BaseModel.h @@ -21,10 +21,11 @@ class BaseModel { std::shared_ptr callInvoker); std::size_t getMemoryLowerBound() const noexcept; void unload() noexcept; - std::vector getInputShape(std::string method_name, int32_t index); + [[nodiscard("Registered non-void function")]] std::vector + getInputShape(std::string method_name, int32_t index); std::vector> getAllInputShapes(std::string methodName = "forward"); - std::vector + [[nodiscard("Registered non-void function")]] std::vector forwardJS(std::vector tensorViewVec); Result> forward(const EValue &input_value) const; Result> diff --git a/packages/react-native-executorch/common/rnexecutorch/models/classification/Classification.h b/packages/react-native-executorch/common/rnexecutorch/models/classification/Classification.h index 88f1e3046..1465fc5f9 100644 --- a/packages/react-native-executorch/common/rnexecutorch/models/classification/Classification.h +++ b/packages/react-native-executorch/common/rnexecutorch/models/classification/Classification.h @@ -17,7 +17,9 @@ class Classification : public BaseModel { public: Classification(const std::string &modelSource, std::shared_ptr callInvoker); - std::unordered_map generate(std::string imageSource); + [[nodiscard("Registered non-void function")]] std::unordered_map< + std::string_view, float> + generate(std::string imageSource); private: std::unordered_map postprocess(const Tensor &tensor); diff --git a/packages/react-native-executorch/common/rnexecutorch/models/embeddings/image/ImageEmbeddings.h b/packages/react-native-executorch/common/rnexecutorch/models/embeddings/image/ImageEmbeddings.h index f5f7a0e89..7e114e939 100644 --- a/packages/react-native-executorch/common/rnexecutorch/models/embeddings/image/ImageEmbeddings.h +++ b/packages/react-native-executorch/common/rnexecutorch/models/embeddings/image/ImageEmbeddings.h @@ -16,7 +16,9 @@ class ImageEmbeddings final : public BaseEmbeddings { public: ImageEmbeddings(const std::string &modelSource, std::shared_ptr callInvoker); - std::shared_ptr generate(std::string imageSource); + [[nodiscard( + "Registered non-void function")]] std::shared_ptr + generate(std::string imageSource); private: cv::Size modelImageSize{0, 0}; diff --git a/packages/react-native-executorch/common/rnexecutorch/models/embeddings/text/TextEmbeddings.h b/packages/react-native-executorch/common/rnexecutorch/models/embeddings/text/TextEmbeddings.h index 0b01bbf97..28dacca36 100644 --- a/packages/react-native-executorch/common/rnexecutorch/models/embeddings/text/TextEmbeddings.h +++ b/packages/react-native-executorch/common/rnexecutorch/models/embeddings/text/TextEmbeddings.h @@ -17,7 +17,9 @@ class TextEmbeddings final : public BaseEmbeddings { TextEmbeddings(const std::string &modelSource, const std::string &tokenizerSource, std::shared_ptr callInvoker); - std::shared_ptr generate(const std::string input); + [[nodiscard( + "Registered non-void function")]] std::shared_ptr + generate(const std::string input); private: std::vector> inputShapes; diff --git a/packages/react-native-executorch/common/rnexecutorch/models/image_segmentation/ImageSegmentation.h b/packages/react-native-executorch/common/rnexecutorch/models/image_segmentation/ImageSegmentation.h index 779ab90c7..4b2a41a66 100644 --- a/packages/react-native-executorch/common/rnexecutorch/models/image_segmentation/ImageSegmentation.h +++ b/packages/react-native-executorch/common/rnexecutorch/models/image_segmentation/ImageSegmentation.h @@ -23,7 +23,7 @@ class ImageSegmentation : public BaseModel { public: ImageSegmentation(const std::string &modelSource, std::shared_ptr callInvoker); - std::shared_ptr + [[nodiscard("Registered non-void function")]] std::shared_ptr generate(std::string imageSource, std::set> classesOfInterest, bool resize); diff --git a/packages/react-native-executorch/common/rnexecutorch/models/object_detection/ObjectDetection.h b/packages/react-native-executorch/common/rnexecutorch/models/object_detection/ObjectDetection.h index 88a97fa77..bba09a6d8 100644 --- a/packages/react-native-executorch/common/rnexecutorch/models/object_detection/ObjectDetection.h +++ b/packages/react-native-executorch/common/rnexecutorch/models/object_detection/ObjectDetection.h @@ -20,8 +20,8 @@ class ObjectDetection : public BaseModel { public: ObjectDetection(const std::string &modelSource, std::shared_ptr callInvoker); - std::vector generate(std::string imageSource, - double detectionThreshold); + [[nodiscard("Registered non-void function")]] std::vector + generate(std::string imageSource, double detectionThreshold); private: std::vector postprocess(const std::vector &tensors, diff --git a/packages/react-native-executorch/common/rnexecutorch/models/ocr/Detector.h b/packages/react-native-executorch/common/rnexecutorch/models/ocr/Detector.h index f9fb2a39b..188ae58ec 100644 --- a/packages/react-native-executorch/common/rnexecutorch/models/ocr/Detector.h +++ b/packages/react-native-executorch/common/rnexecutorch/models/ocr/Detector.h @@ -20,7 +20,8 @@ class Detector final : public BaseModel { public: explicit Detector(const std::string &modelSource, std::shared_ptr callInvoker); - std::vector generate(const cv::Mat &inputImage); + [[nodiscard("Registered non-void function")]] std::vector + generate(const cv::Mat &inputImage); cv::Size getModelImageSize() const noexcept; private: diff --git a/packages/react-native-executorch/common/rnexecutorch/models/ocr/OCR.h b/packages/react-native-executorch/common/rnexecutorch/models/ocr/OCR.h index c7c7e61c4..e1e5abae1 100644 --- a/packages/react-native-executorch/common/rnexecutorch/models/ocr/OCR.h +++ b/packages/react-native-executorch/common/rnexecutorch/models/ocr/OCR.h @@ -28,7 +28,8 @@ class OCR final { const std::string &recognizerSourceMedium, const std::string &recognizerSourceSmall, std::string symbols, std::shared_ptr callInvoker); - std::vector generate(std::string input); + [[nodiscard("Registered non-void function")]] std::vector + generate(std::string input); std::size_t getMemoryLowerBound() const noexcept; void unload() noexcept; diff --git a/packages/react-native-executorch/common/rnexecutorch/models/ocr/Recognizer.h b/packages/react-native-executorch/common/rnexecutorch/models/ocr/Recognizer.h index 50eafe968..21e9f9c6c 100644 --- a/packages/react-native-executorch/common/rnexecutorch/models/ocr/Recognizer.h +++ b/packages/react-native-executorch/common/rnexecutorch/models/ocr/Recognizer.h @@ -25,7 +25,9 @@ class Recognizer final : public BaseModel { public: explicit Recognizer(const std::string &modelSource, std::shared_ptr callInvoker); - std::pair, float> generate(const cv::Mat &grayImage); + [[nodiscard( + "Registered non-void function")]] std::pair, float> + generate(const cv::Mat &grayImage); private: std::pair, float> diff --git a/packages/react-native-executorch/common/rnexecutorch/models/speech_to_text/SpeechToText.h b/packages/react-native-executorch/common/rnexecutorch/models/speech_to_text/SpeechToText.h index d62ef266c..cdca867f5 100644 --- a/packages/react-native-executorch/common/rnexecutorch/models/speech_to_text/SpeechToText.h +++ b/packages/react-native-executorch/common/rnexecutorch/models/speech_to_text/SpeechToText.h @@ -14,11 +14,14 @@ class SpeechToText { std::shared_ptr callInvoker); void unload() noexcept; - std::shared_ptr encode(std::span waveform) const; - std::shared_ptr + [[nodiscard( + "Registered non-void function")]] std::shared_ptr + encode(std::span waveform) const; + [[nodiscard( + "Registered non-void function")]] std::shared_ptr decode(std::span tokens, std::span encoderOutput) const; - std::string transcribe(std::span waveform, - std::string languageOption) const; + [[nodiscard("Registered non-void function")]] std::string + transcribe(std::span waveform, std::string languageOption) const; size_t getMemoryLowerBound() const noexcept; diff --git a/packages/react-native-executorch/common/rnexecutorch/models/style_transfer/StyleTransfer.h b/packages/react-native-executorch/common/rnexecutorch/models/style_transfer/StyleTransfer.h index 3fbdd5543..73744c4d8 100644 --- a/packages/react-native-executorch/common/rnexecutorch/models/style_transfer/StyleTransfer.h +++ b/packages/react-native-executorch/common/rnexecutorch/models/style_transfer/StyleTransfer.h @@ -21,7 +21,8 @@ class StyleTransfer : public BaseModel { public: StyleTransfer(const std::string &modelSource, std::shared_ptr callInvoker); - std::string generate(std::string imageSource); + [[nodiscard("Registered non-void function")]] std::string + generate(std::string imageSource); private: std::string postprocess(const Tensor &tensor, cv::Size originalSize); diff --git a/packages/react-native-executorch/common/rnexecutorch/models/vertical_ocr/VerticalDetector.h b/packages/react-native-executorch/common/rnexecutorch/models/vertical_ocr/VerticalDetector.h index 802ab7329..6566fe24d 100644 --- a/packages/react-native-executorch/common/rnexecutorch/models/vertical_ocr/VerticalDetector.h +++ b/packages/react-native-executorch/common/rnexecutorch/models/vertical_ocr/VerticalDetector.h @@ -38,7 +38,8 @@ class VerticalDetector final : public BaseModel { explicit VerticalDetector(const std::string &modelSource, bool detectSingleCharacters, std::shared_ptr callInvoker); - std::vector generate(const cv::Mat &inputImage); + [[nodiscard("Registered non-void function")]] std::vector + generate(const cv::Mat &inputImage); cv::Size getModelImageSize() const noexcept; private: diff --git a/packages/react-native-executorch/common/rnexecutorch/models/vertical_ocr/VerticalOCR.h b/packages/react-native-executorch/common/rnexecutorch/models/vertical_ocr/VerticalOCR.h index f9f70f2d9..8395b3457 100644 --- a/packages/react-native-executorch/common/rnexecutorch/models/vertical_ocr/VerticalOCR.h +++ b/packages/react-native-executorch/common/rnexecutorch/models/vertical_ocr/VerticalOCR.h @@ -50,7 +50,8 @@ class VerticalOCR final { const std::string &recognizerSource, std::string symbols, bool indpendentCharacters, std::shared_ptr callInvoker); - std::vector generate(std::string input); + [[nodiscard("Registered non-void function")]] std::vector + generate(std::string input); std::size_t getMemoryLowerBound() const noexcept; void unload() noexcept;