Skip to content
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

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
#import <executorch/extension/module/module.h>
#import <executorch/runtime/core/evalue.h>
#endif
#import <ModelRunnerDataKit/ModelRunnerDataKit-Swift.h>
#import <RuntimeBridgingCore/RuntimeBridgingCore-Swift.h>

NS_ASSUME_NONNULL_BEGIN

@interface ExecutorchRuntimeTensorValue : NSObject <ModelRuntimeTensorValueBridging>
@interface ExecutorchRuntimeTensorValue : NSObject

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
Expand All @@ -28,6 +28,9 @@ NS_ASSUME_NONNULL_BEGIN
- (torch::executor::Tensor)backedValue;
#endif

#pragma mark -
- (ModelRuntimeTensorValueBridgingTuple * _Nullable)floatRepresentationAndReturnError:(NSError * _Nullable * _Nullable)error SWIFT_WARN_UNUSED_RESULT;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
#import <executorch/runtime/core/evalue.h>
#endif

#import <ModelRunnerDataKit/ModelRunnerDataKit-Swift.h>
#import <RuntimeBridgingCore/RuntimeBridgingCore-Swift.h>

#import "ExecutorchRuntimeTensorValue.h"

NS_ASSUME_NONNULL_BEGIN

@interface ExecutorchRuntimeValue : NSObject <ModelRuntimeValueBridging>
@interface ExecutorchRuntimeValue : NSObject

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
Expand All @@ -29,6 +29,9 @@ NS_ASSUME_NONNULL_BEGIN
- (torch::executor::EValue)getBackedValue;
#endif

#pragma mark -
- (ExecutorchRuntimeTensorValue *_Nullable)asTensorValueAndReturnError:(NSError * _Nullable * _Nullable)error SWIFT_WARN_UNUSED_RESULT;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,7 @@ - (instancetype)initWithTensor:(ExecutorchRuntimeTensorValue *)tensorValue
return self;
}

- (nullable NSString *)stringValueAndReturnError:(NSError * _Nullable * _Nullable)error
{
if (error) {
*error = [ModelRuntimeValueErrorFactory unsupportedType:@"ExecutorchRuntimeValue doesn't support strings"];
}
return nil;
}

- (nullable id<ModelRuntimeTensorValueBridging>)tensorValueAndReturnError:(NSError * _Nullable * _Nullable)error
- (nullable ExecutorchRuntimeTensorValue *)asTensorValueAndReturnError:(NSError * _Nullable * _Nullable)error
{
if (_value.isTensor()) {
return [[ExecutorchRuntimeTensorValue alloc] initWithTensor:_value.toTensor() error:error];
Expand All @@ -68,12 +60,4 @@ - (EValue)getBackedValue
return _value;
}

- (NSArray<id<ModelRuntimeValueBridging>> *)arrayValueAndReturnError:(NSError * _Nullable * _Nullable)error
{
if (error) {
*error = [ModelRuntimeValueErrorFactory unsupportedType:@"EValue doesn't support arrays"];
}
return nil;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ - (void)testValidModel
XCTAssertEqual(output.count, 1);
NSError *tensorValueError = nil;
NSError *floatRepresentationError = nil;
const auto resultTensorValue = [[output.firstObject tensorValueAndReturnError:&tensorValueError]
const auto resultTensorValue = [[output.firstObject asTensorValueAndReturnError:&tensorValueError]
floatRepresentationAndReturnError:&floatRepresentationError];

XCTAssertNil(tensorValueError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#import <XCTest/XCTest.h>

#import <ExecutorchRuntimeBridge/ExecutorchRuntimeValue.h>
#import <ModelRunnerDataKit/ModelRunnerDataKit-Swift.h>
#import <executorch/extension/module/module.h>

using torch::executor::EValue;
Expand All @@ -21,16 +20,6 @@ @interface ExecutorchRuntimeValueTests : XCTestCase

@implementation ExecutorchRuntimeValueTests

- (void)testStringValueWithError
{
ExecutorchRuntimeValue *value = [[ExecutorchRuntimeValue alloc] initWithEValue:EValue((int64_t)1)];
XCTAssertNil([value stringValueAndReturnError:nil]);
NSError *error = nil;
XCTAssertNil([value stringValueAndReturnError:&error]);
XCTAssertNotNil(error);
XCTAssertEqualObjects([error description], @"Unsupported type: ExecutorchRuntimeValue doesn't support strings");
}

- (void)testTensorValue
{
NSMutableArray *data = [NSMutableArray new];
Expand Down Expand Up @@ -63,9 +52,9 @@ - (void)testTensorValueWithFloatArrayWithError
- (void)testTensorValueWithError
{
ExecutorchRuntimeValue *value = [[ExecutorchRuntimeValue alloc] initWithEValue:EValue((int64_t)1)];
XCTAssertNil([value tensorValueAndReturnError:nil]);
XCTAssertNil([value asTensorValueAndReturnError:nil]);
NSError *error = nil;
XCTAssertNil([value tensorValueAndReturnError:&error]);
XCTAssertNil([value asTensorValueAndReturnError:&error]);
XCTAssertNotNil(error);
XCTAssertEqualObjects([error description], @"Invalid type: Tag::4, expected Tag::Tensor");
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading