diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h b/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h index a477d7d6f09..1554132e929 100644 --- a/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h @@ -40,6 +40,8 @@ typedef NSInteger ExecuTorchIntegerValue NS_SWIFT_BRIDGED_TYPEDEF NS_SWIFT_NAME(IntegerValue); typedef double ExecuTorchDoubleValue NS_SWIFT_BRIDGED_TYPEDEF NS_SWIFT_NAME(DoubleValue); +typedef float ExecuTorchFloatValue + NS_SWIFT_BRIDGED_TYPEDEF NS_SWIFT_NAME(FloatValue); /** * A dynamic value type used by ExecuTorch. @@ -100,6 +102,13 @@ __attribute__((deprecated("This API is experimental."))) */ @property(nonatomic, readonly) ExecuTorchDoubleValue doubleValue NS_SWIFT_NAME(double); +/** + * The float value if the tag is ExecuTorchValueTagDouble. + * + * @return An float representing the float value. + */ + @property(nonatomic, readonly) ExecuTorchFloatValue floatValue NS_SWIFT_NAME(float); + /** * Returns YES if the value is of type None. * @@ -149,6 +158,13 @@ __attribute__((deprecated("This API is experimental."))) */ @property(nonatomic, readonly) BOOL isDouble; +/** + * Returns YES if the value is a float. + * + * @return A BOOL indicating whether the value is a float. + */ + @property(nonatomic, readonly) BOOL isFloat; + /** * Creates an instance encapsulating a Tensor. * diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchValue.mm b/extension/apple/ExecuTorch/Exported/ExecuTorchValue.mm index 4e5b07bcc36..3475d679e5e 100644 --- a/extension/apple/ExecuTorch/Exported/ExecuTorchValue.mm +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchValue.mm @@ -88,6 +88,11 @@ - (ExecuTorchDoubleValue)doubleValue { return [(ExecuTorchScalarValue)_value doubleValue]; } +- (ExecuTorchFloatValue)floatValue { + ET_CHECK(self.isFloat); + return [(ExecuTorchScalarValue)_value floatValue]; +} + - (BOOL)isNone { return _tag == ExecuTorchValueTagNone; } @@ -118,6 +123,11 @@ - (BOOL)isDouble { return _tag == ExecuTorchValueTagDouble; } +- (BOOL)isFloat { + // EValue does not have a separate tag for float. + return _tag == ExecuTorchValueTagDouble; +} + - (BOOL)isEqualToValue:(nullable ExecuTorchValue *)other { if (!other) { return NO;