Skip to content

Commit fafd11f

Browse files
authored
Set inputs directly in Module. (#13228)
Summary: . Differential Revision: D79900450
1 parent e93c139 commit fafd11f

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,21 @@ - (nullable ExecuTorchMethodMetadata *)methodMetadata:(NSString *)methodName
331331
- (nullable NSArray<ExecuTorchValue *> *)executeMethod:(NSString *)methodName
332332
withInputs:(NSArray<ExecuTorchValue *> *)values
333333
error:(NSError **)error {
334-
std::vector<EValue> inputs;
335-
inputs.reserve(values.count);
336-
for (ExecuTorchValue *value in values) {
337-
inputs.push_back(toEValue(value));
334+
const char *methodNameString = methodName.UTF8String;
335+
__block auto errorCode = Error::Ok;
336+
[values enumerateObjectsUsingBlock:^(ExecuTorchValue *value, NSUInteger index, BOOL *stop) {
337+
errorCode = _module->set_input(methodNameString, toEValue(value), index);
338+
if (errorCode != Error::Ok) {
339+
*stop = YES;
340+
}
341+
}];
342+
if (errorCode != Error::Ok) {
343+
if (error) {
344+
*error = ExecuTorchErrorWithCode((ExecuTorchErrorCode)errorCode);
345+
}
346+
return nil;
338347
}
339-
const auto result = _module->execute(methodName.UTF8String, inputs);
348+
const auto result = _module->execute(methodNameString);
340349
if (!result.ok()) {
341350
if (error) {
342351
*error = ExecuTorchErrorWithCode((ExecuTorchErrorCode)result.error());

0 commit comments

Comments
 (0)