objc2_ml_compute/generated/MLCTensor.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10extern_class!(
11 /// A tensor object
12 ///
13 /// See also [Apple's documentation](https://developer.apple.com/documentation/mlcompute/mlctensor?language=objc)
14 #[unsafe(super(NSObject))]
15 #[derive(Debug, PartialEq, Eq, Hash)]
16 #[deprecated]
17 pub struct MLCTensor;
18);
19
20extern_conformance!(
21 unsafe impl NSCopying for MLCTensor {}
22);
23
24unsafe impl CopyingHelper for MLCTensor {
25 type Result = Self;
26}
27
28extern_conformance!(
29 unsafe impl NSObjectProtocol for MLCTensor {}
30);
31
32impl MLCTensor {
33 extern_methods!(
34 /// The tensor ID
35 ///
36 /// A unique number to identify each tensor. Assigned when the tensor is created.
37 #[deprecated]
38 #[unsafe(method(tensorID))]
39 #[unsafe(method_family = none)]
40 pub unsafe fn tensorID(&self) -> NSUInteger;
41
42 #[cfg(feature = "MLCTensorDescriptor")]
43 /// The tensor descriptor
44 #[deprecated]
45 #[unsafe(method(descriptor))]
46 #[unsafe(method_family = none)]
47 pub unsafe fn descriptor(&self) -> Retained<MLCTensorDescriptor>;
48
49 /// The tensor data
50 #[deprecated]
51 #[unsafe(method(data))]
52 #[unsafe(method_family = none)]
53 pub unsafe fn data(&self) -> Option<Retained<NSData>>;
54
55 /// A string to help identify this object.
56 #[deprecated]
57 #[unsafe(method(label))]
58 #[unsafe(method_family = none)]
59 pub unsafe fn label(&self) -> Retained<NSString>;
60
61 /// Setter for [`label`][Self::label].
62 #[deprecated]
63 #[unsafe(method(setLabel:))]
64 #[unsafe(method_family = none)]
65 pub unsafe fn setLabel(&self, label: &NSString);
66
67 #[cfg(feature = "MLCDevice")]
68 /// The device associated with this tensor.
69 #[deprecated]
70 #[unsafe(method(device))]
71 #[unsafe(method_family = none)]
72 pub unsafe fn device(&self) -> Option<Retained<MLCDevice>>;
73
74 #[cfg(feature = "MLCTensorData")]
75 /// These are the host side optimizer (momentum and velocity) buffers which developers can query and initialize
76 ///
77 /// When customizing optimizer data, the contents of these buffers must be initialized before executing optimizer
78 /// update for a graph.
79 #[deprecated]
80 #[unsafe(method(optimizerData))]
81 #[unsafe(method_family = none)]
82 pub unsafe fn optimizerData(&self) -> Retained<NSArray<MLCTensorData>>;
83
84 #[cfg(feature = "MLCTensorOptimizerDeviceData")]
85 /// These are the device side optimizer (momentum and velocity) buffers which developers can query
86 #[deprecated]
87 #[unsafe(method(optimizerDeviceData))]
88 #[unsafe(method_family = none)]
89 pub unsafe fn optimizerDeviceData(&self)
90 -> Retained<NSArray<MLCTensorOptimizerDeviceData>>;
91
92 #[deprecated]
93 #[unsafe(method(new))]
94 #[unsafe(method_family = new)]
95 pub unsafe fn new() -> Retained<Self>;
96
97 #[deprecated]
98 #[unsafe(method(init))]
99 #[unsafe(method_family = init)]
100 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
101
102 #[cfg(feature = "MLCTensorDescriptor")]
103 /// Create a MLCTensor object
104 ///
105 /// Create a tensor object without any data
106 ///
107 /// Returns: A new MLCTensor object
108 #[deprecated]
109 #[unsafe(method(tensorWithDescriptor:))]
110 #[unsafe(method_family = none)]
111 pub unsafe fn tensorWithDescriptor(
112 tensor_descriptor: &MLCTensorDescriptor,
113 ) -> Retained<Self>;
114
115 #[cfg(all(feature = "MLCTensorDescriptor", feature = "MLCTypes"))]
116 /// Create a MLCTensor object
117 ///
118 /// Create a tensor object initialized with a random initializer such as Glorot Uniform.
119 ///
120 /// Parameter `tensorDescriptor`: The tensor descriptor
121 ///
122 /// Parameter `randomInitializerType`: The random initializer type
123 ///
124 /// Returns: A new MLCTensor object
125 #[deprecated]
126 #[unsafe(method(tensorWithDescriptor:randomInitializerType:))]
127 #[unsafe(method_family = none)]
128 pub unsafe fn tensorWithDescriptor_randomInitializerType(
129 tensor_descriptor: &MLCTensorDescriptor,
130 random_initializer_type: MLCRandomInitializerType,
131 ) -> Retained<Self>;
132
133 #[cfg(feature = "MLCTensorDescriptor")]
134 /// Create a MLCTensor object
135 ///
136 /// Create a tensor object with a MLCTensorData object that specifies the tensor data buffer
137 ///
138 /// Parameter `tensorDescriptor`: The tensor descriptor
139 ///
140 /// Parameter `fillData`: The scalar data to fill to tensor with
141 ///
142 /// Returns: A new MLCTensor object
143 #[deprecated]
144 #[unsafe(method(tensorWithDescriptor:fillWithData:))]
145 #[unsafe(method_family = none)]
146 pub unsafe fn tensorWithDescriptor_fillWithData(
147 tensor_descriptor: &MLCTensorDescriptor,
148 fill_data: &NSNumber,
149 ) -> Retained<Self>;
150
151 #[cfg(all(feature = "MLCTensorData", feature = "MLCTensorDescriptor"))]
152 /// Create a MLCTensor object
153 ///
154 /// Create a tensor object with a MLCTensorData object that specifies the tensor data buffer
155 ///
156 /// Parameter `tensorDescriptor`: The tensor descriptor
157 ///
158 /// Parameter `data`: The random initializer type
159 ///
160 /// Returns: A new MLCTensor object
161 #[deprecated]
162 #[unsafe(method(tensorWithDescriptor:data:))]
163 #[unsafe(method_family = none)]
164 pub unsafe fn tensorWithDescriptor_data(
165 tensor_descriptor: &MLCTensorDescriptor,
166 data: &MLCTensorData,
167 ) -> Retained<Self>;
168
169 /// Create a MLCTensor object
170 ///
171 /// Create a tensor object without any data. The tensor data type is MLCDataTypeFloat32.
172 ///
173 /// Parameter `shape`: The tensor shape
174 ///
175 /// Returns: A new MLCTensor object
176 #[deprecated]
177 #[unsafe(method(tensorWithShape:))]
178 #[unsafe(method_family = none)]
179 pub unsafe fn tensorWithShape(shape: &NSArray<NSNumber>) -> Retained<Self>;
180
181 #[cfg(feature = "MLCTypes")]
182 /// Create a MLCTensor object
183 ///
184 /// Create a tensor object initialized with a random initializer such as Glorot Uniform.
185 /// The tensor data type is MLCDataTypeFloat32
186 ///
187 /// Parameter `shape`: The tensor shape
188 ///
189 /// Parameter `randomInitializerType`: The random initializer type
190 ///
191 /// Returns: A new MLCTensor object
192 #[deprecated]
193 #[unsafe(method(tensorWithShape:randomInitializerType:))]
194 #[unsafe(method_family = none)]
195 pub unsafe fn tensorWithShape_randomInitializerType(
196 shape: &NSArray<NSNumber>,
197 random_initializer_type: MLCRandomInitializerType,
198 ) -> Retained<Self>;
199
200 #[cfg(feature = "MLCTypes")]
201 /// Create a MLCTensor object
202 ///
203 /// Create a tensor object initialized with a random initializer such as Glorot Uniform.
204 /// The tensor data type is MLCDataTypeFloat32
205 ///
206 /// Parameter `shape`: The tensor shape
207 ///
208 /// Parameter `randomInitializerType`: The random initializer type
209 ///
210 /// Parameter `dataType`: The tensor data type
211 ///
212 /// Returns: A new MLCTensor object
213 #[deprecated]
214 #[unsafe(method(tensorWithShape:randomInitializerType:dataType:))]
215 #[unsafe(method_family = none)]
216 pub unsafe fn tensorWithShape_randomInitializerType_dataType(
217 shape: &NSArray<NSNumber>,
218 random_initializer_type: MLCRandomInitializerType,
219 data_type: MLCDataType,
220 ) -> Retained<Self>;
221
222 #[cfg(feature = "MLCTypes")]
223 /// Create a MLCTensor object
224 ///
225 /// Create a tensor object without any data
226 ///
227 /// Parameter `shape`: The tensor shape
228 ///
229 /// Parameter `dataType`: The tensor data type
230 ///
231 /// Returns: A new MLCTensor object
232 #[deprecated]
233 #[unsafe(method(tensorWithShape:dataType:))]
234 #[unsafe(method_family = none)]
235 pub unsafe fn tensorWithShape_dataType(
236 shape: &NSArray<NSNumber>,
237 data_type: MLCDataType,
238 ) -> Retained<Self>;
239
240 #[cfg(all(feature = "MLCTensorData", feature = "MLCTypes"))]
241 /// Create a MLCTensor object
242 ///
243 /// Create a tensor object with data
244 ///
245 /// Parameter `shape`: The tensor shape
246 ///
247 /// Parameter `data`: The tensor data
248 ///
249 /// Parameter `dataType`: The tensor data type
250 ///
251 /// Returns: A new MLCTensor object
252 #[deprecated]
253 #[unsafe(method(tensorWithShape:data:dataType:))]
254 #[unsafe(method_family = none)]
255 pub unsafe fn tensorWithShape_data_dataType(
256 shape: &NSArray<NSNumber>,
257 data: &MLCTensorData,
258 data_type: MLCDataType,
259 ) -> Retained<Self>;
260
261 #[cfg(feature = "MLCTypes")]
262 /// Create a MLCTensor object
263 ///
264 /// Create a tensor object with data
265 ///
266 /// Parameter `shape`: The tensor shape
267 ///
268 /// Parameter `fillData`: The scalar value to initialize the tensor data with
269 ///
270 /// Parameter `dataType`: The tensor data type
271 ///
272 /// Returns: A new MLCTensor object
273 #[deprecated]
274 #[unsafe(method(tensorWithShape:fillWithData:dataType:))]
275 #[unsafe(method_family = none)]
276 pub unsafe fn tensorWithShape_fillWithData_dataType(
277 shape: &NSArray<NSNumber>,
278 fill_data: &NSNumber,
279 data_type: MLCDataType,
280 ) -> Retained<Self>;
281
282 /// Create a MLCTensor object
283 ///
284 /// Create a NCHW tensor object with tensor data type = MLCDataTypeFloat32
285 ///
286 /// Parameter `width`: The tensor width
287 ///
288 /// Parameter `height`: The tensor height
289 ///
290 /// Parameter `featureChannelCount`: Number of feature channels
291 ///
292 /// Parameter `batchSize`: The tensor batch size
293 ///
294 /// Returns: A new MLCTensor object
295 #[deprecated]
296 #[unsafe(method(tensorWithWidth:height:featureChannelCount:batchSize:))]
297 #[unsafe(method_family = none)]
298 pub unsafe fn tensorWithWidth_height_featureChannelCount_batchSize(
299 width: NSUInteger,
300 height: NSUInteger,
301 feature_channel_count: NSUInteger,
302 batch_size: NSUInteger,
303 ) -> Retained<Self>;
304
305 #[cfg(feature = "MLCTypes")]
306 /// Create a MLCTensor object
307 ///
308 /// Create a NCHW tensor object initialized with a scalar value
309 ///
310 /// Parameter `width`: The tensor width
311 ///
312 /// Parameter `height`: The tensor height
313 ///
314 /// Parameter `featureChannelCount`: Number of feature channels
315 ///
316 /// Parameter `batchSize`: The tensor batch size
317 ///
318 /// Parameter `fillData`: The scalar value to initialize the tensor data with
319 ///
320 /// Parameter `dataType`: The tensor data type
321 ///
322 /// Returns: A new MLCTensorData object
323 #[deprecated]
324 #[unsafe(method(tensorWithWidth:height:featureChannelCount:batchSize:fillWithData:dataType:))]
325 #[unsafe(method_family = none)]
326 pub unsafe fn tensorWithWidth_height_featureChannelCount_batchSize_fillWithData_dataType(
327 width: NSUInteger,
328 height: NSUInteger,
329 feature_channel_count: NSUInteger,
330 batch_size: NSUInteger,
331 fill_data: c_float,
332 data_type: MLCDataType,
333 ) -> Retained<Self>;
334
335 #[cfg(feature = "MLCTypes")]
336 /// Create a MLCTensor object
337 ///
338 /// Create a NCHW tensor object initialized with a random initializer type.
339 /// The tensor data type is MLCDataTypeFloat32
340 ///
341 /// Parameter `width`: The tensor width
342 ///
343 /// Parameter `height`: The tensor height
344 ///
345 /// Parameter `featureChannelCount`: Number of feature channels
346 ///
347 /// Parameter `batchSize`: The tensor batch size
348 ///
349 /// Parameter `randomInitializerType`: The random initializer type
350 ///
351 /// Returns: A new MLCTensor object
352 #[deprecated]
353 #[unsafe(method(tensorWithWidth:height:featureChannelCount:batchSize:randomInitializerType:))]
354 #[unsafe(method_family = none)]
355 pub unsafe fn tensorWithWidth_height_featureChannelCount_batchSize_randomInitializerType(
356 width: NSUInteger,
357 height: NSUInteger,
358 feature_channel_count: NSUInteger,
359 batch_size: NSUInteger,
360 random_initializer_type: MLCRandomInitializerType,
361 ) -> Retained<Self>;
362
363 #[cfg(feature = "MLCTensorData")]
364 /// Create a MLCTensor object
365 ///
366 /// Create a NCHW tensor object with a tensor data object
367 /// The tensor data type is MLCDataTypeFloat32.
368 ///
369 /// Parameter `width`: The tensor width
370 ///
371 /// Parameter `height`: The tensor height
372 ///
373 /// Parameter `featureChannelCount`: Number of feature channels
374 ///
375 /// Parameter `batchSize`: The tensor batch size
376 ///
377 /// Parameter `data`: The tensor data
378 ///
379 /// Returns: A new MLCTensor object
380 #[deprecated]
381 #[unsafe(method(tensorWithWidth:height:featureChannelCount:batchSize:data:))]
382 #[unsafe(method_family = none)]
383 pub unsafe fn tensorWithWidth_height_featureChannelCount_batchSize_data(
384 width: NSUInteger,
385 height: NSUInteger,
386 feature_channel_count: NSUInteger,
387 batch_size: NSUInteger,
388 data: &MLCTensorData,
389 ) -> Retained<Self>;
390
391 #[cfg(all(feature = "MLCTensorData", feature = "MLCTypes"))]
392 /// Create a MLCTensor object
393 ///
394 /// Create a NCHW tensor object with a tensor data object
395 /// The tensor data type is MLCDataTypeFloat32.
396 ///
397 /// Parameter `width`: The tensor width
398 ///
399 /// Parameter `height`: The tensor height
400 ///
401 /// Parameter `featureChannelCount`: Number of feature channels
402 ///
403 /// Parameter `batchSize`: The tensor batch size
404 ///
405 /// Parameter `data`: The tensor data
406 ///
407 /// Parameter `dataType`: The tensor data type
408 ///
409 /// Returns: A new MLCTensor object
410 #[deprecated]
411 #[unsafe(method(tensorWithWidth:height:featureChannelCount:batchSize:data:dataType:))]
412 #[unsafe(method_family = none)]
413 pub unsafe fn tensorWithWidth_height_featureChannelCount_batchSize_data_dataType(
414 width: NSUInteger,
415 height: NSUInteger,
416 feature_channel_count: NSUInteger,
417 batch_size: NSUInteger,
418 data: &MLCTensorData,
419 data_type: MLCDataType,
420 ) -> Retained<Self>;
421
422 /// Create a MLCTensor object
423 ///
424 /// Create a tensor typically used by a recurrent layer
425 /// The tensor data type is MLCDataTypeFloat32.
426 ///
427 /// Parameter `sequenceLength`: The length of sequences stored in the tensor
428 ///
429 /// Parameter `featureChannelCount`: Number of feature channels
430 ///
431 /// Parameter `batchSize`: The tensor batch size
432 ///
433 /// Returns: A new MLCTensor object
434 #[deprecated]
435 #[unsafe(method(tensorWithSequenceLength:featureChannelCount:batchSize:))]
436 #[unsafe(method_family = none)]
437 pub unsafe fn tensorWithSequenceLength_featureChannelCount_batchSize(
438 sequence_length: NSUInteger,
439 feature_channel_count: NSUInteger,
440 batch_size: NSUInteger,
441 ) -> Retained<Self>;
442
443 #[cfg(feature = "MLCTypes")]
444 /// Create a MLCTensor object
445 ///
446 /// Create a tensor typically used by a recurrent layer
447 /// The tensor data type is MLCDataTypeFloat32.
448 ///
449 /// Parameter `sequenceLength`: The length of sequences stored in the tensor
450 ///
451 /// Parameter `featureChannelCount`: Number of feature channels
452 ///
453 /// Parameter `batchSize`: The tensor batch size
454 ///
455 /// Parameter `randomInitializerType`: The random initializer type
456 ///
457 /// Returns: A new MLCTensor object
458 #[deprecated]
459 #[unsafe(method(tensorWithSequenceLength:featureChannelCount:batchSize:randomInitializerType:))]
460 #[unsafe(method_family = none)]
461 pub unsafe fn tensorWithSequenceLength_featureChannelCount_batchSize_randomInitializerType(
462 sequence_length: NSUInteger,
463 feature_channel_count: NSUInteger,
464 batch_size: NSUInteger,
465 random_initializer_type: MLCRandomInitializerType,
466 ) -> Retained<Self>;
467
468 #[cfg(feature = "MLCTensorData")]
469 /// Create a MLCTensor object
470 ///
471 /// Create a tensor typically used by a recurrent layer
472 /// The tensor data type is MLCDataTypeFloat32.
473 ///
474 /// Parameter `sequenceLength`: The length of sequences stored in the tensor
475 ///
476 /// Parameter `featureChannelCount`: Number of feature channels
477 ///
478 /// Parameter `batchSize`: The tensor batch size
479 ///
480 /// Parameter `data`: The tensor data
481 ///
482 /// Returns: A new MLCTensor object
483 #[deprecated]
484 #[unsafe(method(tensorWithSequenceLength:featureChannelCount:batchSize:data:))]
485 #[unsafe(method_family = none)]
486 pub unsafe fn tensorWithSequenceLength_featureChannelCount_batchSize_data(
487 sequence_length: NSUInteger,
488 feature_channel_count: NSUInteger,
489 batch_size: NSUInteger,
490 data: Option<&MLCTensorData>,
491 ) -> Retained<Self>;
492
493 #[cfg(feature = "MLCTypes")]
494 /// Create a MLCTensor object
495 ///
496 /// Create a tensor of variable length sequences typically used by a recurrent layer
497 /// The tensor data type is MLCDataTypeFloat32.
498 ///
499 /// Parameter `sequenceLengths`: An array of sequence lengths
500 ///
501 /// Parameter `sortedSequences`: A flag to indicate if the sequence lengths are sorted. If yes, they must be sorted in descending order
502 ///
503 /// Parameter `featureChannelCount`: Number of feature channels
504 ///
505 /// Parameter `batchSize`: The tensor batch size
506 ///
507 /// Parameter `randomInitializerType`: The random initializer type
508 ///
509 /// Returns: A new MLCTensor object
510 #[deprecated]
511 #[unsafe(method(tensorWithSequenceLengths:sortedSequences:featureChannelCount:batchSize:randomInitializerType:))]
512 #[unsafe(method_family = none)]
513 pub unsafe fn tensorWithSequenceLengths_sortedSequences_featureChannelCount_batchSize_randomInitializerType(
514 sequence_lengths: &NSArray<NSNumber>,
515 sorted_sequences: bool,
516 feature_channel_count: NSUInteger,
517 batch_size: NSUInteger,
518 random_initializer_type: MLCRandomInitializerType,
519 ) -> Option<Retained<Self>>;
520
521 #[cfg(feature = "MLCTensorData")]
522 /// Create a MLCTensor object
523 ///
524 /// Create a tensor of variable length sequences typically used by a recurrent layer
525 /// The tensor data type is MLCDataTypeFloat32.
526 ///
527 /// Parameter `sequenceLengths`: An array of sequence lengths
528 ///
529 /// Parameter `sortedSequences`: A flag to indicate if the sequence lengths are sorted. If yes, they must be sorted in descending order
530 ///
531 /// Parameter `featureChannelCount`: Number of feature channels
532 ///
533 /// Parameter `batchSize`: The tensor batch size
534 ///
535 /// Parameter `data`: The tensor data
536 ///
537 /// Returns: A new MLCTensor object
538 #[deprecated]
539 #[unsafe(method(tensorWithSequenceLengths:sortedSequences:featureChannelCount:batchSize:data:))]
540 #[unsafe(method_family = none)]
541 pub unsafe fn tensorWithSequenceLengths_sortedSequences_featureChannelCount_batchSize_data(
542 sequence_lengths: &NSArray<NSNumber>,
543 sorted_sequences: bool,
544 feature_channel_count: NSUInteger,
545 batch_size: NSUInteger,
546 data: Option<&MLCTensorData>,
547 ) -> Option<Retained<Self>>;
548
549 /// Returns a Boolean value indicating whether the underlying data has valid floating-point numerics, i.e. it
550 /// does not contain NaN or INF floating-point values.
551 #[deprecated]
552 #[unsafe(method(hasValidNumerics))]
553 #[unsafe(method_family = none)]
554 pub unsafe fn hasValidNumerics(&self) -> bool;
555
556 /// Synchronize the data in host memory.
557 ///
558 /// Synchronize the data in host memory i.e. tensor.data with latest contents in device memory
559 /// This should only be called once the graph that this tensor is used with has finished execution;
560 /// Otherwise the results in device memory may not be up to date.
561 /// NOTE: This method should not be called from a completion callback when device is the GPU.
562 ///
563 /// Returns: Returns YES if success, NO if there is a failure to synchronize
564 #[deprecated]
565 #[unsafe(method(synchronizeData))]
566 #[unsafe(method_family = none)]
567 pub unsafe fn synchronizeData(&self) -> bool;
568
569 /// Synchronize the optimizer data in host memory.
570 ///
571 /// Synchronize the optimizer data in host memory with latest contents in device memory
572 /// This should only be called once the graph that this tensor is used with has finished execution;
573 /// Otherwise the results in device memory may not be up to date.
574 /// NOTE: This method should not be called from a completion callback when device is the GPU.
575 ///
576 /// Returns: Returns YES if success, NO if there is a failure to synchronize
577 #[deprecated]
578 #[unsafe(method(synchronizeOptimizerData))]
579 #[unsafe(method_family = none)]
580 pub unsafe fn synchronizeOptimizerData(&self) -> bool;
581
582 /// Copy tensor data from device memory to user specified memory
583 ///
584 /// Before copying tensor data from device memory, one may need to synchronize the device memory for example
585 /// when device is the GPU. The synchronizeWithDevice argumet can be set appropraitely to indicate this.
586 /// For CPU this is ignored. If the tensor has been specified in outputs of a graph using addOutputs,
587 /// synchronizeWithDevice should be set to NO.
588 /// NOTE: This method should only be called once the graph that this tensor is used with has finished execution;
589 /// Otherwise the results in device memory may not be up to date. synchronizeWithDevice must be set to NO
590 /// when this method is called from a completion callback for GPU.
591 ///
592 /// Parameter `bytes`: The user specified data in which to copy
593 ///
594 /// Parameter `length`: The size in bytes to copy
595 ///
596 /// Parameter `synchronizeWithDevice`: Whether to synchronize device memory if device is GPU
597 ///
598 /// Returns: Returns YES if success, NO if there is a failure to synchronize
599 #[deprecated]
600 #[unsafe(method(copyDataFromDeviceMemoryToBytes:length:synchronizeWithDevice:))]
601 #[unsafe(method_family = none)]
602 pub unsafe fn copyDataFromDeviceMemoryToBytes_length_synchronizeWithDevice(
603 &self,
604 bytes: NonNull<c_void>,
605 length: NSUInteger,
606 synchronize_with_device: bool,
607 ) -> bool;
608
609 #[cfg(all(feature = "MLCDevice", feature = "MLCTensorData"))]
610 /// Associates the given data to the tensor. If the device is GPU, also copies the data to the device memory.
611 /// Returns true if the data is successfully associated with the tensor and copied to the device.
612 ///
613 /// The caller must guarantee the lifetime of the underlying memory of
614 /// `data`for the entirety of the tensor's
615 /// lifetime. For input tensors, we recommend that the bindAndwriteData method provided by MLCTrainingGraph
616 /// and MLCInferenceGraph be used. This method should only be used to allocate and copy data to device memory
617 /// for tensors that are typically layer parameters such as weights, bias for convolution layers, beta, gamma for
618 /// normalization layers.
619 ///
620 /// Parameter `data`: The data to associated with the tensor
621 ///
622 /// Parameter `device`: The compute device
623 ///
624 /// Returns: A Boolean value indicating whether the data is successfully associated with the tensor and copied to the device.
625 #[deprecated]
626 #[unsafe(method(bindAndWriteData:toDevice:))]
627 #[unsafe(method_family = none)]
628 pub unsafe fn bindAndWriteData_toDevice(
629 &self,
630 data: &MLCTensorData,
631 device: &MLCDevice,
632 ) -> bool;
633
634 #[cfg(all(feature = "MLCTensorData", feature = "MLCTensorOptimizerDeviceData"))]
635 /// Associates the given optimizer data and device data buffers to the tensor.
636 /// Returns true if the data is successfully associated with the tensor and copied to the device.
637 ///
638 /// The caller must guarantee the lifetime of the underlying memory of
639 /// `data`for the entirety of the tensor's
640 /// lifetime. The
641 /// `deviceData`buffers are allocated by MLCompute. This method must be called
642 /// before executeOptimizerUpdateWithOptions or executeWithInputsData is called for the training graph.
643 ///
644 /// Parameter `data`: The optimizer data to be associated with the tensor
645 ///
646 /// Parameter `deviceData`: The optimizer device data to be associated with the tensor
647 ///
648 /// Returns: A Boolean value indicating whether the data is successfully associated with the tensor .
649 #[deprecated]
650 #[unsafe(method(bindOptimizerData:deviceData:))]
651 #[unsafe(method_family = none)]
652 pub unsafe fn bindOptimizerData_deviceData(
653 &self,
654 data: &NSArray<MLCTensorData>,
655 device_data: Option<&NSArray<MLCTensorOptimizerDeviceData>>,
656 ) -> bool;
657
658 #[cfg(feature = "MLCTypes")]
659 /// Converts a 32-bit floating-point tensor with given scale and a zero point
660 /// Returns a quantized tensor
661 ///
662 /// Parameter `type`: The quantized data type. Must be MLCDataTypeInt8, MLCDataTypeUInt8 or MLCDataTypeInt32
663 ///
664 /// Parameter `scale`: The scale to apply in quantization
665 ///
666 /// Parameter `bias`: The offset value that maps to float zero
667 ///
668 /// Returns: A quantized tensor
669 #[unsafe(method(tensorByQuantizingToType:scale:bias:))]
670 #[unsafe(method_family = none)]
671 pub unsafe fn tensorByQuantizingToType_scale_bias(
672 &self,
673 r#type: MLCDataType,
674 scale: c_float,
675 bias: NSInteger,
676 ) -> Option<Retained<MLCTensor>>;
677
678 #[cfg(feature = "MLCTypes")]
679 /// Converts a 32-bit floating-point tensor with given scale and a zero point
680 /// Returns a quantized tensor
681 ///
682 /// Parameter `type`: The quantized data type. Must be MLCDataTypeInt8, MLCDataTypeUInt8 or MLCDataTypeInt32
683 ///
684 /// Parameter `scale`: The scale to apply in quantization
685 ///
686 /// Parameter `bias`: The offset value that maps to float zero
687 ///
688 /// Parameter `axis`: The dimension on which to apply per-channel quantization
689 ///
690 /// Returns: A quantized tensor
691 #[unsafe(method(tensorByQuantizingToType:scale:bias:axis:))]
692 #[unsafe(method_family = none)]
693 pub unsafe fn tensorByQuantizingToType_scale_bias_axis(
694 &self,
695 r#type: MLCDataType,
696 scale: &MLCTensor,
697 bias: &MLCTensor,
698 axis: NSInteger,
699 ) -> Option<Retained<MLCTensor>>;
700
701 #[cfg(feature = "MLCTypes")]
702 /// Converts a quantized tensor to a 32-bit floating-point tensor
703 /// Returns a de-quantized tensor
704 ///
705 /// Parameter `type`: The de-quantized data type. Must be MLCFloat32
706 ///
707 /// Parameter `scale`: The scale thst was used for the quantized data
708 ///
709 /// Parameter `bias`: The offset value that maps to float zero used for the quantized data
710 ///
711 /// Parameter `axis`: The dimension on which to apply per-channel quantization
712 ///
713 /// Returns: A quantized tensor
714 #[unsafe(method(tensorByDequantizingToType:scale:bias:axis:))]
715 #[unsafe(method_family = none)]
716 pub unsafe fn tensorByDequantizingToType_scale_bias_axis(
717 &self,
718 r#type: MLCDataType,
719 scale: &MLCTensor,
720 bias: &MLCTensor,
721 axis: NSInteger,
722 ) -> Option<Retained<MLCTensor>>;
723 );
724}