Skip to content

Commit 1bdee96

Browse files
Value default initializer. (#9681)
Summary: #8364 Differential Revision: D71913869 --------- Co-authored-by: Anthony Shoumikhin <[email protected]>
1 parent 79743c9 commit 1bdee96

File tree

4 files changed

+67
-14
lines changed

4 files changed

+67
-14
lines changed

extension/apple/ExecuTorch/Exported/ExecuTorchValue.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,30 @@ typedef NS_ENUM(uint32_t, ExecuTorchValueTag) {
3030
ExecuTorchValueTagOptionalTensorList,
3131
} NS_SWIFT_NAME(ValueTag);
3232

33+
/**
34+
* A dynamic value type used by ExecuTorch.
35+
*
36+
* ExecuTorchValue encapsulates a value that may be of various types such as
37+
* a tensor or a scalar. The value’s type is indicated by its tag.
38+
*/
3339
NS_SWIFT_NAME(Value)
3440
__attribute__((deprecated("This API is experimental.")))
3541
@interface ExecuTorchValue : NSObject
3642

43+
/**
44+
* The tag that indicates the dynamic type of the value.
45+
*
46+
* @return An ExecuTorchValueTag value.
47+
*/
48+
@property(nonatomic, readonly) ExecuTorchValueTag tag;
49+
50+
/**
51+
* Returns YES if the value is of type None.
52+
*
53+
* @return A BOOL indicating whether the value is None.
54+
*/
55+
@property(nonatomic, readonly) BOOL isNone;
56+
3757
@end
3858

3959
NS_ASSUME_NONNULL_END

extension/apple/ExecuTorch/Exported/ExecuTorchValue.m

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
#import "ExecuTorchValue.h"
10+
11+
@interface ExecuTorchValue ()
12+
13+
- (instancetype)initWithTag:(ExecuTorchValueTag)tag
14+
value:(nullable id)value NS_DESIGNATED_INITIALIZER;
15+
16+
@end
17+
18+
@implementation ExecuTorchValue {
19+
ExecuTorchValueTag _tag;
20+
id _value;
21+
}
22+
23+
- (instancetype)init {
24+
return [self initWithTag:ExecuTorchValueTagNone value:nil];
25+
}
26+
27+
- (instancetype)initWithTag:(ExecuTorchValueTag)tag
28+
value:(nullable id)value {
29+
if (self = [super init]) {
30+
_tag = tag;
31+
_value = value;
32+
}
33+
return self;
34+
}
35+
36+
- (ExecuTorchValueTag)tag {
37+
return _tag;
38+
}
39+
40+
- (BOOL)isNone {
41+
return _tag == ExecuTorchValueTagNone;
42+
}
43+
44+
@end

extension/apple/ExecuTorch/__tests__/ValueTest.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import XCTest
1212

1313
class ValueTest: XCTestCase {
14-
func test() {
14+
func testNone() {
15+
let value = Value()
16+
XCTAssertTrue(value.isNone)
1517
}
1618
}

0 commit comments

Comments
 (0)