From 3710e2ad3ddaa652a11107b3c46616779aae3e74 Mon Sep 17 00:00:00 2001 From: Anthony Shoumikhin Date: Wed, 26 Mar 2025 20:44:38 -0700 Subject: [PATCH] Handle more Value types in Module. Summary: https://github.com/pytorch/executorch/issues/8363 Reviewed By: bsoyluoglu Differential Revision: D71936820 --- .../ExecuTorch/Exported/ExecuTorchModule.mm | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm b/extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm index 2e37cd30484..8cdf61b26e8 100644 --- a/extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm @@ -24,6 +24,15 @@ static inline EValue toEValue(ExecuTorchValue *value) { ET_CHECK(nativeTensor); return *nativeTensor; } + if (value.isDouble) { + return EValue(value.doubleValue); + } + if (value.isInteger) { + return EValue(static_cast(value.intValue)); + } + if (value.isBoolean) { + return EValue(value.boolValue); + } ET_CHECK_MSG(false, "Unsupported ExecuTorchValue type"); return EValue(); } @@ -33,6 +42,22 @@ static inline EValue toEValue(ExecuTorchValue *value) { auto nativeInstance = make_tensor_ptr(value.toTensor()); return [ExecuTorchValue valueWithTensor:[[ExecuTorchTensor alloc] initWithNativeInstance:&nativeInstance]]; } + if (value.isDouble()) { + return [ExecuTorchValue valueWithDouble:value.toDouble()]; + } + if (value.isInt()) { + return [ExecuTorchValue valueWithInteger:value.toInt()]; + } + if (value.isBool()) { + return [ExecuTorchValue valueWithBoolean:value.toBool()]; + } + if (value.isString()) { + const auto stringView = value.toString(); + NSString *string = [[NSString alloc] initWithBytes:stringView.data() + length:stringView.size() + encoding:NSUTF8StringEncoding]; + return [ExecuTorchValue valueWithString:string]; + } ET_CHECK_MSG(false, "Unsupported EValue type"); return [ExecuTorchValue new]; }