#[repr(C)]pub struct MLCTensor { /* private fields */ }
MLCTensor
only.Expand description
A tensor object
See also Apple’s documentation
Implementations§
Source§impl MLCTensor
impl MLCTensor
Sourcepub unsafe fn tensorID(&self) -> NSUInteger
👎Deprecated
pub unsafe fn tensorID(&self) -> NSUInteger
The tensor ID
A unique number to identify each tensor. Assigned when the tensor is created.
Sourcepub unsafe fn descriptor(&self) -> Retained<MLCTensorDescriptor>
👎DeprecatedAvailable on crate feature MLCTensorDescriptor
only.
pub unsafe fn descriptor(&self) -> Retained<MLCTensorDescriptor>
MLCTensorDescriptor
only.The tensor descriptor
Sourcepub unsafe fn label(&self) -> Retained<NSString>
👎Deprecated
pub unsafe fn label(&self) -> Retained<NSString>
A string to help identify this object.
Sourcepub unsafe fn device(&self) -> Option<Retained<MLCDevice>>
👎DeprecatedAvailable on crate feature MLCDevice
only.
pub unsafe fn device(&self) -> Option<Retained<MLCDevice>>
MLCDevice
only.The device associated with this tensor.
Sourcepub unsafe fn optimizerData(&self) -> Retained<NSArray<MLCTensorData>>
👎DeprecatedAvailable on crate feature MLCTensorData
only.
pub unsafe fn optimizerData(&self) -> Retained<NSArray<MLCTensorData>>
MLCTensorData
only.These are the host side optimizer (momentum and velocity) buffers which developers can query and initialize
When customizing optimizer data, the contents of these buffers must be initialized before executing optimizer update for a graph.
Sourcepub unsafe fn optimizerDeviceData(
&self,
) -> Retained<NSArray<MLCTensorOptimizerDeviceData>>
👎DeprecatedAvailable on crate feature MLCTensorOptimizerDeviceData
only.
pub unsafe fn optimizerDeviceData( &self, ) -> Retained<NSArray<MLCTensorOptimizerDeviceData>>
MLCTensorOptimizerDeviceData
only.These are the device side optimizer (momentum and velocity) buffers which developers can query
pub unsafe fn new() -> Retained<Self>
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>
Sourcepub unsafe fn tensorWithDescriptor(
tensor_descriptor: &MLCTensorDescriptor,
) -> Retained<Self>
👎DeprecatedAvailable on crate feature MLCTensorDescriptor
only.
pub unsafe fn tensorWithDescriptor( tensor_descriptor: &MLCTensorDescriptor, ) -> Retained<Self>
MLCTensorDescriptor
only.Create a MLCTensor object
Create a tensor object without any data
Returns: A new MLCTensor object
Sourcepub unsafe fn tensorWithDescriptor_randomInitializerType(
tensor_descriptor: &MLCTensorDescriptor,
random_initializer_type: MLCRandomInitializerType,
) -> Retained<Self>
👎DeprecatedAvailable on crate features MLCTensorDescriptor
and MLCTypes
only.
pub unsafe fn tensorWithDescriptor_randomInitializerType( tensor_descriptor: &MLCTensorDescriptor, random_initializer_type: MLCRandomInitializerType, ) -> Retained<Self>
MLCTensorDescriptor
and MLCTypes
only.Create a MLCTensor object
Create a tensor object initialized with a random initializer such as Glorot Uniform.
Parameter tensorDescriptor
: The tensor descriptor
Parameter randomInitializerType
: The random initializer type
Returns: A new MLCTensor object
Sourcepub unsafe fn tensorWithDescriptor_fillWithData(
tensor_descriptor: &MLCTensorDescriptor,
fill_data: &NSNumber,
) -> Retained<Self>
👎DeprecatedAvailable on crate feature MLCTensorDescriptor
only.
pub unsafe fn tensorWithDescriptor_fillWithData( tensor_descriptor: &MLCTensorDescriptor, fill_data: &NSNumber, ) -> Retained<Self>
MLCTensorDescriptor
only.Create a MLCTensor object
Create a tensor object with a MLCTensorData object that specifies the tensor data buffer
Parameter tensorDescriptor
: The tensor descriptor
Parameter fillData
: The scalar data to fill to tensor with
Returns: A new MLCTensor object
Sourcepub unsafe fn tensorWithDescriptor_data(
tensor_descriptor: &MLCTensorDescriptor,
data: &MLCTensorData,
) -> Retained<Self>
👎DeprecatedAvailable on crate features MLCTensorData
and MLCTensorDescriptor
only.
pub unsafe fn tensorWithDescriptor_data( tensor_descriptor: &MLCTensorDescriptor, data: &MLCTensorData, ) -> Retained<Self>
MLCTensorData
and MLCTensorDescriptor
only.Create a MLCTensor object
Create a tensor object with a MLCTensorData object that specifies the tensor data buffer
Parameter tensorDescriptor
: The tensor descriptor
Parameter data
: The random initializer type
Returns: A new MLCTensor object
Sourcepub unsafe fn tensorWithShape(shape: &NSArray<NSNumber>) -> Retained<Self>
👎Deprecated
pub unsafe fn tensorWithShape(shape: &NSArray<NSNumber>) -> Retained<Self>
Create a MLCTensor object
Create a tensor object without any data. The tensor data type is MLCDataTypeFloat32.
Parameter shape
: The tensor shape
Returns: A new MLCTensor object
Sourcepub unsafe fn tensorWithShape_randomInitializerType(
shape: &NSArray<NSNumber>,
random_initializer_type: MLCRandomInitializerType,
) -> Retained<Self>
👎DeprecatedAvailable on crate feature MLCTypes
only.
pub unsafe fn tensorWithShape_randomInitializerType( shape: &NSArray<NSNumber>, random_initializer_type: MLCRandomInitializerType, ) -> Retained<Self>
MLCTypes
only.Create a MLCTensor object
Create a tensor object initialized with a random initializer such as Glorot Uniform. The tensor data type is MLCDataTypeFloat32
Parameter shape
: The tensor shape
Parameter randomInitializerType
: The random initializer type
Returns: A new MLCTensor object
Sourcepub unsafe fn tensorWithShape_randomInitializerType_dataType(
shape: &NSArray<NSNumber>,
random_initializer_type: MLCRandomInitializerType,
data_type: MLCDataType,
) -> Retained<Self>
👎DeprecatedAvailable on crate feature MLCTypes
only.
pub unsafe fn tensorWithShape_randomInitializerType_dataType( shape: &NSArray<NSNumber>, random_initializer_type: MLCRandomInitializerType, data_type: MLCDataType, ) -> Retained<Self>
MLCTypes
only.Create a MLCTensor object
Create a tensor object initialized with a random initializer such as Glorot Uniform. The tensor data type is MLCDataTypeFloat32
Parameter shape
: The tensor shape
Parameter randomInitializerType
: The random initializer type
Parameter dataType
: The tensor data type
Returns: A new MLCTensor object
Sourcepub unsafe fn tensorWithShape_dataType(
shape: &NSArray<NSNumber>,
data_type: MLCDataType,
) -> Retained<Self>
👎DeprecatedAvailable on crate feature MLCTypes
only.
pub unsafe fn tensorWithShape_dataType( shape: &NSArray<NSNumber>, data_type: MLCDataType, ) -> Retained<Self>
MLCTypes
only.Create a MLCTensor object
Create a tensor object without any data
Parameter shape
: The tensor shape
Parameter dataType
: The tensor data type
Returns: A new MLCTensor object
Sourcepub unsafe fn tensorWithShape_data_dataType(
shape: &NSArray<NSNumber>,
data: &MLCTensorData,
data_type: MLCDataType,
) -> Retained<Self>
👎DeprecatedAvailable on crate features MLCTensorData
and MLCTypes
only.
pub unsafe fn tensorWithShape_data_dataType( shape: &NSArray<NSNumber>, data: &MLCTensorData, data_type: MLCDataType, ) -> Retained<Self>
MLCTensorData
and MLCTypes
only.Create a MLCTensor object
Create a tensor object with data
Parameter shape
: The tensor shape
Parameter data
: The tensor data
Parameter dataType
: The tensor data type
Returns: A new MLCTensor object
Sourcepub unsafe fn tensorWithShape_fillWithData_dataType(
shape: &NSArray<NSNumber>,
fill_data: &NSNumber,
data_type: MLCDataType,
) -> Retained<Self>
👎DeprecatedAvailable on crate feature MLCTypes
only.
pub unsafe fn tensorWithShape_fillWithData_dataType( shape: &NSArray<NSNumber>, fill_data: &NSNumber, data_type: MLCDataType, ) -> Retained<Self>
MLCTypes
only.Create a MLCTensor object
Create a tensor object with data
Parameter shape
: The tensor shape
Parameter fillData
: The scalar value to initialize the tensor data with
Parameter dataType
: The tensor data type
Returns: A new MLCTensor object
Sourcepub unsafe fn tensorWithWidth_height_featureChannelCount_batchSize(
width: NSUInteger,
height: NSUInteger,
feature_channel_count: NSUInteger,
batch_size: NSUInteger,
) -> Retained<Self>
👎Deprecated
pub unsafe fn tensorWithWidth_height_featureChannelCount_batchSize( width: NSUInteger, height: NSUInteger, feature_channel_count: NSUInteger, batch_size: NSUInteger, ) -> Retained<Self>
Create a MLCTensor object
Create a NCHW tensor object with tensor data type = MLCDataTypeFloat32
Parameter width
: The tensor width
Parameter height
: The tensor height
Parameter featureChannelCount
: Number of feature channels
Parameter batchSize
: The tensor batch size
Returns: A new MLCTensor object
Sourcepub unsafe fn tensorWithWidth_height_featureChannelCount_batchSize_fillWithData_dataType(
width: NSUInteger,
height: NSUInteger,
feature_channel_count: NSUInteger,
batch_size: NSUInteger,
fill_data: c_float,
data_type: MLCDataType,
) -> Retained<Self>
👎DeprecatedAvailable on crate feature MLCTypes
only.
pub unsafe fn tensorWithWidth_height_featureChannelCount_batchSize_fillWithData_dataType( width: NSUInteger, height: NSUInteger, feature_channel_count: NSUInteger, batch_size: NSUInteger, fill_data: c_float, data_type: MLCDataType, ) -> Retained<Self>
MLCTypes
only.Create a MLCTensor object
Create a NCHW tensor object initialized with a scalar value
Parameter width
: The tensor width
Parameter height
: The tensor height
Parameter featureChannelCount
: Number of feature channels
Parameter batchSize
: The tensor batch size
Parameter fillData
: The scalar value to initialize the tensor data with
Parameter dataType
: The tensor data type
Returns: A new MLCTensorData object
Sourcepub unsafe fn tensorWithWidth_height_featureChannelCount_batchSize_randomInitializerType(
width: NSUInteger,
height: NSUInteger,
feature_channel_count: NSUInteger,
batch_size: NSUInteger,
random_initializer_type: MLCRandomInitializerType,
) -> Retained<Self>
👎DeprecatedAvailable on crate feature MLCTypes
only.
pub unsafe fn tensorWithWidth_height_featureChannelCount_batchSize_randomInitializerType( width: NSUInteger, height: NSUInteger, feature_channel_count: NSUInteger, batch_size: NSUInteger, random_initializer_type: MLCRandomInitializerType, ) -> Retained<Self>
MLCTypes
only.Create a MLCTensor object
Create a NCHW tensor object initialized with a random initializer type. The tensor data type is MLCDataTypeFloat32
Parameter width
: The tensor width
Parameter height
: The tensor height
Parameter featureChannelCount
: Number of feature channels
Parameter batchSize
: The tensor batch size
Parameter randomInitializerType
: The random initializer type
Returns: A new MLCTensor object
Sourcepub unsafe fn tensorWithWidth_height_featureChannelCount_batchSize_data(
width: NSUInteger,
height: NSUInteger,
feature_channel_count: NSUInteger,
batch_size: NSUInteger,
data: &MLCTensorData,
) -> Retained<Self>
👎DeprecatedAvailable on crate feature MLCTensorData
only.
pub unsafe fn tensorWithWidth_height_featureChannelCount_batchSize_data( width: NSUInteger, height: NSUInteger, feature_channel_count: NSUInteger, batch_size: NSUInteger, data: &MLCTensorData, ) -> Retained<Self>
MLCTensorData
only.Create a MLCTensor object
Create a NCHW tensor object with a tensor data object The tensor data type is MLCDataTypeFloat32.
Parameter width
: The tensor width
Parameter height
: The tensor height
Parameter featureChannelCount
: Number of feature channels
Parameter batchSize
: The tensor batch size
Parameter data
: The tensor data
Returns: A new MLCTensor object
Sourcepub unsafe fn tensorWithWidth_height_featureChannelCount_batchSize_data_dataType(
width: NSUInteger,
height: NSUInteger,
feature_channel_count: NSUInteger,
batch_size: NSUInteger,
data: &MLCTensorData,
data_type: MLCDataType,
) -> Retained<Self>
👎DeprecatedAvailable on crate features MLCTensorData
and MLCTypes
only.
pub unsafe fn tensorWithWidth_height_featureChannelCount_batchSize_data_dataType( width: NSUInteger, height: NSUInteger, feature_channel_count: NSUInteger, batch_size: NSUInteger, data: &MLCTensorData, data_type: MLCDataType, ) -> Retained<Self>
MLCTensorData
and MLCTypes
only.Create a MLCTensor object
Create a NCHW tensor object with a tensor data object The tensor data type is MLCDataTypeFloat32.
Parameter width
: The tensor width
Parameter height
: The tensor height
Parameter featureChannelCount
: Number of feature channels
Parameter batchSize
: The tensor batch size
Parameter data
: The tensor data
Parameter dataType
: The tensor data type
Returns: A new MLCTensor object
Sourcepub unsafe fn tensorWithSequenceLength_featureChannelCount_batchSize(
sequence_length: NSUInteger,
feature_channel_count: NSUInteger,
batch_size: NSUInteger,
) -> Retained<Self>
👎Deprecated
pub unsafe fn tensorWithSequenceLength_featureChannelCount_batchSize( sequence_length: NSUInteger, feature_channel_count: NSUInteger, batch_size: NSUInteger, ) -> Retained<Self>
Create a MLCTensor object
Create a tensor typically used by a recurrent layer The tensor data type is MLCDataTypeFloat32.
Parameter sequenceLength
: The length of sequences stored in the tensor
Parameter featureChannelCount
: Number of feature channels
Parameter batchSize
: The tensor batch size
Returns: A new MLCTensor object
Sourcepub unsafe fn tensorWithSequenceLength_featureChannelCount_batchSize_randomInitializerType(
sequence_length: NSUInteger,
feature_channel_count: NSUInteger,
batch_size: NSUInteger,
random_initializer_type: MLCRandomInitializerType,
) -> Retained<Self>
👎DeprecatedAvailable on crate feature MLCTypes
only.
pub unsafe fn tensorWithSequenceLength_featureChannelCount_batchSize_randomInitializerType( sequence_length: NSUInteger, feature_channel_count: NSUInteger, batch_size: NSUInteger, random_initializer_type: MLCRandomInitializerType, ) -> Retained<Self>
MLCTypes
only.Create a MLCTensor object
Create a tensor typically used by a recurrent layer The tensor data type is MLCDataTypeFloat32.
Parameter sequenceLength
: The length of sequences stored in the tensor
Parameter featureChannelCount
: Number of feature channels
Parameter batchSize
: The tensor batch size
Parameter randomInitializerType
: The random initializer type
Returns: A new MLCTensor object
Sourcepub unsafe fn tensorWithSequenceLength_featureChannelCount_batchSize_data(
sequence_length: NSUInteger,
feature_channel_count: NSUInteger,
batch_size: NSUInteger,
data: Option<&MLCTensorData>,
) -> Retained<Self>
👎DeprecatedAvailable on crate feature MLCTensorData
only.
pub unsafe fn tensorWithSequenceLength_featureChannelCount_batchSize_data( sequence_length: NSUInteger, feature_channel_count: NSUInteger, batch_size: NSUInteger, data: Option<&MLCTensorData>, ) -> Retained<Self>
MLCTensorData
only.Create a MLCTensor object
Create a tensor typically used by a recurrent layer The tensor data type is MLCDataTypeFloat32.
Parameter sequenceLength
: The length of sequences stored in the tensor
Parameter featureChannelCount
: Number of feature channels
Parameter batchSize
: The tensor batch size
Parameter data
: The tensor data
Returns: A new MLCTensor object
Sourcepub unsafe fn tensorWithSequenceLengths_sortedSequences_featureChannelCount_batchSize_randomInitializerType(
sequence_lengths: &NSArray<NSNumber>,
sorted_sequences: bool,
feature_channel_count: NSUInteger,
batch_size: NSUInteger,
random_initializer_type: MLCRandomInitializerType,
) -> Option<Retained<Self>>
👎DeprecatedAvailable on crate feature MLCTypes
only.
pub unsafe fn tensorWithSequenceLengths_sortedSequences_featureChannelCount_batchSize_randomInitializerType( sequence_lengths: &NSArray<NSNumber>, sorted_sequences: bool, feature_channel_count: NSUInteger, batch_size: NSUInteger, random_initializer_type: MLCRandomInitializerType, ) -> Option<Retained<Self>>
MLCTypes
only.Create a MLCTensor object
Create a tensor of variable length sequences typically used by a recurrent layer The tensor data type is MLCDataTypeFloat32.
Parameter sequenceLengths
: An array of sequence lengths
Parameter sortedSequences
: A flag to indicate if the sequence lengths are sorted. If yes, they must be sorted in descending order
Parameter featureChannelCount
: Number of feature channels
Parameter batchSize
: The tensor batch size
Parameter randomInitializerType
: The random initializer type
Returns: A new MLCTensor object
Sourcepub unsafe fn tensorWithSequenceLengths_sortedSequences_featureChannelCount_batchSize_data(
sequence_lengths: &NSArray<NSNumber>,
sorted_sequences: bool,
feature_channel_count: NSUInteger,
batch_size: NSUInteger,
data: Option<&MLCTensorData>,
) -> Option<Retained<Self>>
👎DeprecatedAvailable on crate feature MLCTensorData
only.
pub unsafe fn tensorWithSequenceLengths_sortedSequences_featureChannelCount_batchSize_data( sequence_lengths: &NSArray<NSNumber>, sorted_sequences: bool, feature_channel_count: NSUInteger, batch_size: NSUInteger, data: Option<&MLCTensorData>, ) -> Option<Retained<Self>>
MLCTensorData
only.Create a MLCTensor object
Create a tensor of variable length sequences typically used by a recurrent layer The tensor data type is MLCDataTypeFloat32.
Parameter sequenceLengths
: An array of sequence lengths
Parameter sortedSequences
: A flag to indicate if the sequence lengths are sorted. If yes, they must be sorted in descending order
Parameter featureChannelCount
: Number of feature channels
Parameter batchSize
: The tensor batch size
Parameter data
: The tensor data
Returns: A new MLCTensor object
Sourcepub unsafe fn hasValidNumerics(&self) -> bool
👎Deprecated
pub unsafe fn hasValidNumerics(&self) -> bool
Returns a Boolean value indicating whether the underlying data has valid floating-point numerics, i.e. it does not contain NaN or INF floating-point values.
Sourcepub unsafe fn synchronizeData(&self) -> bool
👎Deprecated
pub unsafe fn synchronizeData(&self) -> bool
Synchronize the data in host memory.
Synchronize the data in host memory i.e. tensor.data with latest contents in device memory This should only be called once the graph that this tensor is used with has finished execution; Otherwise the results in device memory may not be up to date. NOTE: This method should not be called from a completion callback when device is the GPU.
Returns: Returns YES if success, NO if there is a failure to synchronize
Sourcepub unsafe fn synchronizeOptimizerData(&self) -> bool
👎Deprecated
pub unsafe fn synchronizeOptimizerData(&self) -> bool
Synchronize the optimizer data in host memory.
Synchronize the optimizer data in host memory with latest contents in device memory This should only be called once the graph that this tensor is used with has finished execution; Otherwise the results in device memory may not be up to date. NOTE: This method should not be called from a completion callback when device is the GPU.
Returns: Returns YES if success, NO if there is a failure to synchronize
Sourcepub unsafe fn copyDataFromDeviceMemoryToBytes_length_synchronizeWithDevice(
&self,
bytes: NonNull<c_void>,
length: NSUInteger,
synchronize_with_device: bool,
) -> bool
👎Deprecated
pub unsafe fn copyDataFromDeviceMemoryToBytes_length_synchronizeWithDevice( &self, bytes: NonNull<c_void>, length: NSUInteger, synchronize_with_device: bool, ) -> bool
Copy tensor data from device memory to user specified memory
Before copying tensor data from device memory, one may need to synchronize the device memory for example when device is the GPU. The synchronizeWithDevice argumet can be set appropraitely to indicate this. For CPU this is ignored. If the tensor has been specified in outputs of a graph using addOutputs, synchronizeWithDevice should be set to NO. NOTE: This method should only be called once the graph that this tensor is used with has finished execution; Otherwise the results in device memory may not be up to date. synchronizeWithDevice must be set to NO when this method is called from a completion callback for GPU.
Parameter bytes
: The user specified data in which to copy
Parameter length
: The size in bytes to copy
Parameter synchronizeWithDevice
: Whether to synchronize device memory if device is GPU
Returns: Returns YES if success, NO if there is a failure to synchronize
Sourcepub unsafe fn bindAndWriteData_toDevice(
&self,
data: &MLCTensorData,
device: &MLCDevice,
) -> bool
👎DeprecatedAvailable on crate features MLCDevice
and MLCTensorData
only.
pub unsafe fn bindAndWriteData_toDevice( &self, data: &MLCTensorData, device: &MLCDevice, ) -> bool
MLCDevice
and MLCTensorData
only.Associates the given data to the tensor. If the device is GPU, also copies the data to the device memory. Returns true if the data is successfully associated with the tensor and copied to the device.
The caller must guarantee the lifetime of the underlying memory of
data
for the entirety of the tensor’s
lifetime. For input tensors, we recommend that the bindAndwriteData method provided by MLCTrainingGraph
and MLCInferenceGraph be used. This method should only be used to allocate and copy data to device memory
for tensors that are typically layer parameters such as weights, bias for convolution layers, beta, gamma for
normalization layers.
Parameter data
: The data to associated with the tensor
Parameter device
: The compute device
Returns: A Boolean value indicating whether the data is successfully associated with the tensor and copied to the device.
Sourcepub unsafe fn bindOptimizerData_deviceData(
&self,
data: &NSArray<MLCTensorData>,
device_data: Option<&NSArray<MLCTensorOptimizerDeviceData>>,
) -> bool
👎DeprecatedAvailable on crate features MLCTensorData
and MLCTensorOptimizerDeviceData
only.
pub unsafe fn bindOptimizerData_deviceData( &self, data: &NSArray<MLCTensorData>, device_data: Option<&NSArray<MLCTensorOptimizerDeviceData>>, ) -> bool
MLCTensorData
and MLCTensorOptimizerDeviceData
only.Associates the given optimizer data and device data buffers to the tensor. Returns true if the data is successfully associated with the tensor and copied to the device.
The caller must guarantee the lifetime of the underlying memory of
data
for the entirety of the tensor’s
lifetime. The
deviceData
buffers are allocated by MLCompute. This method must be called
before executeOptimizerUpdateWithOptions or executeWithInputsData is called for the training graph.
Parameter data
: The optimizer data to be associated with the tensor
Parameter deviceData
: The optimizer device data to be associated with the tensor
Returns: A Boolean value indicating whether the data is successfully associated with the tensor .
Sourcepub unsafe fn tensorByQuantizingToType_scale_bias(
&self,
type: MLCDataType,
scale: c_float,
bias: NSInteger,
) -> Option<Retained<MLCTensor>>
Available on crate feature MLCTypes
only.
pub unsafe fn tensorByQuantizingToType_scale_bias( &self, type: MLCDataType, scale: c_float, bias: NSInteger, ) -> Option<Retained<MLCTensor>>
MLCTypes
only.Converts a 32-bit floating-point tensor with given scale and a zero point Returns a quantized tensor
Parameter type
: The quantized data type. Must be MLCDataTypeInt8, MLCDataTypeUInt8 or MLCDataTypeInt32
Parameter scale
: The scale to apply in quantization
Parameter bias
: The offset value that maps to float zero
Returns: A quantized tensor
Sourcepub unsafe fn tensorByQuantizingToType_scale_bias_axis(
&self,
type: MLCDataType,
scale: &MLCTensor,
bias: &MLCTensor,
axis: NSInteger,
) -> Option<Retained<MLCTensor>>
Available on crate feature MLCTypes
only.
pub unsafe fn tensorByQuantizingToType_scale_bias_axis( &self, type: MLCDataType, scale: &MLCTensor, bias: &MLCTensor, axis: NSInteger, ) -> Option<Retained<MLCTensor>>
MLCTypes
only.Converts a 32-bit floating-point tensor with given scale and a zero point Returns a quantized tensor
Parameter type
: The quantized data type. Must be MLCDataTypeInt8, MLCDataTypeUInt8 or MLCDataTypeInt32
Parameter scale
: The scale to apply in quantization
Parameter bias
: The offset value that maps to float zero
Parameter axis
: The dimension on which to apply per-channel quantization
Returns: A quantized tensor
Sourcepub unsafe fn tensorByDequantizingToType_scale_bias_axis(
&self,
type: MLCDataType,
scale: &MLCTensor,
bias: &MLCTensor,
axis: NSInteger,
) -> Option<Retained<MLCTensor>>
Available on crate feature MLCTypes
only.
pub unsafe fn tensorByDequantizingToType_scale_bias_axis( &self, type: MLCDataType, scale: &MLCTensor, bias: &MLCTensor, axis: NSInteger, ) -> Option<Retained<MLCTensor>>
MLCTypes
only.Converts a quantized tensor to a 32-bit floating-point tensor Returns a de-quantized tensor
Parameter type
: The de-quantized data type. Must be MLCFloat32
Parameter scale
: The scale thst was used for the quantized data
Parameter bias
: The offset value that maps to float zero used for the quantized data
Parameter axis
: The dimension on which to apply per-channel quantization
Returns: A quantized tensor
Methods from Deref<Target = NSObject>§
Sourcepub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
pub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
Handle messages the object doesn’t recognize.
See Apple’s documentation for details.
Methods from Deref<Target = AnyObject>§
Sourcepub fn class(&self) -> &'static AnyClass
pub fn class(&self) -> &'static AnyClass
Dynamically find the class of this object.
§Panics
May panic if the object is invalid (which may be the case for objects
returned from unavailable init
/new
methods).
§Example
Check that an instance of NSObject
has the precise class NSObject
.
use objc2::ClassType;
use objc2::runtime::NSObject;
let obj = NSObject::new();
assert_eq!(obj.class(), NSObject::class());
Sourcepub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
👎Deprecated: this is difficult to use correctly, use Ivar::load
instead.
pub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
Ivar::load
instead.Use Ivar::load
instead.
§Safety
The object must have an instance variable with the given name, and it
must be of type T
.
See Ivar::load_ptr
for details surrounding this.
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
Attempt to downcast the object to a class of type T
.
This is the reference-variant. Use Retained::downcast
if you want
to convert a retained object to another type.
§Mutable classes
Some classes have immutable and mutable variants, such as NSString
and NSMutableString
.
When some Objective-C API signature says it gives you an immutable class, it generally expects you to not mutate that, even though it may technically be mutable “under the hood”.
So using this method to convert a NSString
to a NSMutableString
,
while not unsound, is generally frowned upon unless you created the
string yourself, or the API explicitly documents the string to be
mutable.
See Apple’s documentation on mutability and on
isKindOfClass:
for more details.
§Generic classes
Objective-C generics are called “lightweight generics”, and that’s because they aren’t exposed in the runtime. This makes it impossible to safely downcast to generic collections, so this is disallowed by this method.
You can, however, safely downcast to generic collections where all the
type-parameters are AnyObject
.
§Panics
This works internally by calling isKindOfClass:
. That means that the
object must have the instance method of that name, and an exception
will be thrown (if CoreFoundation is linked) or the process will abort
if that is not the case. In the vast majority of cases, you don’t need
to worry about this, since both root objects NSObject
and
NSProxy
implement this method.
§Examples
Cast an NSString
back and forth from NSObject
.
use objc2::rc::Retained;
use objc2_foundation::{NSObject, NSString};
let obj: Retained<NSObject> = NSString::new().into_super();
let string = obj.downcast_ref::<NSString>().unwrap();
// Or with `downcast`, if we do not need the object afterwards
let string = obj.downcast::<NSString>().unwrap();
Try (and fail) to cast an NSObject
to an NSString
.
use objc2_foundation::{NSObject, NSString};
let obj = NSObject::new();
assert!(obj.downcast_ref::<NSString>().is_none());
Try to cast to an array of strings.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
// This is invalid and doesn't type check.
let arr = arr.downcast_ref::<NSArray<NSString>>();
This fails to compile, since it would require enumerating over the array to ensure that each element is of the desired type, which is a performance pitfall.
Downcast when processing each element instead.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
for elem in arr {
if let Some(data) = elem.downcast_ref::<NSString>() {
// handle `data`
}
}
Trait Implementations§
Source§impl ClassType for MLCTensor
impl ClassType for MLCTensor
Source§const NAME: &'static str = "MLCTensor"
const NAME: &'static str = "MLCTensor"
Source§type ThreadKind = <<MLCTensor as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<MLCTensor as ClassType>::Super as ClassType>::ThreadKind
Source§impl CopyingHelper for MLCTensor
impl CopyingHelper for MLCTensor
Source§impl NSCopying for MLCTensor
impl NSCopying for MLCTensor
Source§impl NSObjectProtocol for MLCTensor
impl NSObjectProtocol for MLCTensor
Source§fn isEqual(&self, other: Option<&AnyObject>) -> bool
fn isEqual(&self, other: Option<&AnyObject>) -> bool
Source§fn hash(&self) -> usize
fn hash(&self) -> usize
Source§fn isKindOfClass(&self, cls: &AnyClass) -> bool
fn isKindOfClass(&self, cls: &AnyClass) -> bool
Source§fn is_kind_of<T>(&self) -> bool
fn is_kind_of<T>(&self) -> bool
isKindOfClass
directly, or cast your objects with AnyObject::downcast_ref