Skip to content

Add floatValue to ExecuTorch value #10823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2025
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
16 changes: 16 additions & 0 deletions extension/apple/ExecuTorch/Exported/ExecuTorchValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down
10 changes: 10 additions & 0 deletions extension/apple/ExecuTorch/Exported/ExecuTorchValue.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
Loading