react-native-executorch 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/common/rnexecutorch/TokenizerModule.cpp +3 -2
  2. package/common/rnexecutorch/TokenizerModule.h +1 -1
  3. package/package.json +2 -1
  4. package/third-party/android/libs/executorch/arm64-v8a/libexecutorch.so +0 -0
  5. package/third-party/android/libs/executorch/x86_64/libexecutorch.so +0 -0
  6. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/bpe_model.h +84 -0
  7. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/bpe_tokenizer_base.h +6 -87
  8. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/hf_tokenizer.h +28 -176
  9. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/map_utils.h +174 -0
  10. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/model.h +151 -0
  11. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/normalizer.h +55 -1
  12. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/padding.h +112 -0
  13. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/post_processor.h +101 -42
  14. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/pre_tokenizer.h +25 -9
  15. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/token_decoder.h +33 -6
  16. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/tokenizer.h +2 -2
  17. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/truncation.h +92 -0
  18. package/third-party/include/executorch/extension/llm/tokenizers/include/pytorch/tokenizers/wordpiece_model.h +74 -0
  19. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/ExecutorchLib +0 -0
  20. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/ExecutorchLib +0 -0
  21. package/common/rnexecutorch/tests/CMakeLists.txt +0 -253
  22. package/common/rnexecutorch/tests/README.md +0 -73
  23. package/common/rnexecutorch/tests/integration/BaseModelTest.cpp +0 -207
  24. package/common/rnexecutorch/tests/integration/BaseModelTests.h +0 -120
  25. package/common/rnexecutorch/tests/integration/ClassificationTest.cpp +0 -117
  26. package/common/rnexecutorch/tests/integration/ImageEmbeddingsTest.cpp +0 -122
  27. package/common/rnexecutorch/tests/integration/ImageSegmentationTest.cpp +0 -152
  28. package/common/rnexecutorch/tests/integration/LLMTest.cpp +0 -155
  29. package/common/rnexecutorch/tests/integration/OCRTest.cpp +0 -128
  30. package/common/rnexecutorch/tests/integration/ObjectDetectionTest.cpp +0 -135
  31. package/common/rnexecutorch/tests/integration/SpeechToTextTest.cpp +0 -97
  32. package/common/rnexecutorch/tests/integration/StyleTransferTest.cpp +0 -112
  33. package/common/rnexecutorch/tests/integration/TextEmbeddingsTest.cpp +0 -164
  34. package/common/rnexecutorch/tests/integration/TextToImageTest.cpp +0 -149
  35. package/common/rnexecutorch/tests/integration/TokenizerModuleTest.cpp +0 -98
  36. package/common/rnexecutorch/tests/integration/VerticalOCRTest.cpp +0 -238
  37. package/common/rnexecutorch/tests/integration/VoiceActivityDetectionTest.cpp +0 -99
  38. package/common/rnexecutorch/tests/integration/assets/test_audio_float.raw +0 -0
  39. package/common/rnexecutorch/tests/integration/assets/we_are_software_mansion.jpg +0 -0
  40. package/common/rnexecutorch/tests/integration/libs/libfbjni.so +0 -0
  41. package/common/rnexecutorch/tests/integration/stubs/jsi_stubs.cpp +0 -45
  42. package/common/rnexecutorch/tests/integration/utils/TestUtils.h +0 -36
  43. package/common/rnexecutorch/tests/run_tests.sh +0 -333
  44. package/common/rnexecutorch/tests/unit/FileUtilsTest.cpp +0 -32
  45. package/common/rnexecutorch/tests/unit/LogTest.cpp +0 -529
  46. package/common/rnexecutorch/tests/unit/NumericalTest.cpp +0 -107
@@ -13,8 +13,8 @@
13
13
 
14
14
  #pragma once
15
15
 
16
- #include "error.h"
17
- #include "result.h"
16
+ #include <pytorch/tokenizers/error.h>
17
+ #include <pytorch/tokenizers/result.h>
18
18
  #include <string>
19
19
  #include <vector>
20
20
 
@@ -0,0 +1,92 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ // @lint-ignore-every LICENSELINT
9
+
10
+ #pragma once
11
+
12
+ // Standard
13
+ #include <memory>
14
+ #include <optional>
15
+ #include <string>
16
+ #include <vector>
17
+
18
+ // Third Party
19
+ #include <nlohmann/json.hpp>
20
+
21
+ namespace tokenizers {
22
+
23
+ // -- Truncation ---------------------------------------------------------------
24
+
25
+ enum class TruncationStrategy {
26
+ LongestFirst,
27
+ OnlyFirst,
28
+ OnlySecond,
29
+ };
30
+
31
+ enum class TruncationDirection {
32
+ Left,
33
+ Right,
34
+ };
35
+
36
+ struct TruncationParams {
37
+ TruncationDirection direction = TruncationDirection::Right;
38
+ size_t max_length = 512;
39
+ TruncationStrategy strategy = TruncationStrategy::LongestFirst;
40
+ size_t stride = 0;
41
+ };
42
+
43
+ class Truncation {
44
+ public:
45
+ /** Shared pointer type */
46
+ typedef std::shared_ptr<Truncation> Ptr;
47
+
48
+ /**
49
+ * @param params: The truncation parameters
50
+ */
51
+ explicit Truncation(const TruncationParams &params);
52
+
53
+ /**
54
+ * Truncate the tokens according to the configuration.
55
+ *
56
+ * @param tokens The tokens to truncate.
57
+ * @param num_tokens_to_add The number of special tokens that will be added
58
+ * later. These are subtracted from max_length during truncation calculation.
59
+ */
60
+ std::vector<uint64_t> truncate(std::vector<uint64_t> tokens,
61
+ size_t num_tokens_to_add = 0) const;
62
+
63
+ /**
64
+ * Truncate a pair of sequences according to the configuration.
65
+ */
66
+ std::pair<std::vector<uint64_t>, std::vector<uint64_t>>
67
+ truncate_pair(std::vector<uint64_t> a, std::vector<uint64_t> b,
68
+ size_t num_tokens_to_add = 0) const;
69
+
70
+ private:
71
+ TruncationParams params_;
72
+ };
73
+
74
+ // -- Factory ------------------------------------------------------------------
75
+
76
+ class TruncationConfig {
77
+ public:
78
+ /**
79
+ * Construct the truncation instance from the member data
80
+ */
81
+ Truncation::Ptr create() const;
82
+
83
+ /**
84
+ * Populate from a json config file
85
+ */
86
+ TruncationConfig &parse_json(const nlohmann::json &json_config);
87
+
88
+ // Configuration members
89
+ TruncationParams params;
90
+ };
91
+
92
+ } // namespace tokenizers
@@ -0,0 +1,74 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ // @lint-ignore-every LICENSELINT
9
+
10
+ #pragma once
11
+
12
+ #include <memory>
13
+ #include <optional>
14
+ #include <string>
15
+ #include <vector>
16
+
17
+ #include <pytorch/tokenizers/model.h>
18
+ #include <pytorch/tokenizers/regex.h>
19
+ #include <pytorch/tokenizers/result.h>
20
+ #include <pytorch/tokenizers/string_integer_map.h>
21
+
22
+ namespace tokenizers {
23
+
24
+ class WordPieceModel : public Model {
25
+ public:
26
+ explicit WordPieceModel(detail::TokenMap token_map,
27
+ detail::TokenMap special_token_map,
28
+ std::string unk_token,
29
+ std::string continuing_subword_prefix,
30
+ size_t max_input_chars_per_word,
31
+ std::optional<uint64_t> unk_token_id,
32
+ std::optional<uint64_t> bos_token_id,
33
+ std::optional<uint64_t> eos_token_id);
34
+
35
+ ~WordPieceModel() override = default;
36
+
37
+ Result<std::vector<uint64_t>>
38
+ tokenize(const std::string &piece) const override;
39
+
40
+ Result<std::string> id_to_piece(uint64_t token) const override;
41
+ Result<uint64_t> piece_to_id(const std::string &token) const override;
42
+
43
+ int32_t vocab_size() const override { return vocab_size_; }
44
+
45
+ bool is_special_token(uint64_t token) const override;
46
+
47
+ bool is_loaded() const override { return initialized_; }
48
+
49
+ std::pair<std::optional<std::string>, std::string>
50
+ split_with_allowed_special_token(const std::string &input,
51
+ size_t offset) const override;
52
+
53
+ uint64_t bos_token_id() const override { return bos_token_id_.value_or(0); }
54
+
55
+ uint64_t eos_token_id() const override { return eos_token_id_.value_or(0); }
56
+
57
+ private:
58
+ detail::TokenMap token_map_;
59
+ detail::TokenMap special_token_map_;
60
+ std::unique_ptr<IRegex> special_token_regex_;
61
+
62
+ std::string unk_token_;
63
+ std::string continuing_subword_prefix_;
64
+ size_t max_input_chars_per_word_;
65
+
66
+ std::optional<uint64_t> unk_token_id_;
67
+ std::optional<uint64_t> bos_token_id_;
68
+ std::optional<uint64_t> eos_token_id_;
69
+
70
+ bool initialized_ = false;
71
+ int32_t vocab_size_ = 0;
72
+ };
73
+
74
+ } // namespace tokenizers
@@ -1,253 +0,0 @@
1
- if(NOT ANDROID_ABI)
2
- message(FATAL_ERROR "Tests can be only built for Android simulator")
3
- endif()
4
-
5
- cmake_minimum_required(VERSION 3.13)
6
- project(RNExecutorchTests)
7
-
8
- set(CMAKE_CXX_STANDARD 20)
9
- set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
10
-
11
- # tests/ <- CMAKE_SOURCE_DIR (this file's location)
12
- # rnexecutorch/ <- RNEXECUTORCH_DIR (parent of tests)
13
- # common/ <- COMMON_DIR
14
- # react-native-executorch/ <- PACKAGE_ROOT
15
- # <monorepo-root>/ <- MONOREPO_ROOT
16
- # <monorepo-root>/third-party/ <- THIRD_PARTY_DIR
17
- set(RNEXECUTORCH_DIR "${CMAKE_SOURCE_DIR}/..")
18
- set(COMMON_DIR "${RNEXECUTORCH_DIR}/..")
19
- set(PACKAGE_ROOT "${COMMON_DIR}/..")
20
- set(MONOREPO_ROOT "${PACKAGE_ROOT}/../..")
21
- set(THIRD_PARTY_DIR "${MONOREPO_ROOT}/third-party")
22
- set(REACT_NATIVE_DIR "${MONOREPO_ROOT}/node_modules/react-native")
23
- set(ANDROID_THIRD_PARTY "${PACKAGE_ROOT}/third-party/android/libs/")
24
- set(TOKENIZERS_DIR "${PACKAGE_ROOT}/third-party/include/executorch/extension/llm/tokenizers/include")
25
-
26
- # Add Gtest as a subdirectory
27
- add_subdirectory(${THIRD_PARTY_DIR}/googletest ${PROJECT_BINARY_DIR}/googletest)
28
-
29
- # ExecuTorch Prebuilt binaries
30
- add_library(executorch_prebuilt SHARED IMPORTED)
31
- set_target_properties(executorch_prebuilt PROPERTIES
32
- IMPORTED_LOCATION "${ANDROID_THIRD_PARTY}/executorch/${ANDROID_ABI}/libexecutorch.so"
33
- )
34
-
35
- # pthreadpool and cpuinfo (needed for OpenMP/OpenCV)
36
- if(ANDROID_ABI STREQUAL "arm64-v8a")
37
- add_library(pthreadpool SHARED IMPORTED)
38
- set_target_properties(pthreadpool PROPERTIES
39
- IMPORTED_LOCATION "${ANDROID_THIRD_PARTY}/pthreadpool/${ANDROID_ABI}/libpthreadpool.so"
40
- )
41
-
42
- add_library(cpuinfo SHARED IMPORTED)
43
- set_target_properties(cpuinfo PROPERTIES
44
- IMPORTED_LOCATION "${ANDROID_THIRD_PARTY}/cpuinfo/${ANDROID_ABI}/libcpuinfo.so"
45
- )
46
-
47
- set(EXECUTORCH_LIBS pthreadpool cpuinfo)
48
- else()
49
- set(EXECUTORCH_LIBS "")
50
- endif()
51
-
52
- # OpenCV (Interface Library)
53
- set(OPENCV_LIBS_DIR "${ANDROID_THIRD_PARTY}/opencv/${ANDROID_ABI}")
54
- set(OPENCV_THIRD_PARTY_DIR "${ANDROID_THIRD_PARTY}/opencv-third-party/${ANDROID_ABI}")
55
-
56
- if(ANDROID_ABI STREQUAL "arm64-v8a")
57
- set(OPENCV_THIRD_PARTY_LIBS
58
- "${OPENCV_THIRD_PARTY_DIR}/libkleidicv_hal.a"
59
- "${OPENCV_THIRD_PARTY_DIR}/libkleidicv_thread.a"
60
- "${OPENCV_THIRD_PARTY_DIR}/libkleidicv.a"
61
- )
62
- elseif(ANDROID_ABI STREQUAL "x86_64")
63
- set(OPENCV_THIRD_PARTY_LIBS "")
64
- endif()
65
-
66
-
67
- add_library(opencv_deps INTERFACE)
68
- target_link_libraries(opencv_deps INTERFACE
69
- ${OPENCV_LIBS_DIR}/libopencv_core.a
70
- ${OPENCV_LIBS_DIR}/libopencv_features2d.a
71
- ${OPENCV_LIBS_DIR}/libopencv_highgui.a
72
- ${OPENCV_LIBS_DIR}/libopencv_imgproc.a
73
- ${OPENCV_LIBS_DIR}/libopencv_photo.a
74
- ${OPENCV_LIBS_DIR}/libopencv_video.a
75
- ${OPENCV_THIRD_PARTY_LIBS}
76
- ${EXECUTORCH_LIBS}
77
- z
78
- dl
79
- m
80
- log
81
- )
82
- target_link_options(opencv_deps INTERFACE -fopenmp -static-openmp)
83
-
84
- add_library(tokenizers_deps INTERFACE)
85
- target_include_directories(tokenizers_deps INTERFACE "${TOKENIZERS_DIR}")
86
-
87
- # Source Definitions
88
- set(CORE_SOURCES
89
- ${RNEXECUTORCH_DIR}/models/BaseModel.cpp
90
- ${RNEXECUTORCH_DIR}/data_processing/Numerical.cpp
91
- ${CMAKE_SOURCE_DIR}/integration/stubs/jsi_stubs.cpp
92
- )
93
-
94
- set(IMAGE_UTILS_SOURCES
95
- ${RNEXECUTORCH_DIR}/data_processing/ImageProcessing.cpp
96
- ${RNEXECUTORCH_DIR}/data_processing/base64.cpp
97
- ${COMMON_DIR}/ada/ada.cpp
98
- )
99
-
100
- set(TOKENIZER_SOURCES ${RNEXECUTORCH_DIR}/TokenizerModule.cpp)
101
- set(DSP_SOURCES ${RNEXECUTORCH_DIR}/data_processing/dsp.cpp)
102
-
103
- # Core Library
104
- add_library(rntests_core STATIC ${CORE_SOURCES})
105
-
106
- target_include_directories(rntests_core PUBLIC
107
- ${RNEXECUTORCH_DIR}/data_processing
108
- ${TOKENIZERS_DIR}
109
- ${RNEXECUTORCH_DIR}
110
- ${COMMON_DIR}
111
- ${PACKAGE_ROOT}/third-party/include
112
- ${REACT_NATIVE_DIR}/ReactCommon
113
- ${REACT_NATIVE_DIR}/ReactCommon/jsi
114
- ${REACT_NATIVE_DIR}/ReactCommon/callinvoker
115
- ${COMMON_DIR}/ada
116
- )
117
-
118
- target_link_libraries(rntests_core PUBLIC
119
- executorch_prebuilt
120
- gtest
121
- log
122
- )
123
-
124
- enable_testing()
125
- function(add_rn_test TEST_TARGET TEST_FILENAME)
126
- cmake_parse_arguments(ARG "" "" "SOURCES;LIBS" ${ARGN})
127
- # Create executable using the explicit filename provided
128
- add_executable(${TEST_TARGET} ${TEST_FILENAME} ${ARG_SOURCES})
129
-
130
- target_compile_definitions(${TEST_TARGET} PRIVATE TEST_BUILD)
131
- target_link_libraries(${TEST_TARGET} PRIVATE rntests_core gtest_main ${ARG_LIBS})
132
- target_link_options(${TEST_TARGET} PRIVATE "LINKER:-z,max-page-size=16384")
133
-
134
- add_test(NAME ${TEST_TARGET} COMMAND ${TEST_TARGET})
135
- endfunction()
136
-
137
- add_rn_test(NumericalTests unit/NumericalTest.cpp)
138
- add_rn_test(LogTests unit/LogTest.cpp)
139
- add_rn_test(BaseModelTests integration/BaseModelTest.cpp)
140
-
141
- add_rn_test(ClassificationTests integration/ClassificationTest.cpp
142
- SOURCES
143
- ${RNEXECUTORCH_DIR}/models/classification/Classification.cpp
144
- ${IMAGE_UTILS_SOURCES}
145
- LIBS opencv_deps
146
- )
147
-
148
- add_rn_test(ObjectDetectionTests integration/ObjectDetectionTest.cpp
149
- SOURCES
150
- ${RNEXECUTORCH_DIR}/models/object_detection/ObjectDetection.cpp
151
- ${RNEXECUTORCH_DIR}/models/object_detection/Utils.cpp
152
- ${IMAGE_UTILS_SOURCES}
153
- LIBS opencv_deps
154
- )
155
-
156
- add_rn_test(ImageEmbeddingsTests integration/ImageEmbeddingsTest.cpp
157
- SOURCES
158
- ${RNEXECUTORCH_DIR}/models/embeddings/image/ImageEmbeddings.cpp
159
- ${RNEXECUTORCH_DIR}/models/embeddings/BaseEmbeddings.cpp
160
- ${IMAGE_UTILS_SOURCES}
161
- LIBS opencv_deps
162
- )
163
-
164
- add_rn_test(TextEmbeddingsTests integration/TextEmbeddingsTest.cpp
165
- SOURCES
166
- ${RNEXECUTORCH_DIR}/models/embeddings/text/TextEmbeddings.cpp
167
- ${RNEXECUTORCH_DIR}/models/embeddings/BaseEmbeddings.cpp
168
- ${TOKENIZER_SOURCES}
169
- LIBS tokenizers_deps
170
- )
171
-
172
- add_rn_test(StyleTransferTests integration/StyleTransferTest.cpp
173
- SOURCES
174
- ${RNEXECUTORCH_DIR}/models/style_transfer/StyleTransfer.cpp
175
- ${IMAGE_UTILS_SOURCES}
176
- LIBS opencv_deps
177
- )
178
-
179
- add_rn_test(VADTests integration/VoiceActivityDetectionTest.cpp
180
- SOURCES
181
- ${RNEXECUTORCH_DIR}/models/voice_activity_detection/VoiceActivityDetection.cpp
182
- ${RNEXECUTORCH_DIR}/models/voice_activity_detection/Utils.cpp
183
- ${DSP_SOURCES}
184
- )
185
-
186
- add_rn_test(TokenizerModuleTests integration/TokenizerModuleTest.cpp
187
- SOURCES ${TOKENIZER_SOURCES}
188
- LIBS tokenizers_deps
189
- )
190
-
191
- add_rn_test(SpeechToTextTests integration/SpeechToTextTest.cpp
192
- SOURCES
193
- ${RNEXECUTORCH_DIR}/models/speech_to_text/SpeechToText.cpp
194
- ${RNEXECUTORCH_DIR}/models/speech_to_text/asr/ASR.cpp
195
- ${RNEXECUTORCH_DIR}/models/speech_to_text/stream/HypothesisBuffer.cpp
196
- ${RNEXECUTORCH_DIR}/models/speech_to_text/stream/OnlineASRProcessor.cpp
197
- ${RNEXECUTORCH_DIR}/data_processing/gzip.cpp
198
- ${TOKENIZER_SOURCES}
199
- ${DSP_SOURCES}
200
- LIBS tokenizers_deps z
201
- )
202
-
203
- add_rn_test(LLMTests integration/LLMTest.cpp
204
- SOURCES
205
- ${RNEXECUTORCH_DIR}/models/llm/LLM.cpp
206
- ${COMMON_DIR}/runner/runner.cpp
207
- ${COMMON_DIR}/runner/text_prefiller.cpp
208
- ${COMMON_DIR}/runner/text_decoder_runner.cpp
209
- ${COMMON_DIR}/runner/sampler.cpp
210
- ${COMMON_DIR}/runner/arange_util.cpp
211
- LIBS tokenizers_deps
212
- )
213
-
214
- add_rn_test(TextToImageTests integration/TextToImageTest.cpp
215
- SOURCES
216
- ${RNEXECUTORCH_DIR}/models/text_to_image/TextToImage.cpp
217
- ${RNEXECUTORCH_DIR}/models/text_to_image/Encoder.cpp
218
- ${RNEXECUTORCH_DIR}/models/text_to_image/UNet.cpp
219
- ${RNEXECUTORCH_DIR}/models/text_to_image/Decoder.cpp
220
- ${RNEXECUTORCH_DIR}/models/text_to_image/Scheduler.cpp
221
- ${RNEXECUTORCH_DIR}/models/embeddings/text/TextEmbeddings.cpp
222
- ${RNEXECUTORCH_DIR}/models/embeddings/BaseEmbeddings.cpp
223
- ${TOKENIZER_SOURCES}
224
- LIBS tokenizers_deps
225
- )
226
-
227
- add_rn_test(OCRTests integration/OCRTest.cpp
228
- SOURCES
229
- ${RNEXECUTORCH_DIR}/models/ocr/OCR.cpp
230
- ${RNEXECUTORCH_DIR}/models/ocr/CTCLabelConverter.cpp
231
- ${RNEXECUTORCH_DIR}/models/ocr/Detector.cpp
232
- ${RNEXECUTORCH_DIR}/models/ocr/RecognitionHandler.cpp
233
- ${RNEXECUTORCH_DIR}/models/ocr/Recognizer.cpp
234
- ${RNEXECUTORCH_DIR}/models/ocr/utils/DetectorUtils.cpp
235
- ${RNEXECUTORCH_DIR}/models/ocr/utils/RecognitionHandlerUtils.cpp
236
- ${RNEXECUTORCH_DIR}/models/ocr/utils/RecognizerUtils.cpp
237
- ${IMAGE_UTILS_SOURCES}
238
- LIBS opencv_deps
239
- )
240
-
241
- add_rn_test(VerticalOCRTests integration/VerticalOCRTest.cpp
242
- SOURCES
243
- ${RNEXECUTORCH_DIR}/models/vertical_ocr/VerticalOCR.cpp
244
- ${RNEXECUTORCH_DIR}/models/vertical_ocr/VerticalDetector.cpp
245
- ${RNEXECUTORCH_DIR}/models/ocr/Detector.cpp
246
- ${RNEXECUTORCH_DIR}/models/ocr/CTCLabelConverter.cpp
247
- ${RNEXECUTORCH_DIR}/models/ocr/Recognizer.cpp
248
- ${RNEXECUTORCH_DIR}/models/ocr/utils/DetectorUtils.cpp
249
- ${RNEXECUTORCH_DIR}/models/ocr/utils/RecognitionHandlerUtils.cpp
250
- ${RNEXECUTORCH_DIR}/models/ocr/utils/RecognizerUtils.cpp
251
- ${IMAGE_UTILS_SOURCES}
252
- LIBS opencv_deps
253
- )
@@ -1,73 +0,0 @@
1
- ## Native Test
2
- This guide provide information on how functions are tested, how to install all needed dependencies and how to run tests.
3
-
4
- ### Used Tools
5
- To test the native code we use [`googletest`](https://github.com/google/googletest). It's a flexible tool for creating unit tests.
6
-
7
- ### Installation
8
- The googletest is already in repo in `react-native-executorch/third-party/googletest`. Firstly, you need to fetch googletest locally, run from root directory of project:
9
- * `git submodule update --init --recursive third-party/googletest`
10
-
11
- ### Running tests
12
-
13
- #### Prerequisites
14
-
15
- - **Android NDK**: The `ANDROID_NDK` environment variable must be set
16
- - **wget**: Must be in your PATH
17
- - **Android emulator**: Must be running before executing tests
18
- - **Device requirements**:
19
- - 16GB disk storage (minimum)
20
- - 8GB RAM (minimum)
21
-
22
- #### First-time setup
23
-
24
- Before running tests, you need to build an app to generate required native libraries (`libfbjni.so` and `libc++_shared.so`). The test script automatically searches for these in the monorepo.
25
-
26
- If the script reports missing libraries, build any example app:
27
- ```bash
28
- cd apps/computer-vision/android
29
- ./gradlew assembleDebug
30
- # or
31
- ./gradlew assembleRelease
32
- ```
33
-
34
- #### Running the tests
35
-
36
- Navigate to the tests directory:
37
- ```bash
38
- cd packages/react-native-executorch/common/rnexecutorch/tests
39
- ```
40
-
41
- Run the test script:
42
- ```bash
43
- bash ./run_tests.sh
44
- ```
45
-
46
- This script:
47
- - Downloads all needed models
48
- - Pushes executables, models, assets, and shared libraries via ADB to the running emulator
49
- - Runs the pre-compiled test executables
50
-
51
- #### Available flags
52
-
53
- * `--refresh-models` - Forcefully downloads all the models. By default, models are not downloaded unless they are missing from the specified directory.
54
- * `--skip-build` - Skips the cmake build step.
55
-
56
- ### How to add a new test
57
- To add new test you need to:
58
- * Add a new .cpp file to either integration/ or unit/, depending on the type of the test.
59
- * In `CMakeLists.txt`, add all executables and link all the needed libraries against the executable, for example you can use the `add_rn_test`, which is a helper function that links core libs. Example:
60
- ```cmake
61
- # unit
62
- add_rn_test(BaseModelTests integration/BaseModelTest.cpp)
63
-
64
- # integration
65
- add_rn_test(ClassificationTests integration/ClassificationTest.cpp
66
- SOURCES
67
- ${RNEXECUTORCH_DIR}/models/classification/Classification.cpp
68
- ${IMAGE_UTILS_SOURCES}
69
- LIBS opencv_deps
70
- )
71
- ```
72
- * Lastly, add the test executable name to the run_tests script along with all the needed URL and assets.
73
-