Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions extension/apple/ExecuTorch/Exported/ExecuTorchModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,49 @@ __attribute__((deprecated("This API is experimental.")))
error:(NSError **)error
NS_SWIFT_NAME(execute(_:_:));

/**
* Executes a specific method with the provided single input value.
*
* The method is loaded on demand if not already loaded.
*
* @param methodName A string representing the method name.
* @param value An ExecuTorchValue object representing the input.
* @param error A pointer to an NSError pointer that is set if an error occurs.
* @return An NSArray of ExecuTorchValue objects representing the outputs, or nil in case of an error.
*/
- (nullable NSArray<ExecuTorchValue *> *)executeMethod:(NSString *)methodName
withInput:(ExecuTorchValue *)value
error:(NSError **)error
NS_SWIFT_NAME(execute(_:_:));

/**
* Executes a specific method with no input values.
*
* The method is loaded on demand if not already loaded.
*
* @param methodName A string representing the method name.
* @param error A pointer to an NSError pointer that is set if an error occurs.
* @return An NSArray of ExecuTorchValue objects representing the outputs, or nil in case of an error.
*/
- (nullable NSArray<ExecuTorchValue *> *)executeMethod:(NSString *)methodName
error:(NSError **)error
NS_SWIFT_NAME(execute(_:));

/**
* Executes a specific method with the provided input tensors.
*
* The method is loaded on demand if not already loaded.
*
* @param methodName A string representing the method name.
* @param tensors An NSArray of ExecuTorchTensor objects representing the inputs.
* @param error A pointer to an NSError pointer that is set if an error occurs.
* @return An NSArray of ExecuTorchValue objects representing the outputs, or nil in case of an error.
*/
- (nullable NSArray<ExecuTorchValue *> *)executeMethod:(NSString *)methodName
withTensors:(NSArray<ExecuTorchTensor *> *)tensors
error:(NSError **)error
NS_SWIFT_NAME(execute(_:_:));

+ (instancetype)new NS_UNAVAILABLE;
- (instancetype)init NS_UNAVAILABLE;

Expand Down
27 changes: 27 additions & 0 deletions extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,31 @@ - (BOOL)isMethodLoaded:(NSString *)methodName {
return outputs;
}

- (nullable NSArray<ExecuTorchValue *> *)executeMethod:(NSString *)methodName
withInput:(ExecuTorchValue *)value
error:(NSError **)error {
return [self executeMethod:methodName
withInputs:@[value]
error:error];
}

- (nullable NSArray<ExecuTorchValue *> *)executeMethod:(NSString *)methodName
error:(NSError **)error {
return [self executeMethod:methodName
withInputs:@[]
error:error];
}

- (nullable NSArray<ExecuTorchValue *> *)executeMethod:(NSString *)methodName
withTensors:(NSArray<ExecuTorchTensor *> *)tensors
error:(NSError **)error {
NSMutableArray<ExecuTorchValue *> *values = [NSMutableArray arrayWithCapacity:tensors.count];
for (ExecuTorchTensor *tensor in tensors) {
[values addObject:[ExecuTorchValue valueWithTensor:tensor]];
}
return [self executeMethod:methodName
withInputs:values
error:error];
}

@end
2 changes: 1 addition & 1 deletion extension/apple/ExecuTorch/__tests__/ModuleTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ModuleTest: XCTestCase {
let inputTensor = inputData.withUnsafeMutableBytes {
Tensor(bytesNoCopy: $0.baseAddress!, shape:[1], dataType: .float)
}
let inputs = [Value(inputTensor), Value(inputTensor)]
let inputs = [inputTensor, inputTensor]
var outputs: [Value]?
XCTAssertNoThrow(outputs = try module.execute("forward", inputs))
var outputData: [Float] = [2.0]
Expand Down
Loading