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
42 changes: 42 additions & 0 deletions extension/apple/ExecuTorch/Exported/ExecuTorchTensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,48 @@ __attribute__((deprecated("This API is experimental.")))
*/
@property(nonatomic, readonly) void *nativeInstance NS_SWIFT_UNAVAILABLE("");

/**
* The data type of the tensor.
*
* @return An ExecuTorchDataType value representing the tensor's element type.
*/
@property(nonatomic, readonly) ExecuTorchDataType dataType;

/**
* The shape of the tensor.
*
* @return An NSArray of NSNumber objects representing the size of each dimension.
*/
@property(nonatomic, readonly) NSArray<NSNumber *> *shape;

/**
* The order of dimensions in the tensor.
*
* @return An NSArray of NSNumber objects representing the tensor’s dimension order.
*/
@property(nonatomic, readonly) NSArray<NSNumber *> *dimensionOrder;

/**
* The strides of the tensor.
*
* @return An NSArray of NSNumber objects representing the step sizes for each dimension.
*/
@property(nonatomic, readonly) NSArray<NSNumber *> *strides;

/**
* The dynamism of the tensor's shape.
*
* @return An ExecuTorchShapeDynamism value indicating whether the tensor shape is static or dynamic.
*/
@property(nonatomic, readonly) ExecuTorchShapeDynamism shapeDynamism;

/**
* The total number of elements in the tensor.
*
* @return An NSInteger representing the total element count.
*/
@property(nonatomic, readonly) NSInteger count;

/**
* Initializes a tensor with a native TensorPtr instance.
*
Expand Down
37 changes: 37 additions & 0 deletions extension/apple/ExecuTorch/Exported/ExecuTorchTensor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
#import "ExecuTorchTensor.h"

#import "ExecuTorchError.h"
#import "ExecuTorchUtils.h"

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

using namespace executorch::extension;

@implementation ExecuTorchTensor {
TensorPtr _tensor;
NSArray<NSNumber *> *_shape;
NSArray<NSNumber *> *_strides;
NSArray<NSNumber *> *_dimensionOrder;
}

- (instancetype)initWithNativeInstance:(void *)nativeInstance {
Expand All @@ -31,4 +35,37 @@ - (void *)nativeInstance {
return &_tensor;
}

- (ExecuTorchDataType)dataType {
return static_cast<ExecuTorchDataType>(_tensor->scalar_type());
}

- (NSArray<NSNumber *> *)shape {
if (!_shape) {
_shape = utils::toNSArray(_tensor->sizes());
}
return _shape;
}

- (NSArray<NSNumber *> *)dimensionOrder {
if (!_dimensionOrder) {
_dimensionOrder = utils::toNSArray(_tensor->dim_order());
}
return _dimensionOrder;
}

- (NSArray<NSNumber *> *)strides {
if (!_strides) {
_strides = utils::toNSArray(_tensor->strides());
}
return _strides;
}

- (ExecuTorchShapeDynamism)shapeDynamism {
return static_cast<ExecuTorchShapeDynamism>(_tensor->shape_dynamism());
}

- (NSInteger)count {
return _tensor->numel();
}

@end
Loading