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
22 changes: 22 additions & 0 deletions extension/apple/ExecuTorch/Exported/ExecuTorchTensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,32 @@ typedef NS_ENUM(uint8_t, ExecuTorchShapeDynamism) {
ExecuTorchShapeDynamismDynamicUnbound,
} NS_SWIFT_NAME(ShapeDynamism);

/**
* A tensor class for ExecuTorch operations.
*
* This class encapsulates a native TensorPtr instance and provides a variety of
* initializers and utility methods to work with tensor data.
*/
NS_SWIFT_NAME(Tensor)
__attribute__((deprecated("This API is experimental.")))
@interface ExecuTorchTensor : NSObject

/**
* Pointer to the underlying native TensorPtr instance.
*
* @return A raw pointer to the native TensorPtr held by this Tensor class.
*/
@property(nonatomic, readonly) void *nativeInstance NS_SWIFT_UNAVAILABLE("");

/**
* Initializes a tensor with a native TensorPtr instance.
*
* @param nativeInstance A pointer to a native TensorPtr instance.
* @return An initialized ExecuTorchTensor instance.
*/
- (instancetype)initWithNativeInstance:(void *)nativeInstance
NS_DESIGNATED_INITIALIZER NS_SWIFT_UNAVAILABLE("");

+ (instancetype)new NS_UNAVAILABLE;
- (instancetype)init NS_UNAVAILABLE;

Expand Down
17 changes: 16 additions & 1 deletion extension/apple/ExecuTorch/Exported/ExecuTorchTensor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,23 @@

#import <executorch/extension/tensor/tensor.h>

using namespace executorch::extension;

@implementation ExecuTorchTensor {
::executorch::extension::TensorPtr _tensor;
TensorPtr _tensor;
}

- (instancetype)initWithNativeInstance:(void *)nativeInstance {
ET_CHECK(nativeInstance);
if (self = [super init]) {
_tensor = std::move(*reinterpret_cast<TensorPtr *>(nativeInstance));
ET_CHECK(_tensor);
}
return self;
}

- (void *)nativeInstance {
return &_tensor;
}

@end
Loading