Skip to content

Commit 7bde4c4

Browse files
authored
Add valueWithFloat API.
Differential Revision: D76482176 Pull Request resolved: #11627
1 parent e7108dd commit 7bde4c4

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

extension/apple/ExecuTorch/Exported/ExecuTorchValue.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ __attribute__((deprecated("This API is experimental.")))
158158
@property(nonatomic, readonly) BOOL isDouble;
159159

160160
/**
161-
* Returns YES if the value is a float.
161+
* Returns YES if the value's tag is Double.
162+
*
163+
* Note: Since float values are stored with a Double tag, this property will
164+
* also be YES for values created from floats.
162165
*
163166
* @return A BOOL indicating whether the value is a float.
164167
*/
@@ -208,6 +211,18 @@ __attribute__((deprecated("This API is experimental.")))
208211
+ (instancetype)valueWithDouble:(ExecuTorchDoubleValue)value
209212
NS_SWIFT_NAME(init(_:));
210213

214+
/**
215+
* Creates an instance encapsulating a float value.
216+
*
217+
* Note: The underlying value will be stored with a tag of
218+
* ExecuTorchValueTagDouble, as there is no distinct float tag.
219+
*
220+
* @param value A float value.
221+
* @return A new ExecuTorchValue instance with a tag of ExecuTorchValueTagDouble.
222+
*/
223+
+ (instancetype)valueWithFloat:(ExecuTorchFloatValue)value
224+
NS_SWIFT_NAME(init(_:));
225+
211226
/**
212227
* Creates an instance encapsulating a scalar value.
213228
*

extension/apple/ExecuTorch/Exported/ExecuTorchValue.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ + (instancetype)valueWithDouble:(ExecuTorchDoubleValue)value {
6868
value:@(value)];
6969
}
7070

71+
+ (instancetype)valueWithFloat:(ExecuTorchFloatValue)value {
72+
return [[ExecuTorchValue alloc] initWithTag:ExecuTorchValueTagDouble
73+
value:@(value)];
74+
}
75+
7176
+ (instancetype)valueWithScalar:(ExecuTorchScalarValue)value {
7277
return [[ExecuTorchValue alloc] initWithTag:deduceValueTag(value)
7378
value:value];

0 commit comments

Comments
 (0)