Skip to content

Commit 3d0b1af

Browse files
Franco Melonifacebook-github-bot
Franco Meloni
authored andcommitted
Add floatValue to ExecuTorch value (#10823)
Summary: I think we can have an utility to return floats back. I would not create a new tag, but just use the double value and return it as float if the user needs float Reviewed By: shoumikhin Differential Revision: D74603334
1 parent f8e7264 commit 3d0b1af

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

extension/apple/ExecuTorch/Exported/ExecuTorchValue.h

+16
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ typedef NSInteger ExecuTorchIntegerValue
4040
NS_SWIFT_BRIDGED_TYPEDEF NS_SWIFT_NAME(IntegerValue);
4141
typedef double ExecuTorchDoubleValue
4242
NS_SWIFT_BRIDGED_TYPEDEF NS_SWIFT_NAME(DoubleValue);
43+
typedef float ExecuTorchFloatValue
44+
NS_SWIFT_BRIDGED_TYPEDEF NS_SWIFT_NAME(FloatValue);
4345

4446
/**
4547
* A dynamic value type used by ExecuTorch.
@@ -100,6 +102,13 @@ __attribute__((deprecated("This API is experimental.")))
100102
*/
101103
@property(nonatomic, readonly) ExecuTorchDoubleValue doubleValue NS_SWIFT_NAME(double);
102104

105+
/**
106+
* The float value if the tag is ExecuTorchValueTagDouble.
107+
*
108+
* @return An float representing the float value.
109+
*/
110+
@property(nonatomic, readonly) ExecuTorchFloatValue floatValue NS_SWIFT_NAME(float);
111+
103112
/**
104113
* Returns YES if the value is of type None.
105114
*
@@ -149,6 +158,13 @@ __attribute__((deprecated("This API is experimental.")))
149158
*/
150159
@property(nonatomic, readonly) BOOL isDouble;
151160

161+
/**
162+
* Returns YES if the value is a float.
163+
*
164+
* @return A BOOL indicating whether the value is a float.
165+
*/
166+
@property(nonatomic, readonly) BOOL isFloat;
167+
152168
/**
153169
* Creates an instance encapsulating a Tensor.
154170
*

extension/apple/ExecuTorch/Exported/ExecuTorchValue.mm

+10
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ - (ExecuTorchDoubleValue)doubleValue {
8888
return [(ExecuTorchScalarValue)_value doubleValue];
8989
}
9090

91+
- (ExecuTorchFloatValue)floatValue {
92+
ET_CHECK(self.isFloat);
93+
// EValue does not have a separate tag for float.
94+
return [(ExecuTorchScalarValue)_value floatValue];
95+
}
96+
9197
- (BOOL)isNone {
9298
return _tag == ExecuTorchValueTagNone;
9399
}
@@ -118,6 +124,10 @@ - (BOOL)isDouble {
118124
return _tag == ExecuTorchValueTagDouble;
119125
}
120126

127+
- (BOOL)isFloat {
128+
return _tag == ExecuTorchValueTagDouble;
129+
}
130+
121131
- (BOOL)isEqualToValue:(nullable ExecuTorchValue *)other {
122132
if (!other) {
123133
return NO;

0 commit comments

Comments
 (0)