File tree 3 files changed +40
-0
lines changed
extension/apple/ExecuTorch 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -104,6 +104,17 @@ __attribute__((deprecated("This API is experimental.")))
104
104
*/
105
105
- (BOOL )isMethodLoaded:(NSString *)methodName NS_SWIFT_NAME (isLoaded(_:));
106
106
107
+ /* *
108
+ * Retrieves the set of method names available in the loaded program.
109
+ *
110
+ * The method names are returned as an unordered set of strings. The program and methods
111
+ * are loaded as needed.
112
+ *
113
+ * @param error A pointer to an NSError pointer that is set if an error occurs.
114
+ * @return An unordered set of method names, or nil in case of an error.
115
+ */
116
+ - (nullable NSSet <NSString *> *)methodNames:(NSError **)error;
117
+
107
118
+ (instancetype )new NS_UNAVAILABLE;
108
119
- (instancetype )init NS_UNAVAILABLE;
109
120
Original file line number Diff line number Diff line change @@ -77,4 +77,21 @@ - (BOOL)isMethodLoaded:(NSString *)methodName {
77
77
return _module->is_method_loaded (methodName.UTF8String );
78
78
}
79
79
80
+ - (nullable NSSet <NSString *> *)methodNames : (NSError **)error {
81
+ const auto result = _module->method_names ();
82
+ if (!result.ok ()) {
83
+ if (error) {
84
+ *error = [NSError errorWithDomain: ExecuTorchErrorDomain
85
+ code: (NSInteger )result.error ()
86
+ userInfo: nil ];
87
+ }
88
+ return nil ;
89
+ }
90
+ NSMutableSet <NSString *> *methods = [NSMutableSet setWithCapacity: result->size ()];
91
+ for (const auto &name : *result) {
92
+ [methods addObject: (NSString *)@(name.c_str ())];
93
+ }
94
+ return methods;
95
+ }
96
+
80
97
@end
Original file line number Diff line number Diff line change @@ -39,4 +39,16 @@ class ModuleTest: XCTestCase {
39
39
XCTAssertNoThrow ( try module. load ( " forward " ) )
40
40
XCTAssertTrue ( module. isLoaded ( " forward " ) )
41
41
}
42
+
43
+ func testMethodNames( ) {
44
+ let bundle = Bundle ( for: type ( of: self ) )
45
+ guard let modelPath = bundle. path ( forResource: " add " , ofType: " pte " ) else {
46
+ XCTFail ( " Couldn't find the model file " )
47
+ return
48
+ }
49
+ let module = Module ( filePath: modelPath)
50
+ var methodNames : Set < String > ?
51
+ XCTAssertNoThrow ( methodNames = try module. methodNames ( ) )
52
+ XCTAssertEqual ( methodNames, Set ( [ " forward " ] ) )
53
+ }
42
54
}
You can’t perform that action at this time.
0 commit comments