react-native-executorch 0.5.6 → 0.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/android/libs/classes.jar +0 -0
  2. package/android/src/main/cpp/CMakeLists.txt +23 -14
  3. package/common/rnexecutorch/RnExecutorchInstaller.cpp +4 -21
  4. package/common/rnexecutorch/host_objects/ModelHostObject.h +67 -51
  5. package/common/rnexecutorch/models/llm/LLM.cpp +24 -1
  6. package/common/rnexecutorch/models/llm/LLM.h +4 -1
  7. package/common/rnexecutorch/threads/GlobalThreadPool.h +79 -0
  8. package/common/rnexecutorch/threads/HighPerformanceThreadPool.h +364 -0
  9. package/common/rnexecutorch/threads/utils/ThreadUtils.h +29 -0
  10. package/common/runner/runner.cpp +9 -3
  11. package/common/runner/runner.h +4 -3
  12. package/common/runner/text_token_generator.h +28 -10
  13. package/lib/module/controllers/LLMController.js +21 -2
  14. package/lib/module/controllers/LLMController.js.map +1 -1
  15. package/lib/module/hooks/natural_language_processing/useLLM.js +6 -2
  16. package/lib/module/hooks/natural_language_processing/useLLM.js.map +1 -1
  17. package/lib/module/modules/natural_language_processing/LLMModule.js +4 -2
  18. package/lib/module/modules/natural_language_processing/LLMModule.js.map +1 -1
  19. package/lib/module/types/llm.js.map +1 -1
  20. package/lib/typescript/controllers/LLMController.d.ts +4 -2
  21. package/lib/typescript/controllers/LLMController.d.ts.map +1 -1
  22. package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts.map +1 -1
  23. package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts +3 -2
  24. package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts.map +1 -1
  25. package/lib/typescript/types/llm.d.ts +7 -1
  26. package/lib/typescript/types/llm.d.ts.map +1 -1
  27. package/package.json +3 -1
  28. package/react-native-executorch.podspec +12 -31
  29. package/src/controllers/LLMController.ts +29 -5
  30. package/src/hooks/natural_language_processing/useLLM.ts +15 -1
  31. package/src/modules/natural_language_processing/LLMModule.ts +10 -2
  32. package/src/types/llm.ts +8 -0
  33. package/third-party/android/libs/cpuinfo/arm64-v8a/libcpuinfo.so +0 -0
  34. package/third-party/android/libs/executorch/arm64-v8a/libexecutorch.so +0 -0
  35. package/third-party/android/libs/executorch/x86_64/libexecutorch.so +0 -0
  36. package/third-party/android/libs/pthreadpool/arm64-v8a/libpthreadpool.so +0 -0
  37. package/third-party/android/libs/tokenizers-cpp/arm64-v8a/libsentencepiece.a +0 -0
  38. package/third-party/android/libs/tokenizers-cpp/arm64-v8a/libtokenizers_c.a +0 -0
  39. package/third-party/android/libs/tokenizers-cpp/arm64-v8a/libtokenizers_cpp.a +0 -0
  40. package/third-party/android/libs/tokenizers-cpp/x86_64/libsentencepiece.a +0 -0
  41. package/third-party/android/libs/tokenizers-cpp/x86_64/libtokenizers_c.a +0 -0
  42. package/third-party/android/libs/tokenizers-cpp/x86_64/libtokenizers_cpp.a +0 -0
  43. package/third-party/include/c10/macros/Export.h +2 -86
  44. package/third-party/include/c10/macros/Macros.h +28 -5
  45. package/third-party/include/c10/util/BFloat16-inl.h +1 -4
  46. package/third-party/include/c10/util/BFloat16.h +5 -8
  47. package/third-party/include/c10/util/Half.h +5 -0
  48. package/third-party/include/c10/util/bit_cast.h +1 -1
  49. package/third-party/include/c10/util/complex.h +639 -0
  50. package/third-party/include/c10/util/complex_math.h +399 -0
  51. package/third-party/include/c10/util/complex_utils.h +41 -0
  52. package/third-party/include/c10/util/irange.h +2 -2
  53. package/third-party/include/c10/util/overflows.h +95 -0
  54. package/third-party/include/executorch/ExecuTorchError.h +75 -0
  55. package/third-party/include/executorch/ExecuTorchModule.h +115 -11
  56. package/third-party/include/executorch/ExecuTorchTensor.h +731 -51
  57. package/third-party/include/executorch/ExecuTorchValue.h +61 -9
  58. package/third-party/include/executorch/extension/kernel_util/make_boxed_from_unboxed_functor.h +181 -0
  59. package/third-party/include/executorch/extension/kernel_util/meta_programming.h +108 -0
  60. package/third-party/include/executorch/extension/kernel_util/type_list.h +137 -0
  61. package/third-party/include/executorch/extension/module/bundled_module.h +131 -0
  62. package/third-party/include/executorch/extension/module/module.h +46 -20
  63. package/third-party/include/executorch/extension/threadpool/cpuinfo_utils.h +1 -3
  64. package/third-party/include/executorch/extension/threadpool/threadpool.h +1 -3
  65. package/third-party/include/executorch/extension/threadpool/threadpool_guard.h +35 -0
  66. package/third-party/include/executorch/runtime/backend/backend_execution_context.h +3 -3
  67. package/third-party/include/executorch/runtime/backend/backend_init_context.h +12 -6
  68. package/third-party/include/executorch/runtime/backend/backend_option_context.h +34 -0
  69. package/third-party/include/executorch/runtime/backend/interface.h +70 -9
  70. package/third-party/include/executorch/runtime/backend/options.h +206 -0
  71. package/third-party/include/executorch/runtime/core/evalue.h +19 -25
  72. package/third-party/include/executorch/runtime/core/event_tracer.h +32 -17
  73. package/third-party/include/executorch/runtime/core/event_tracer_hooks.h +23 -14
  74. package/third-party/include/executorch/runtime/core/exec_aten/exec_aten.h +32 -9
  75. package/third-party/include/executorch/runtime/core/exec_aten/util/dim_order_util.h +3 -2
  76. package/third-party/include/executorch/runtime/core/exec_aten/util/scalar_type_util.h +43 -75
  77. package/third-party/include/executorch/runtime/core/exec_aten/util/tensor_util.h +88 -87
  78. package/third-party/include/executorch/runtime/core/function_ref.h +100 -0
  79. package/third-party/include/executorch/runtime/core/named_data_map.h +14 -14
  80. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/macros/Export.h +2 -86
  81. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/macros/Macros.h +28 -5
  82. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16-inl.h +1 -4
  83. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16.h +5 -8
  84. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/Half.h +5 -0
  85. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/bit_cast.h +1 -1
  86. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/complex.h +639 -0
  87. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/complex_math.h +399 -0
  88. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/complex_utils.h +41 -0
  89. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/irange.h +2 -2
  90. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/overflows.h +95 -0
  91. package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/macros/Export.h +88 -0
  92. package/third-party/include/executorch/runtime/core/portable_type/complex.h +6 -29
  93. package/third-party/include/executorch/runtime/core/portable_type/tensor_impl.h +20 -0
  94. package/third-party/include/executorch/runtime/core/span.h +4 -0
  95. package/third-party/include/executorch/runtime/core/tag.h +19 -0
  96. package/third-party/include/executorch/runtime/core/tensor_layout.h +2 -2
  97. package/third-party/include/executorch/runtime/executor/method.h +15 -3
  98. package/third-party/include/executorch/runtime/executor/method_meta.h +34 -5
  99. package/third-party/include/executorch/runtime/executor/program.h +3 -4
  100. package/third-party/include/executorch/runtime/executor/pte_data_map.h +9 -8
  101. package/third-party/include/executorch/runtime/executor/tensor_parser.h +14 -13
  102. package/third-party/include/executorch/runtime/kernel/kernel_runtime_context.h +5 -5
  103. package/third-party/include/executorch/runtime/kernel/operator_registry.h +21 -19
  104. package/third-party/include/executorch/runtime/platform/compiler.h +8 -0
  105. package/third-party/include/executorch/runtime/platform/platform.h +126 -0
  106. package/third-party/include/headeronly/macros/Export.h +88 -0
  107. package/third-party/include/tokenizers-cpp/tokenizers_c.h +61 -0
  108. package/third-party/include/torch/headeronly/macros/Export.h +88 -0
  109. package/third-party/ios/ExecutorchLib.xcframework/Info.plist +43 -0
  110. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/ExecutorchLib +0 -0
  111. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Info.plist +0 -0
  112. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/ExecutorchLib +0 -0
  113. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Info.plist +0 -0
  114. package/third-party/ios/libs/cpuinfo/libcpuinfo.a +0 -0
  115. package/third-party/ios/libs/pthreadpool/physical-arm64-release/libpthreadpool.a +0 -0
  116. package/third-party/ios/libs/pthreadpool/simulator-arm64-debug/libpthreadpool.a +0 -0
  117. package/ios/libs/executorch/libbackend_coreml_ios.a +0 -0
  118. package/ios/libs/executorch/libbackend_coreml_simulator.a +0 -0
  119. package/ios/libs/executorch/libbackend_mps_ios.a +0 -0
  120. package/ios/libs/executorch/libbackend_mps_simulator.a +0 -0
  121. package/ios/libs/executorch/libbackend_xnnpack_ios.a +0 -0
  122. package/ios/libs/executorch/libbackend_xnnpack_simulator.a +0 -0
  123. package/ios/libs/executorch/libexecutorch_ios.a +0 -0
  124. package/ios/libs/executorch/libexecutorch_simulator.a +0 -0
  125. package/ios/libs/executorch/libkernels_custom_ios.a +0 -0
  126. package/ios/libs/executorch/libkernels_custom_simulator.a +0 -0
  127. package/ios/libs/executorch/libkernels_optimized_ios.a +0 -0
  128. package/ios/libs/executorch/libkernels_optimized_simulator.a +0 -0
  129. package/ios/libs/executorch/libkernels_portable_ios.a +0 -0
  130. package/ios/libs/executorch/libkernels_portable_simulator.a +0 -0
  131. package/ios/libs/executorch/libkernels_quantized_ios.a +0 -0
  132. package/ios/libs/executorch/libkernels_quantized_simulator.a +0 -0
  133. package/third-party/ios/ios.toolchain.cmake +0 -1122
  134. /package/{ios → third-party/ios}/libs/tokenizers-cpp/physical-arm64-release/libsentencepiece.a +0 -0
  135. /package/{ios → third-party/ios}/libs/tokenizers-cpp/physical-arm64-release/libtokenizers_c.a +0 -0
  136. /package/{ios → third-party/ios}/libs/tokenizers-cpp/physical-arm64-release/libtokenizers_cpp.a +0 -0
  137. /package/{ios → third-party/ios}/libs/tokenizers-cpp/simulator-arm64-debug/libsentencepiece.a +0 -0
  138. /package/{ios → third-party/ios}/libs/tokenizers-cpp/simulator-arm64-debug/libtokenizers_c.a +0 -0
  139. /package/{ios → third-party/ios}/libs/tokenizers-cpp/simulator-arm64-debug/libtokenizers_cpp.a +0 -0
@@ -82,8 +82,7 @@ ExecuTorchSizeOfDataType(ExecuTorchDataType dataType)
82
82
  */
83
83
  FOUNDATION_EXPORT
84
84
  __attribute__((deprecated("This API is experimental."))) NSInteger
85
- ExecuTorchElementCountOfShape(NSArray<NSNumber *> *shape)
86
- NS_SWIFT_NAME(elementCount(ofShape:));
85
+ ExecuTorchElementCountOfShape(NSArray<NSNumber *> *shape) NS_REFINED_FOR_SWIFT;
87
86
 
88
87
  /**
89
88
  * A tensor class for ExecuTorch operations.
@@ -91,7 +90,7 @@ ExecuTorchElementCountOfShape(NSArray<NSNumber *> *shape)
91
90
  * This class encapsulates a native TensorPtr instance and provides a variety of
92
91
  * initializers and utility methods to work with tensor data.
93
92
  */
94
- NS_SWIFT_NAME(Tensor)
93
+ NS_SWIFT_NAME(AnyTensor)
95
94
  __attribute__((deprecated("This API is experimental.")))
96
95
  @interface ExecuTorchTensor : NSObject<NSCopying>
97
96
 
@@ -115,7 +114,7 @@ __attribute__((deprecated("This API is experimental.")))
115
114
  * @return An NSArray of NSNumber objects representing the size of each
116
115
  * dimension.
117
116
  */
118
- @property(nonatomic, readonly) NSArray<NSNumber *> *shape;
117
+ @property(nonatomic, readonly) NSArray<NSNumber *> *shape NS_REFINED_FOR_SWIFT;
119
118
 
120
119
  /**
121
120
  * The order of dimensions in the tensor.
@@ -123,7 +122,8 @@ __attribute__((deprecated("This API is experimental.")))
123
122
  * @return An NSArray of NSNumber objects representing the tensor’s dimension
124
123
  * order.
125
124
  */
126
- @property(nonatomic, readonly) NSArray<NSNumber *> *dimensionOrder;
125
+ @property(nonatomic, readonly)
126
+ NSArray<NSNumber *> *dimensionOrder NS_REFINED_FOR_SWIFT;
127
127
 
128
128
  /**
129
129
  * The strides of the tensor.
@@ -131,7 +131,8 @@ __attribute__((deprecated("This API is experimental.")))
131
131
  * @return An NSArray of NSNumber objects representing the step sizes for each
132
132
  * dimension.
133
133
  */
134
- @property(nonatomic, readonly) NSArray<NSNumber *> *strides;
134
+ @property(nonatomic, readonly)
135
+ NSArray<NSNumber *> *strides NS_REFINED_FOR_SWIFT;
135
136
 
136
137
  /**
137
138
  * The dynamism of the tensor's shape.
@@ -146,7 +147,7 @@ __attribute__((deprecated("This API is experimental.")))
146
147
  *
147
148
  * @return An NSInteger representing the total element count.
148
149
  */
149
- @property(nonatomic, readonly) NSInteger count;
150
+ @property(nonatomic, readonly) NSInteger count NS_REFINED_FOR_SWIFT;
150
151
 
151
152
  /**
152
153
  * Initializes a tensor with a native TensorPtr instance.
@@ -158,16 +159,18 @@ __attribute__((deprecated("This API is experimental.")))
158
159
  NS_DESIGNATED_INITIALIZER NS_SWIFT_UNAVAILABLE("");
159
160
 
160
161
  /**
161
- * Creates a new tensor by copying an existing tensor.
162
+ * Creates a new tensor that shares the underlying data storage with the
163
+ * given tensor. This new tensor is a view and does not own the data.
162
164
  *
163
- * @param otherTensor The tensor instance to copy.
164
- * @return A new ExecuTorchTensor instance that is a copy of otherTensor.
165
+ * @param otherTensor The tensor instance to create a view of.
166
+ * @return A new ExecuTorchTensor instance that shares data with otherTensor.
165
167
  */
166
168
  - (instancetype)initWithTensor:(ExecuTorchTensor *)otherTensor
167
169
  NS_SWIFT_NAME(init(_:));
168
170
 
169
171
  /**
170
- * Returns a copy of the tensor.
172
+ * Creates a deep copy of the tensor.
173
+ * The new tensor will have its own copy of the data.
171
174
  *
172
175
  * @return A new ExecuTorchTensor instance that is a duplicate of the current
173
176
  * tensor.
@@ -182,8 +185,9 @@ __attribute__((deprecated("This API is experimental.")))
182
185
  * - the total number of elements,
183
186
  * - and the data type.
184
187
  */
185
- - (void)bytesWithHandler:(void (^)(const void *pointer, NSInteger count,
186
- ExecuTorchDataType dataType))handler
188
+ - (void)bytesWithHandler:
189
+ (NS_NOESCAPE void (^)(const void *pointer, NSInteger count,
190
+ ExecuTorchDataType dataType))handler
187
191
  NS_SWIFT_NAME(bytes(_:));
188
192
 
189
193
  /**
@@ -194,8 +198,9 @@ __attribute__((deprecated("This API is experimental.")))
194
198
  * - the total number of elements,
195
199
  * - and the data type.
196
200
  */
197
- - (void)mutableBytesWithHandler:(void (^)(void *pointer, NSInteger count,
198
- ExecuTorchDataType dataType))handler
201
+ - (void)mutableBytesWithHandler:
202
+ (NS_NOESCAPE void (^)(void *pointer, NSInteger count,
203
+ ExecuTorchDataType dataType))handler
199
204
  NS_SWIFT_NAME(mutableBytes(_:));
200
205
 
201
206
  /**
@@ -207,16 +212,16 @@ __attribute__((deprecated("This API is experimental.")))
207
212
  * @return YES if the tensor was successfully resized; otherwise, NO.
208
213
  */
209
214
  - (BOOL)resizeToShape:(NSArray<NSNumber *> *)shape
210
- error:(NSError **)error NS_SWIFT_NAME(resize(to:));
215
+ error:(NSError **)error NS_REFINED_FOR_SWIFT;
211
216
 
212
217
  /**
213
218
  * Determines whether the current tensor is equal to another tensor.
214
219
  *
215
220
  * @param other Another ExecuTorchTensor instance to compare against.
216
- * @return YES if the tensors have the same type, shape, strides, and data;
217
- * otherwise, NO.
221
+ * @return YES if the tensors have the same data type, shape, dimension order,
222
+ * strides, and underlying data; otherwise, NO.
218
223
  */
219
- - (BOOL)isEqualToTensor:(nullable ExecuTorchTensor *)other;
224
+ - (BOOL)isEqualToTensor:(nullable ExecuTorchTensor *)other NS_REFINED_FOR_SWIFT;
220
225
 
221
226
  + (instancetype)new NS_UNAVAILABLE;
222
227
  - (instancetype)init NS_UNAVAILABLE;
@@ -247,7 +252,8 @@ __attribute__((deprecated("This API is experimental.")))
247
252
  strides:(NSArray<NSNumber *> *)strides
248
253
  dimensionOrder:(NSArray<NSNumber *> *)dimensionOrder
249
254
  dataType:(ExecuTorchDataType)dataType
250
- shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism;
255
+ shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism
256
+ NS_REFINED_FOR_SWIFT;
251
257
 
252
258
  /**
253
259
  * Initializes a tensor without copying data using dynamic bound shape (default
@@ -266,7 +272,8 @@ __attribute__((deprecated("This API is experimental.")))
266
272
  shape:(NSArray<NSNumber *> *)shape
267
273
  strides:(NSArray<NSNumber *> *)strides
268
274
  dimensionOrder:(NSArray<NSNumber *> *)dimensionOrder
269
- dataType:(ExecuTorchDataType)dataType;
275
+ dataType:(ExecuTorchDataType)dataType
276
+ NS_SWIFT_UNAVAILABLE("");
270
277
 
271
278
  /**
272
279
  * Initializes a tensor without copying data, with an explicit shape dynamism.
@@ -281,7 +288,8 @@ __attribute__((deprecated("This API is experimental.")))
281
288
  - (instancetype)initWithBytesNoCopy:(void *)pointer
282
289
  shape:(NSArray<NSNumber *> *)shape
283
290
  dataType:(ExecuTorchDataType)dataType
284
- shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism;
291
+ shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism
292
+ NS_SWIFT_UNAVAILABLE("");
285
293
 
286
294
  /**
287
295
  * Initializes a tensor without copying data, specifying only the shape and data
@@ -294,7 +302,8 @@ __attribute__((deprecated("This API is experimental.")))
294
302
  */
295
303
  - (instancetype)initWithBytesNoCopy:(void *)pointer
296
304
  shape:(NSArray<NSNumber *> *)shape
297
- dataType:(ExecuTorchDataType)dataType;
305
+ dataType:(ExecuTorchDataType)dataType
306
+ NS_SWIFT_UNAVAILABLE("");
298
307
 
299
308
  @end
300
309
 
@@ -322,7 +331,8 @@ __attribute__((deprecated("This API is experimental.")))
322
331
  strides:(NSArray<NSNumber *> *)strides
323
332
  dimensionOrder:(NSArray<NSNumber *> *)dimensionOrder
324
333
  dataType:(ExecuTorchDataType)dataType
325
- shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism;
334
+ shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism
335
+ NS_REFINED_FOR_SWIFT;
326
336
 
327
337
  /**
328
338
  * Initializes a tensor by copying bytes from the provided pointer with dynamic
@@ -342,7 +352,8 @@ __attribute__((deprecated("This API is experimental.")))
342
352
  shape:(NSArray<NSNumber *> *)shape
343
353
  strides:(NSArray<NSNumber *> *)strides
344
354
  dimensionOrder:(NSArray<NSNumber *> *)dimensionOrder
345
- dataType:(ExecuTorchDataType)dataType;
355
+ dataType:(ExecuTorchDataType)dataType
356
+ NS_SWIFT_UNAVAILABLE("");
346
357
 
347
358
  /**
348
359
  * Initializes a tensor by copying bytes from the provided pointer, specifying
@@ -359,7 +370,8 @@ __attribute__((deprecated("This API is experimental.")))
359
370
  - (instancetype)initWithBytes:(const void *)pointer
360
371
  shape:(NSArray<NSNumber *> *)shape
361
372
  dataType:(ExecuTorchDataType)dataType
362
- shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism;
373
+ shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism
374
+ NS_SWIFT_UNAVAILABLE("");
363
375
 
364
376
  /**
365
377
  * Initializes a tensor by copying bytes from the provided pointer, specifying
@@ -373,7 +385,8 @@ __attribute__((deprecated("This API is experimental.")))
373
385
  */
374
386
  - (instancetype)initWithBytes:(const void *)pointer
375
387
  shape:(NSArray<NSNumber *> *)shape
376
- dataType:(ExecuTorchDataType)dataType;
388
+ dataType:(ExecuTorchDataType)dataType
389
+ NS_SWIFT_UNAVAILABLE("");
377
390
 
378
391
  @end
379
392
 
@@ -382,7 +395,9 @@ __attribute__((deprecated("This API is experimental.")))
382
395
  @interface ExecuTorchTensor (Data)
383
396
 
384
397
  /**
385
- * Initializes a tensor using an NSData object as the underlying data buffer.
398
+ * Initializes a tensor using an NSData object. The tensor will hold a
399
+ * strong reference to the NSData object to manage the lifetime of the
400
+ * underlying data buffer, which is not copied.
386
401
  *
387
402
  * @param data An NSData object containing the tensor data.
388
403
  * @param shape An NSArray of NSNumber objects representing the tensor's shape.
@@ -400,7 +415,8 @@ __attribute__((deprecated("This API is experimental.")))
400
415
  strides:(NSArray<NSNumber *> *)strides
401
416
  dimensionOrder:(NSArray<NSNumber *> *)dimensionOrder
402
417
  dataType:(ExecuTorchDataType)dataType
403
- shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism;
418
+ shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism
419
+ NS_REFINED_FOR_SWIFT;
404
420
 
405
421
  /**
406
422
  * Initializes a tensor using an NSData object as the underlying data buffer
@@ -419,7 +435,8 @@ __attribute__((deprecated("This API is experimental.")))
419
435
  shape:(NSArray<NSNumber *> *)shape
420
436
  strides:(NSArray<NSNumber *> *)strides
421
437
  dimensionOrder:(NSArray<NSNumber *> *)dimensionOrder
422
- dataType:(ExecuTorchDataType)dataType;
438
+ dataType:(ExecuTorchDataType)dataType
439
+ NS_SWIFT_UNAVAILABLE("");
423
440
 
424
441
  /**
425
442
  * Initializes a tensor using an NSData object as the underlying data buffer,
@@ -435,7 +452,8 @@ __attribute__((deprecated("This API is experimental.")))
435
452
  - (instancetype)initWithData:(NSData *)data
436
453
  shape:(NSArray<NSNumber *> *)shape
437
454
  dataType:(ExecuTorchDataType)dataType
438
- shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism;
455
+ shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism
456
+ NS_SWIFT_UNAVAILABLE("");
439
457
 
440
458
  /**
441
459
  * Initializes a tensor using an NSData object as the underlying data buffer,
@@ -448,7 +466,8 @@ __attribute__((deprecated("This API is experimental.")))
448
466
  */
449
467
  - (instancetype)initWithData:(NSData *)data
450
468
  shape:(NSArray<NSNumber *> *)shape
451
- dataType:(ExecuTorchDataType)dataType;
469
+ dataType:(ExecuTorchDataType)dataType
470
+ NS_SWIFT_UNAVAILABLE("");
452
471
 
453
472
  @end
454
473
 
@@ -479,7 +498,7 @@ __attribute__((deprecated("This API is experimental.")))
479
498
  dimensionOrder:(NSArray<NSNumber *> *)dimensionOrder
480
499
  dataType:(ExecuTorchDataType)dataType
481
500
  shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism
482
- NS_SWIFT_NAME(init(_:shape:strides:dimensionOrder:dataType:shapeDynamism:));
501
+ NS_SWIFT_UNAVAILABLE("");
483
502
 
484
503
  /**
485
504
  * Initializes a tensor with an array of scalar values, specifying shape,
@@ -502,7 +521,7 @@ __attribute__((deprecated("This API is experimental.")))
502
521
  strides:(NSArray<NSNumber *> *)strides
503
522
  dimensionOrder:(NSArray<NSNumber *> *)dimensionOrder
504
523
  dataType:(ExecuTorchDataType)dataType
505
- NS_SWIFT_NAME(init(_:shape:strides:dimensionOrder:dataType:));
524
+ NS_SWIFT_UNAVAILABLE("");
506
525
 
507
526
  /**
508
527
  * Initializes a tensor with an array of scalar values, specifying the desired
@@ -520,7 +539,7 @@ __attribute__((deprecated("This API is experimental.")))
520
539
  shape:(NSArray<NSNumber *> *)shape
521
540
  dataType:(ExecuTorchDataType)dataType
522
541
  shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism
523
- NS_SWIFT_NAME(init(_:shape:dataType:shapeDynamism:));
542
+ NS_SWIFT_UNAVAILABLE("");
524
543
 
525
544
  /**
526
545
  * Initializes a tensor with an array of scalar values and a specified shape,
@@ -535,7 +554,7 @@ __attribute__((deprecated("This API is experimental.")))
535
554
  - (instancetype)initWithScalars:(NSArray<NSNumber *> *)scalars
536
555
  shape:(NSArray<NSNumber *> *)shape
537
556
  dataType:(ExecuTorchDataType)dataType
538
- NS_SWIFT_NAME(init(_:shape:dataType:));
557
+ NS_SWIFT_UNAVAILABLE("");
539
558
 
540
559
  /**
541
560
  * Initializes a tensor with an array of scalar values, specifying the tensor
@@ -552,7 +571,7 @@ __attribute__((deprecated("This API is experimental.")))
552
571
  - (instancetype)initWithScalars:(NSArray<NSNumber *> *)scalars
553
572
  dataType:(ExecuTorchDataType)dataType
554
573
  shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism
555
- NS_SWIFT_NAME(init(_:dataType:shapeDynamism:));
574
+ NS_SWIFT_UNAVAILABLE("");
556
575
 
557
576
  /**
558
577
  * Initializes a tensor with an array of scalar values, specifying the tensor
@@ -565,7 +584,7 @@ __attribute__((deprecated("This API is experimental.")))
565
584
  */
566
585
  - (instancetype)initWithScalars:(NSArray<NSNumber *> *)scalars
567
586
  dataType:(ExecuTorchDataType)dataType
568
- NS_SWIFT_NAME(init(_:dataType:));
587
+ NS_SWIFT_UNAVAILABLE("");
569
588
 
570
589
  /**
571
590
  * Initializes a tensor with an array of scalar values, a specified shape and
@@ -582,7 +601,7 @@ __attribute__((deprecated("This API is experimental.")))
582
601
  - (instancetype)initWithScalars:(NSArray<NSNumber *> *)scalars
583
602
  shape:(NSArray<NSNumber *> *)shape
584
603
  shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism
585
- NS_SWIFT_NAME(init(_:shape:shapeDynamism:));
604
+ NS_SWIFT_UNAVAILABLE("");
586
605
 
587
606
  /**
588
607
  * Initializes a tensor with an array of scalar values and a specified shape.
@@ -595,7 +614,7 @@ __attribute__((deprecated("This API is experimental.")))
595
614
  */
596
615
  - (instancetype)initWithScalars:(NSArray<NSNumber *> *)scalars
597
616
  shape:(NSArray<NSNumber *> *)shape
598
- NS_SWIFT_NAME(init(_:shape:));
617
+ NS_SWIFT_UNAVAILABLE("");
599
618
 
600
619
  /**
601
620
  * Initializes a tensor with an array of scalar values, automatically deducing
@@ -606,7 +625,7 @@ __attribute__((deprecated("This API is experimental.")))
606
625
  * deduced.
607
626
  */
608
627
  - (instancetype)initWithScalars:(NSArray<NSNumber *> *)scalars
609
- NS_SWIFT_NAME(init(_:));
628
+ NS_SWIFT_UNAVAILABLE("");
610
629
 
611
630
  @end
612
631
 
@@ -621,7 +640,7 @@ __attribute__((deprecated("This API is experimental.")))
621
640
  */
622
641
  - (instancetype)initWithScalar:(NSNumber *)scalar
623
642
  dataType:(ExecuTorchDataType)dataType
624
- NS_SWIFT_NAME(init(_:dataType:));
643
+ NS_REFINED_FOR_SWIFT;
625
644
 
626
645
  /**
627
646
  * Initializes a tensor with a single scalar value, automatically deducing its
@@ -630,7 +649,7 @@ __attribute__((deprecated("This API is experimental.")))
630
649
  * @param scalar An NSNumber representing the scalar value.
631
650
  * @return An initialized ExecuTorchTensor instance representing the scalar.
632
651
  */
633
- - (instancetype)initWithScalar:(NSNumber *)scalar NS_SWIFT_NAME(init(_:));
652
+ - (instancetype)initWithScalar:(NSNumber *)scalar NS_SWIFT_UNAVAILABLE("");
634
653
 
635
654
  /**
636
655
  * Initializes a tensor with a byte scalar value.
@@ -638,7 +657,7 @@ __attribute__((deprecated("This API is experimental.")))
638
657
  * @param scalar A uint8_t value.
639
658
  * @return An initialized ExecuTorchTensor instance.
640
659
  */
641
- - (instancetype)initWithByte:(uint8_t)scalar NS_SWIFT_NAME(init(_:));
660
+ - (instancetype)initWithByte:(uint8_t)scalar NS_SWIFT_UNAVAILABLE("");
642
661
 
643
662
  /**
644
663
  * Initializes a tensor with a char scalar value.
@@ -646,7 +665,7 @@ __attribute__((deprecated("This API is experimental.")))
646
665
  * @param scalar An int8_t value.
647
666
  * @return An initialized ExecuTorchTensor instance.
648
667
  */
649
- - (instancetype)initWithChar:(int8_t)scalar NS_SWIFT_NAME(init(_:));
668
+ - (instancetype)initWithChar:(int8_t)scalar NS_SWIFT_UNAVAILABLE("");
650
669
 
651
670
  /**
652
671
  * Initializes a tensor with a short scalar value.
@@ -654,7 +673,7 @@ __attribute__((deprecated("This API is experimental.")))
654
673
  * @param scalar An int16_t value.
655
674
  * @return An initialized ExecuTorchTensor instance.
656
675
  */
657
- - (instancetype)initWithShort:(int16_t)scalar NS_SWIFT_NAME(init(_:));
676
+ - (instancetype)initWithShort:(int16_t)scalar NS_SWIFT_UNAVAILABLE("");
658
677
 
659
678
  /**
660
679
  * Initializes a tensor with an int scalar value.
@@ -662,7 +681,7 @@ __attribute__((deprecated("This API is experimental.")))
662
681
  * @param scalar An int32_t value.
663
682
  * @return An initialized ExecuTorchTensor instance.
664
683
  */
665
- - (instancetype)initWithInt:(int32_t)scalar NS_SWIFT_NAME(init(_:));
684
+ - (instancetype)initWithInt:(int32_t)scalar NS_SWIFT_UNAVAILABLE("");
666
685
 
667
686
  /**
668
687
  * Initializes a tensor with a long scalar value.
@@ -670,7 +689,7 @@ __attribute__((deprecated("This API is experimental.")))
670
689
  * @param scalar An int64_t value.
671
690
  * @return An initialized ExecuTorchTensor instance.
672
691
  */
673
- - (instancetype)initWithLong:(int64_t)scalar NS_SWIFT_NAME(init(_:));
692
+ - (instancetype)initWithLong:(int64_t)scalar NS_SWIFT_UNAVAILABLE("");
674
693
 
675
694
  /**
676
695
  * Initializes a tensor with a float scalar value.
@@ -678,7 +697,7 @@ __attribute__((deprecated("This API is experimental.")))
678
697
  * @param scalar A float value.
679
698
  * @return An initialized ExecuTorchTensor instance.
680
699
  */
681
- - (instancetype)initWithFloat:(float)scalar NS_SWIFT_NAME(init(_:));
700
+ - (instancetype)initWithFloat:(float)scalar NS_SWIFT_UNAVAILABLE("");
682
701
 
683
702
  /**
684
703
  * Initializes a tensor with a double scalar value.
@@ -686,7 +705,7 @@ __attribute__((deprecated("This API is experimental.")))
686
705
  * @param scalar A double value.
687
706
  * @return An initialized ExecuTorchTensor instance.
688
707
  */
689
- - (instancetype)initWithDouble:(double)scalar NS_SWIFT_NAME(init(_:));
708
+ - (instancetype)initWithDouble:(double)scalar NS_SWIFT_UNAVAILABLE("");
690
709
 
691
710
  /**
692
711
  * Initializes a tensor with a boolean scalar value.
@@ -694,7 +713,7 @@ __attribute__((deprecated("This API is experimental.")))
694
713
  * @param scalar A BOOL value.
695
714
  * @return An initialized ExecuTorchTensor instance.
696
715
  */
697
- - (instancetype)initWithBool:(BOOL)scalar NS_SWIFT_NAME(init(_:));
716
+ - (instancetype)initWithBool:(BOOL)scalar NS_SWIFT_UNAVAILABLE("");
698
717
 
699
718
  /**
700
719
  * Initializes a tensor with a uint16 scalar value.
@@ -739,4 +758,665 @@ __attribute__((deprecated("This API is experimental.")))
739
758
 
740
759
  @end
741
760
 
761
+ #pragma mark - Empty Category
762
+
763
+ @interface ExecuTorchTensor (Empty)
764
+
765
+ /**
766
+ * Creates an empty tensor with the specified shape, strides, data type, and
767
+ * shape dynamism.
768
+ *
769
+ * @param shape An NSArray of NSNumber objects representing the desired shape.
770
+ * @param strides An NSArray of NSNumber objects representing the desired
771
+ * strides.
772
+ * @param dataType An ExecuTorchDataType value specifying the element type.
773
+ * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the
774
+ * shape is static or dynamic.
775
+ * @return A new, empty ExecuTorchTensor instance.
776
+ */
777
+ + (instancetype)emptyTensorWithShape:(NSArray<NSNumber *> *)shape
778
+ strides:(NSArray<NSNumber *> *)strides
779
+ dataType:(ExecuTorchDataType)dataType
780
+ shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism
781
+ NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED;
782
+
783
+ /**
784
+ * Creates an empty tensor with the specified shape, data type, and shape
785
+ * dynamism.
786
+ *
787
+ * @param shape An NSArray of NSNumber objects representing the desired shape.
788
+ * @param dataType An ExecuTorchDataType value specifying the element type.
789
+ * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the
790
+ * shape is static or dynamic.
791
+ * @return A new, empty ExecuTorchTensor instance.
792
+ */
793
+ + (instancetype)emptyTensorWithShape:(NSArray<NSNumber *> *)shape
794
+ dataType:(ExecuTorchDataType)dataType
795
+ shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism
796
+ NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
797
+
798
+ /**
799
+ * Creates an empty tensor with the specified shape and data type, using dynamic
800
+ * bound shape.
801
+ *
802
+ * @param shape An NSArray of NSNumber objects representing the desired shape.
803
+ * @param dataType An ExecuTorchDataType value specifying the element type.
804
+ * @return A new, empty ExecuTorchTensor instance.
805
+ */
806
+ + (instancetype)emptyTensorWithShape:(NSArray<NSNumber *> *)shape
807
+ dataType:(ExecuTorchDataType)dataType
808
+ NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
809
+
810
+ /**
811
+ * Creates an empty tensor similar to the given tensor, with the specified data
812
+ * type and shape dynamism.
813
+ *
814
+ * @param tensor An existing ExecuTorchTensor instance whose shape and strides
815
+ * are used.
816
+ * @param dataType An ExecuTorchDataType value specifying the desired element
817
+ * type.
818
+ * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the
819
+ * shape is static or dynamic.
820
+ * @return A new, empty ExecuTorchTensor instance with the same shape as the
821
+ * provided tensor.
822
+ */
823
+ + (instancetype)emptyTensorLikeTensor:(ExecuTorchTensor *)tensor
824
+ dataType:(ExecuTorchDataType)dataType
825
+ shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism
826
+ NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED;
827
+
828
+ /**
829
+ * Creates an empty tensor similar to the given tensor, with the specified data
830
+ * type.
831
+ *
832
+ * @param tensor An existing ExecuTorchTensor instance whose shape and strides
833
+ * are used.
834
+ * @param dataType An ExecuTorchDataType value specifying the desired element
835
+ * type.
836
+ * @return A new, empty ExecuTorchTensor instance with the same shape as the
837
+ * provided tensor.
838
+ */
839
+ + (instancetype)emptyTensorLikeTensor:(ExecuTorchTensor *)tensor
840
+ dataType:(ExecuTorchDataType)dataType
841
+ NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
842
+
843
+ /**
844
+ * Creates an empty tensor similar to the given tensor.
845
+ *
846
+ * @param tensor An existing ExecuTorchTensor instance.
847
+ * @return A new, empty ExecuTorchTensor instance with the same properties as
848
+ * the provided tensor.
849
+ */
850
+ + (instancetype)emptyTensorLikeTensor:(ExecuTorchTensor *)tensor
851
+ NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
852
+
853
+ @end
854
+
855
+ #pragma mark - Full Category
856
+
857
+ @interface ExecuTorchTensor (Full)
858
+
859
+ /**
860
+ * Creates a tensor filled with the specified scalar value, with full
861
+ * specification of shape, strides, data type, and shape dynamism.
862
+ *
863
+ * @param shape An NSArray of NSNumber objects representing the desired shape.
864
+ * @param scalar An NSNumber representing the value to fill the tensor.
865
+ * @param strides An NSArray of NSNumber objects representing the desired
866
+ * strides.
867
+ * @param dataType An ExecuTorchDataType value specifying the element type.
868
+ * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the
869
+ * shape is static or dynamic.
870
+ * @return A new ExecuTorchTensor instance filled with the scalar value.
871
+ */
872
+ + (instancetype)fullTensorWithShape:(NSArray<NSNumber *> *)shape
873
+ scalar:(NSNumber *)scalar
874
+ strides:(NSArray<NSNumber *> *)strides
875
+ dataType:(ExecuTorchDataType)dataType
876
+ shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism
877
+ NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED;
878
+
879
+ /**
880
+ * Creates a tensor filled with the specified scalar value, with the given
881
+ * shape, data type, and shape dynamism.
882
+ *
883
+ * @param shape An NSArray of NSNumber objects representing the desired shape.
884
+ * @param scalar An NSNumber representing the value to fill the tensor.
885
+ * @param dataType An ExecuTorchDataType value specifying the element type.
886
+ * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the
887
+ * shape is static or dynamic.
888
+ * @return A new ExecuTorchTensor instance filled with the scalar value.
889
+ */
890
+ + (instancetype)fullTensorWithShape:(NSArray<NSNumber *> *)shape
891
+ scalar:(NSNumber *)scalar
892
+ dataType:(ExecuTorchDataType)dataType
893
+ shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism
894
+ NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
895
+
896
+ /**
897
+ * Creates a tensor filled with the specified scalar value, with the given shape
898
+ * and data type, using dynamic bound shape for strides and dimension order.
899
+ *
900
+ * @param shape An NSArray of NSNumber objects representing the desired shape.
901
+ * @param scalar An NSNumber representing the value to fill the tensor.
902
+ * @param dataType An ExecuTorchDataType value specifying the element type.
903
+ * @return A new ExecuTorchTensor instance filled with the scalar value.
904
+ */
905
+ + (instancetype)fullTensorWithShape:(NSArray<NSNumber *> *)shape
906
+ scalar:(NSNumber *)scalar
907
+ dataType:(ExecuTorchDataType)dataType
908
+ NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
909
+
910
+ /**
911
+ * Creates a tensor filled with the specified scalar value, similar to an
912
+ * existing tensor, with the given data type and shape dynamism.
913
+ *
914
+ * @param tensr An existing ExecuTorchTensor instance whose shape and strides
915
+ * are used.
916
+ * @param scalar An NSNumber representing the value to fill the tensor.
917
+ * @param dataType An ExecuTorchDataType value specifying the desired element
918
+ * type.
919
+ * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the
920
+ * shape is static or dynamic.
921
+ * @return A new ExecuTorchTensor instance filled with the scalar value.
922
+ */
923
+ + (instancetype)fullTensorLikeTensor:(ExecuTorchTensor *)tensr
924
+ scalar:(NSNumber *)scalar
925
+ dataType:(ExecuTorchDataType)dataType
926
+ shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism
927
+ NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED;
928
+
929
+ /**
930
+ * Creates a tensor filled with the specified scalar value, similar to an
931
+ * existing tensor, with the given data type.
932
+ *
933
+ * @param tensr An existing ExecuTorchTensor instance whose shape and strides
934
+ * are used.
935
+ * @param scalar An NSNumber representing the value to fill the tensor.
936
+ * @param dataType An ExecuTorchDataType value specifying the desired element
937
+ * type.
938
+ * @return A new ExecuTorchTensor instance filled with the scalar value.
939
+ */
940
+ + (instancetype)fullTensorLikeTensor:(ExecuTorchTensor *)tensr
941
+ scalar:(NSNumber *)scalar
942
+ dataType:(ExecuTorchDataType)dataType
943
+ NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
944
+
945
+ /**
946
+ * Creates a tensor filled with the specified scalar value, similar to an
947
+ * existing tensor.
948
+ *
949
+ * @param tensr An existing ExecuTorchTensor instance.
950
+ * @param scalar An NSNumber representing the value to fill the tensor.
951
+ * @return A new ExecuTorchTensor instance filled with the scalar value.
952
+ */
953
+ + (instancetype)fullTensorLikeTensor:(ExecuTorchTensor *)tensr
954
+ scalar:(NSNumber *)scalar
955
+ NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
956
+
957
+ @end
958
+
959
+ #pragma mark - Ones Category
960
+
961
+ @interface ExecuTorchTensor (Ones)
962
+
963
+ /**
964
+ * Creates a tensor filled with ones, with the specified shape, data type, and
965
+ * shape dynamism.
966
+ *
967
+ * @param shape An NSArray of NSNumber objects representing the desired shape.
968
+ * @param dataType An ExecuTorchDataType value specifying the element type.
969
+ * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the
970
+ * shape is static or dynamic.
971
+ * @return A new ExecuTorchTensor instance filled with ones.
972
+ */
973
+ + (instancetype)onesTensorWithShape:(NSArray<NSNumber *> *)shape
974
+ dataType:(ExecuTorchDataType)dataType
975
+ shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism
976
+ NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED;
977
+
978
+ /**
979
+ * Creates a tensor filled with ones, with the specified shape and data type.
980
+ *
981
+ * @param shape An NSArray of NSNumber objects representing the desired shape.
982
+ * @param dataType An ExecuTorchDataType value specifying the element type.
983
+ * @return A new ExecuTorchTensor instance filled with ones.
984
+ */
985
+ + (instancetype)onesTensorWithShape:(NSArray<NSNumber *> *)shape
986
+ dataType:(ExecuTorchDataType)dataType
987
+ NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
988
+
989
+ /**
990
+ * Creates a tensor filled with ones similar to an existing tensor, with the
991
+ * specified data type and shape dynamism.
992
+ *
993
+ * @param tensor An existing ExecuTorchTensor instance whose shape and strides
994
+ * are used.
995
+ * @param dataType An ExecuTorchDataType value specifying the desired element
996
+ * type.
997
+ * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the
998
+ * shape is static or dynamic.
999
+ * @return A new ExecuTorchTensor instance filled with ones.
1000
+ */
1001
+ + (instancetype)onesTensorLikeTensor:(ExecuTorchTensor *)tensor
1002
+ dataType:(ExecuTorchDataType)dataType
1003
+ shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism
1004
+ NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED;
1005
+
1006
+ /**
1007
+ * Creates a tensor filled with ones similar to an existing tensor, with the
1008
+ * specified data type.
1009
+ *
1010
+ * @param tensor An existing ExecuTorchTensor instance whose shape and strides
1011
+ * are used.
1012
+ * @param dataType An ExecuTorchDataType value specifying the desired element
1013
+ * type.
1014
+ * @return A new ExecuTorchTensor instance filled with ones.
1015
+ */
1016
+ + (instancetype)onesTensorLikeTensor:(ExecuTorchTensor *)tensor
1017
+ dataType:(ExecuTorchDataType)dataType
1018
+ NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
1019
+
1020
+ /**
1021
+ * Creates a tensor filled with ones similar to an existing tensor.
1022
+ *
1023
+ * @param tensor An existing ExecuTorchTensor instance.
1024
+ * @return A new ExecuTorchTensor instance filled with ones.
1025
+ */
1026
+ + (instancetype)onesTensorLikeTensor:(ExecuTorchTensor *)tensor
1027
+ NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
1028
+
1029
+ @end
1030
+
1031
+ #pragma mark - Zeros Category
1032
+
1033
+ @interface ExecuTorchTensor (Zeros)
1034
+
1035
+ /**
1036
+ * Creates a tensor filled with zeros, with the specified shape, data type, and
1037
+ * shape dynamism.
1038
+ *
1039
+ * @param shape An NSArray of NSNumber objects representing the desired shape.
1040
+ * @param dataType An ExecuTorchDataType value specifying the element type.
1041
+ * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the
1042
+ * shape is static or dynamic.
1043
+ * @return A new ExecuTorchTensor instance filled with zeros.
1044
+ */
1045
+ + (instancetype)zerosTensorWithShape:(NSArray<NSNumber *> *)shape
1046
+ dataType:(ExecuTorchDataType)dataType
1047
+ shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism
1048
+ NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED;
1049
+
1050
+ /**
1051
+ * Creates a tensor filled with zeros, with the specified shape and data type.
1052
+ *
1053
+ * @param shape An NSArray of NSNumber objects representing the desired shape.
1054
+ * @param dataType An ExecuTorchDataType value specifying the element type.
1055
+ * @return A new ExecuTorchTensor instance filled with zeros.
1056
+ */
1057
+ + (instancetype)zerosTensorWithShape:(NSArray<NSNumber *> *)shape
1058
+ dataType:(ExecuTorchDataType)dataType
1059
+ NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
1060
+
1061
+ /**
1062
+ * Creates a tensor filled with zeros similar to an existing tensor, with the
1063
+ * specified data type and shape dynamism.
1064
+ *
1065
+ * @param tensor An existing ExecuTorchTensor instance whose shape and strides
1066
+ * are used.
1067
+ * @param dataType An ExecuTorchDataType value specifying the desired element
1068
+ * type.
1069
+ * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the
1070
+ * shape is static or dynamic.
1071
+ * @return A new ExecuTorchTensor instance filled with zeros.
1072
+ */
1073
+ + (instancetype)zerosTensorLikeTensor:(ExecuTorchTensor *)tensor
1074
+ dataType:(ExecuTorchDataType)dataType
1075
+ shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism
1076
+ NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED;
1077
+
1078
+ /**
1079
+ * Creates a tensor filled with zeros similar to an existing tensor, with the
1080
+ * specified data type.
1081
+ *
1082
+ * @param tensor An existing ExecuTorchTensor instance whose shape and strides
1083
+ * are used.
1084
+ * @param dataType An ExecuTorchDataType value specifying the desired element
1085
+ * type.
1086
+ * @return A new ExecuTorchTensor instance filled with zeros.
1087
+ */
1088
+ + (instancetype)zerosTensorLikeTensor:(ExecuTorchTensor *)tensor
1089
+ dataType:(ExecuTorchDataType)dataType
1090
+ NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
1091
+
1092
+ /**
1093
+ * Creates a tensor filled with zeros similar to an existing tensor.
1094
+ *
1095
+ * @param tensor An existing ExecuTorchTensor instance.
1096
+ * @return A new ExecuTorchTensor instance filled with zeros.
1097
+ */
1098
+ + (instancetype)zerosTensorLikeTensor:(ExecuTorchTensor *)tensor
1099
+ NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
1100
+
1101
+ @end
1102
+
1103
+ #pragma mark - Random Category
1104
+
1105
+ @interface ExecuTorchTensor (Random)
1106
+
1107
+ /**
1108
+ * Creates a tensor with random values, with full specification of shape,
1109
+ * strides, data type, and shape dynamism.
1110
+ *
1111
+ * @param shape An NSArray of NSNumber objects representing the desired shape.
1112
+ * @param strides An NSArray of NSNumber objects representing the desired
1113
+ * strides.
1114
+ * @param dataType An ExecuTorchDataType value specifying the element type.
1115
+ * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the
1116
+ * shape is static or dynamic.
1117
+ * @return A new ExecuTorchTensor instance filled with random values.
1118
+ */
1119
+ + (instancetype)randomTensorWithShape:(NSArray<NSNumber *> *)shape
1120
+ strides:(NSArray<NSNumber *> *)strides
1121
+ dataType:(ExecuTorchDataType)dataType
1122
+ shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism
1123
+ NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED;
1124
+
1125
+ /**
1126
+ * Creates a tensor with random values, with the specified shape and data type.
1127
+ *
1128
+ * @param shape An NSArray of NSNumber objects representing the desired shape.
1129
+ * @param dataType An ExecuTorchDataType value specifying the element type.
1130
+ * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the
1131
+ * shape is static or dynamic.
1132
+ * @return A new ExecuTorchTensor instance filled with random values.
1133
+ */
1134
+ + (instancetype)randomTensorWithShape:(NSArray<NSNumber *> *)shape
1135
+ dataType:(ExecuTorchDataType)dataType
1136
+ shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism
1137
+ NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
1138
+
1139
+ /**
1140
+ * Creates a tensor with random values, with the specified shape (using dynamic
1141
+ * bound shape) and data type.
1142
+ *
1143
+ * @param shape An NSArray of NSNumber objects representing the desired shape.
1144
+ * @param dataType An ExecuTorchDataType value specifying the element type.
1145
+ * @return A new ExecuTorchTensor instance filled with random values.
1146
+ */
1147
+ + (instancetype)randomTensorWithShape:(NSArray<NSNumber *> *)shape
1148
+ dataType:(ExecuTorchDataType)dataType
1149
+ NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
1150
+
1151
+ /**
1152
+ * Creates a tensor with random values similar to an existing tensor, with the
1153
+ * specified data type and shape dynamism.
1154
+ *
1155
+ * @param tensor An existing ExecuTorchTensor instance whose shape and strides
1156
+ * are used.
1157
+ * @param dataType An ExecuTorchDataType value specifying the desired element
1158
+ * type.
1159
+ * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the
1160
+ * shape is static or dynamic.
1161
+ * @return A new ExecuTorchTensor instance filled with random values.
1162
+ */
1163
+ + (instancetype)randomTensorLikeTensor:(ExecuTorchTensor *)tensor
1164
+ dataType:(ExecuTorchDataType)dataType
1165
+ shapeDynamism:(ExecuTorchShapeDynamism)shapeDynamism
1166
+ NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED;
1167
+
1168
+ /**
1169
+ * Creates a tensor with random values similar to an existing tensor, with the
1170
+ * specified data type.
1171
+ *
1172
+ * @param tensor An existing ExecuTorchTensor instance whose shape and strides
1173
+ * are used.
1174
+ * @param dataType An ExecuTorchDataType value specifying the desired element
1175
+ * type.
1176
+ * @return A new ExecuTorchTensor instance filled with random values.
1177
+ */
1178
+ + (instancetype)randomTensorLikeTensor:(ExecuTorchTensor *)tensor
1179
+ dataType:(ExecuTorchDataType)dataType
1180
+ NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
1181
+
1182
+ /**
1183
+ * Creates a tensor with random values similar to an existing tensor.
1184
+ *
1185
+ * @param tensor An existing ExecuTorchTensor instance.
1186
+ * @return A new ExecuTorchTensor instance filled with random values.
1187
+ */
1188
+ + (instancetype)randomTensorLikeTensor:(ExecuTorchTensor *)tensor
1189
+ NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
1190
+
1191
+ @end
1192
+
1193
+ #pragma mark - RandomNormal Category
1194
+
1195
+ @interface ExecuTorchTensor (RandomNormal)
1196
+
1197
+ /**
1198
+ * Creates a tensor with random values drawn from a normal distribution,
1199
+ * with full specification of shape, strides, data type, and shape dynamism.
1200
+ *
1201
+ * @param shape An NSArray of NSNumber objects representing the desired shape.
1202
+ * @param strides An NSArray of NSNumber objects representing the desired
1203
+ * strides.
1204
+ * @param dataType An ExecuTorchDataType value specifying the element type.
1205
+ * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the
1206
+ * shape is static or dynamic.
1207
+ * @return A new ExecuTorchTensor instance filled with values from a normal
1208
+ * distribution.
1209
+ */
1210
+ + (instancetype)randomNormalTensorWithShape:(NSArray<NSNumber *> *)shape
1211
+ strides:(NSArray<NSNumber *> *)strides
1212
+ dataType:(ExecuTorchDataType)dataType
1213
+ shapeDynamism:
1214
+ (ExecuTorchShapeDynamism)shapeDynamism
1215
+ NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED;
1216
+
1217
+ /**
1218
+ * Creates a tensor with random values drawn from a normal distribution,
1219
+ * with the specified shape and data type.
1220
+ *
1221
+ * @param shape An NSArray of NSNumber objects representing the desired shape.
1222
+ * @param dataType An ExecuTorchDataType value specifying the element type.
1223
+ * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the
1224
+ * shape is static or dynamic.
1225
+ * @return A new ExecuTorchTensor instance filled with values from a normal
1226
+ * distribution.
1227
+ */
1228
+ + (instancetype)randomNormalTensorWithShape:(NSArray<NSNumber *> *)shape
1229
+ dataType:(ExecuTorchDataType)dataType
1230
+ shapeDynamism:
1231
+ (ExecuTorchShapeDynamism)shapeDynamism
1232
+ NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
1233
+
1234
+ /**
1235
+ * Creates a tensor with random values drawn from a normal distribution,
1236
+ * with the specified shape (using dynamic bound shape) and data type.
1237
+ *
1238
+ * @param shape An NSArray of NSNumber objects representing the desired shape.
1239
+ * @param dataType An ExecuTorchDataType value specifying the element type.
1240
+ * @return A new ExecuTorchTensor instance filled with values from a normal
1241
+ * distribution.
1242
+ */
1243
+ + (instancetype)randomNormalTensorWithShape:(NSArray<NSNumber *> *)shape
1244
+ dataType:(ExecuTorchDataType)dataType
1245
+ NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
1246
+
1247
+ /**
1248
+ * Creates a tensor with random normal values similar to an existing tensor,
1249
+ * with the specified data type and shape dynamism.
1250
+ *
1251
+ * @param tensor An existing ExecuTorchTensor instance whose shape and strides
1252
+ * are used.
1253
+ * @param dataType An ExecuTorchDataType value specifying the desired element
1254
+ * type.
1255
+ * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the
1256
+ * shape is static or dynamic.
1257
+ * @return A new ExecuTorchTensor instance filled with values from a normal
1258
+ * distribution.
1259
+ */
1260
+ + (instancetype)randomNormalTensorLikeTensor:(ExecuTorchTensor *)tensor
1261
+ dataType:(ExecuTorchDataType)dataType
1262
+ shapeDynamism:
1263
+ (ExecuTorchShapeDynamism)shapeDynamism
1264
+ NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED;
1265
+
1266
+ /**
1267
+ * Creates a tensor with random normal values similar to an existing tensor,
1268
+ * with the specified data type.
1269
+ *
1270
+ * @param tensor An existing ExecuTorchTensor instance whose shape and strides
1271
+ * are used.
1272
+ * @param dataType An ExecuTorchDataType value specifying the desired element
1273
+ * type.
1274
+ * @return A new ExecuTorchTensor instance filled with values from a normal
1275
+ * distribution.
1276
+ */
1277
+ + (instancetype)randomNormalTensorLikeTensor:(ExecuTorchTensor *)tensor
1278
+ dataType:(ExecuTorchDataType)dataType
1279
+ NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
1280
+
1281
+ /**
1282
+ * Creates a tensor with random normal values similar to an existing tensor.
1283
+ *
1284
+ * @param tensor An existing ExecuTorchTensor instance.
1285
+ * @return A new ExecuTorchTensor instance filled with values from a normal
1286
+ * distribution.
1287
+ */
1288
+ + (instancetype)randomNormalTensorLikeTensor:(ExecuTorchTensor *)tensor
1289
+ NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
1290
+
1291
+ @end
1292
+
1293
+ #pragma mark - RandomInteger Category
1294
+
1295
+ @interface ExecuTorchTensor (RandomInteger)
1296
+
1297
+ /**
1298
+ * Creates a tensor with random integer values in the specified range,
1299
+ * with full specification of shape, strides, data type, and shape dynamism.
1300
+ *
1301
+ * @param low An NSInteger specifying the inclusive lower bound of random
1302
+ * values.
1303
+ * @param high An NSInteger specifying the exclusive upper bound of random
1304
+ * values.
1305
+ * @param shape An NSArray of NSNumber objects representing the desired shape.
1306
+ * @param strides An NSArray of NSNumber objects representing the desired
1307
+ * strides.
1308
+ * @param dataType An ExecuTorchDataType value specifying the element type.
1309
+ * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the
1310
+ * shape is static or dynamic.
1311
+ * @return A new ExecuTorchTensor instance filled with random integer values.
1312
+ */
1313
+ + (instancetype)randomIntegerTensorWithLow:(NSInteger)low
1314
+ high:(NSInteger)high
1315
+ shape:(NSArray<NSNumber *> *)shape
1316
+ strides:(NSArray<NSNumber *> *)strides
1317
+ dataType:(ExecuTorchDataType)dataType
1318
+ shapeDynamism:
1319
+ (ExecuTorchShapeDynamism)shapeDynamism
1320
+ NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED;
1321
+
1322
+ /**
1323
+ * Creates a tensor with random integer values in the specified range,
1324
+ * with the given shape and data type.
1325
+ *
1326
+ * @param low An NSInteger specifying the inclusive lower bound of random
1327
+ * values.
1328
+ * @param high An NSInteger specifying the exclusive upper bound of random
1329
+ * values.
1330
+ * @param shape An NSArray of NSNumber objects representing the desired shape.
1331
+ * @param dataType An ExecuTorchDataType value specifying the element type.
1332
+ * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the
1333
+ * shape is static or dynamic.
1334
+ * @return A new ExecuTorchTensor instance filled with random integer values.
1335
+ */
1336
+ + (instancetype)randomIntegerTensorWithLow:(NSInteger)low
1337
+ high:(NSInteger)high
1338
+ shape:(NSArray<NSNumber *> *)shape
1339
+ dataType:(ExecuTorchDataType)dataType
1340
+ shapeDynamism:
1341
+ (ExecuTorchShapeDynamism)shapeDynamism
1342
+ NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
1343
+
1344
+ /**
1345
+ * Creates a tensor with random integer values in the specified range,
1346
+ * with the given shape (using dynamic bound shape) and data type.
1347
+ *
1348
+ * @param low An NSInteger specifying the inclusive lower bound of random
1349
+ * values.
1350
+ * @param high An NSInteger specifying the exclusive upper bound of random
1351
+ * values.
1352
+ * @param shape An NSArray of NSNumber objects representing the desired shape.
1353
+ * @param dataType An ExecuTorchDataType value specifying the element type.
1354
+ * @return A new ExecuTorchTensor instance filled with random integer values.
1355
+ */
1356
+ + (instancetype)randomIntegerTensorWithLow:(NSInteger)low
1357
+ high:(NSInteger)high
1358
+ shape:(NSArray<NSNumber *> *)shape
1359
+ dataType:(ExecuTorchDataType)dataType
1360
+ NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
1361
+
1362
+ /**
1363
+ * Creates a tensor with random integer values in the specified range, similar
1364
+ * to an existing tensor, with the given data type and shape dynamism.
1365
+ *
1366
+ * @param tensor An existing ExecuTorchTensor instance whose shape and strides
1367
+ * are used.
1368
+ * @param low An NSInteger specifying the inclusive lower bound of random
1369
+ * values.
1370
+ * @param high An NSInteger specifying the exclusive upper bound of random
1371
+ * values.
1372
+ * @param dataType An ExecuTorchDataType value specifying the element type.
1373
+ * @param shapeDynamism An ExecuTorchShapeDynamism value specifying whether the
1374
+ * shape is static or dynamic.
1375
+ * @return A new ExecuTorchTensor instance filled with random integer values.
1376
+ */
1377
+ + (instancetype)randomIntegerTensorLikeTensor:(ExecuTorchTensor *)tensor
1378
+ low:(NSInteger)low
1379
+ high:(NSInteger)high
1380
+ dataType:(ExecuTorchDataType)dataType
1381
+ shapeDynamism:
1382
+ (ExecuTorchShapeDynamism)shapeDynamism
1383
+ NS_REFINED_FOR_SWIFT NS_RETURNS_RETAINED;
1384
+
1385
+ /**
1386
+ * Creates a tensor with random integer values in the specified range, similar
1387
+ * to an existing tensor, with the given data type.
1388
+ *
1389
+ * @param tensor An existing ExecuTorchTensor instance whose shape and strides
1390
+ * are used.
1391
+ * @param low An NSInteger specifying the inclusive lower bound of random
1392
+ * values.
1393
+ * @param high An NSInteger specifying the exclusive upper bound of random
1394
+ * values.
1395
+ * @param dataType An ExecuTorchDataType value specifying the element type.
1396
+ * @return A new ExecuTorchTensor instance filled with random integer values.
1397
+ */
1398
+ + (instancetype)randomIntegerTensorLikeTensor:(ExecuTorchTensor *)tensor
1399
+ low:(NSInteger)low
1400
+ high:(NSInteger)high
1401
+ dataType:(ExecuTorchDataType)dataType
1402
+ NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
1403
+
1404
+ /**
1405
+ * Creates a tensor with random integer values in the specified range, similar
1406
+ * to an existing tensor.
1407
+ *
1408
+ * @param tensor An existing ExecuTorchTensor instance.
1409
+ * @param low An NSInteger specifying the inclusive lower bound of random
1410
+ * values.
1411
+ * @param high An NSInteger specifying the exclusive upper bound of random
1412
+ * values.
1413
+ * @return A new ExecuTorchTensor instance filled with random integer values.
1414
+ */
1415
+ + (instancetype)randomIntegerTensorLikeTensor:(ExecuTorchTensor *)tensor
1416
+ low:(NSInteger)low
1417
+ high:(NSInteger)high
1418
+ NS_SWIFT_UNAVAILABLE("")NS_RETURNS_RETAINED;
1419
+
1420
+ @end
1421
+
742
1422
  NS_ASSUME_NONNULL_END