From a73663f19ae42129065a38b734074b477097ba44 Mon Sep 17 00:00:00 2001 From: Berker Soyluoglu Date: Fri, 16 May 2025 17:33:05 -0700 Subject: [PATCH] Add copy API to ExecuTorchValue Summary: Add copy API to ExecuTorchValue Reviewed By: shoumikhin Differential Revision: D74920022 --- extension/apple/ExecuTorch/Exported/ExecuTorchValue.h | 8 +++++++- extension/apple/ExecuTorch/Exported/ExecuTorchValue.mm | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h b/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h index f95fa48210a..a205c154a20 100644 --- a/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h @@ -50,7 +50,7 @@ typedef float ExecuTorchFloatValue */ NS_SWIFT_NAME(Value) __attribute__((deprecated("This API is experimental."))) -@interface ExecuTorchValue : NSObject +@interface ExecuTorchValue : NSObject /** * The tag that indicates the dynamic type of the value. @@ -208,6 +208,12 @@ __attribute__((deprecated("This API is experimental."))) + (instancetype)valueWithDouble:(ExecuTorchDoubleValue)value NS_SWIFT_NAME(init(_:)); +/** + * Returns a copy of the value. + * + * @return A new ExecuTorchValue instance that is a duplicate of the current value. + */ + - (instancetype)copy; /** * Determines whether the current Value is equal to another Value. diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchValue.mm b/extension/apple/ExecuTorch/Exported/ExecuTorchValue.mm index 3475d679e5e..a335f67a99a 100644 --- a/extension/apple/ExecuTorch/Exported/ExecuTorchValue.mm +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchValue.mm @@ -57,6 +57,15 @@ - (instancetype)initWithTag:(ExecuTorchValueTag)tag return self; } +- (instancetype)copy { + return [self copyWithZone:nil]; +} + +- (instancetype)copyWithZone:(nullable NSZone *)zone { + return [[ExecuTorchValue allocWithZone:zone] initWithTag:_tag + value:[_value copyWithZone:zone]]; +} + - (ExecuTorchValueTag)tag { return _tag; }