#[repr(C)]pub struct MLCTensorDescriptor { /* private fields */ }
MLCTensorDescriptor
only.Expand description
The MLCTensorDescriptor specifies a tensor descriptor.
See also Appleโs documentation
Implementationsยง
Sourceยงimpl MLCTensorDescriptor
impl MLCTensorDescriptor
Sourcepub unsafe fn dataType(&self) -> MLCDataType
๐DeprecatedAvailable on crate feature MLCTypes
only.
pub unsafe fn dataType(&self) -> MLCDataType
MLCTypes
only.The tensor data type. The default is MLCDataTypeFloat32.
Sourcepub unsafe fn dimensionCount(&self) -> NSUInteger
๐Deprecated
pub unsafe fn dimensionCount(&self) -> NSUInteger
The number of dimensions in the tensor
Sourcepub unsafe fn shape(&self) -> Retained<NSArray<NSNumber>>
๐Deprecated
pub unsafe fn shape(&self) -> Retained<NSArray<NSNumber>>
The size in each dimension
Sourcepub unsafe fn stride(&self) -> Retained<NSArray<NSNumber>>
๐Deprecated
pub unsafe fn stride(&self) -> Retained<NSArray<NSNumber>>
The stride in bytes in each dimension
Sourcepub unsafe fn tensorAllocationSizeInBytes(&self) -> NSUInteger
๐Deprecated
pub unsafe fn tensorAllocationSizeInBytes(&self) -> NSUInteger
The allocation size in bytes for a tensor.
Sourcepub unsafe fn sortedSequences(&self) -> bool
๐Deprecated
pub unsafe fn sortedSequences(&self) -> bool
Specifies whether the sequences are sorted or not.
Sourcepub unsafe fn batchSizePerSequenceStep(
&self,
) -> Option<Retained<NSArray<NSNumber>>>
๐Deprecated
pub unsafe fn batchSizePerSequenceStep( &self, ) -> Option<Retained<NSArray<NSNumber>>>
The batch size for each sequence
We populate this only when sequenceLengths is valid. The length of this array should be the maximum sequence length in sequenceLengths (i.e sequenceLengths[0]).
pub unsafe fn new() -> Retained<Self>
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>
Sourcepub unsafe fn maxTensorDimensions() -> NSUInteger
๐Deprecated
pub unsafe fn maxTensorDimensions() -> NSUInteger
The maximum number of tensor dimensions supported
Sourcepub unsafe fn descriptorWithShape_dataType(
shape: &NSArray<NSNumber>,
data_type: MLCDataType,
) -> Option<Retained<Self>>
๐DeprecatedAvailable on crate feature MLCTypes
only.
pub unsafe fn descriptorWithShape_dataType( shape: &NSArray<NSNumber>, data_type: MLCDataType, ) -> Option<Retained<Self>>
MLCTypes
only.Create a MLCTensorDescriptor object
Parameter shape
: The tensor shape
Parameter dataType
: The tensor data type
Returns: A new MLCTensorDescriptor object or nil if failure.
Sourcepub unsafe fn descriptorWithShape_sequenceLengths_sortedSequences_dataType(
shape: &NSArray<NSNumber>,
sequence_lengths: &NSArray<NSNumber>,
sorted_sequences: bool,
data_type: MLCDataType,
) -> Option<Retained<Self>>
๐DeprecatedAvailable on crate feature MLCTypes
only.
pub unsafe fn descriptorWithShape_sequenceLengths_sortedSequences_dataType( shape: &NSArray<NSNumber>, sequence_lengths: &NSArray<NSNumber>, sorted_sequences: bool, data_type: MLCDataType, ) -> Option<Retained<Self>>
MLCTypes
only.Create a MLCTensorDescriptor object
Parameter shape
: The tensor shape
Parameter sequenceLengths
: The sequence lengths in tensor
Parameter sortedSequences
: A boolean to indicate whether sequences are sorted
Parameter dataType
: The tensor data type
Returns: A new MLCTensorDescriptor object or nil if failure.
This method is provided as an easy to use API to create sequence tensors used by recurrent layers.
Sourcepub unsafe fn descriptorWithWidth_height_featureChannelCount_batchSize(
width: NSUInteger,
height: NSUInteger,
feature_channels: NSUInteger,
batch_size: NSUInteger,
) -> Option<Retained<Self>>
๐Deprecated
pub unsafe fn descriptorWithWidth_height_featureChannelCount_batchSize( width: NSUInteger, height: NSUInteger, feature_channels: NSUInteger, batch_size: NSUInteger, ) -> Option<Retained<Self>>
Create a MLCTensorDescriptor object
Parameter width
: The tensor width
Parameter height
: The tensor height
Parameter featureChannels
: The number of feature channels
Parameter batchSize
: The batch size
Returns: A new MLCTensorDescriptor object or nil if failure.
This method is provided as an easy to use API to create [NCHW] tensors used by convolutional layers.
Sourcepub unsafe fn descriptorWithWidth_height_featureChannelCount_batchSize_dataType(
width: NSUInteger,
height: NSUInteger,
feature_channel_count: NSUInteger,
batch_size: NSUInteger,
data_type: MLCDataType,
) -> Option<Retained<Self>>
๐DeprecatedAvailable on crate feature MLCTypes
only.
pub unsafe fn descriptorWithWidth_height_featureChannelCount_batchSize_dataType( width: NSUInteger, height: NSUInteger, feature_channel_count: NSUInteger, batch_size: NSUInteger, data_type: MLCDataType, ) -> Option<Retained<Self>>
MLCTypes
only.Create a MLCTensorDescriptor object
Parameter width
: The tensor width
Parameter height
: The tensor height
Parameter featureChannelCount
: The number of feature channels
Parameter batchSize
: The batch size
Parameter dataType
: The tensor data type
Returns: A new MLCTensorDescriptor object or nil if failure.
This method is provided as an easy to use API to create [NCHW] tensors used by convolutional layers.
Sourcepub unsafe fn convolutionWeightsDescriptorWithWidth_height_inputFeatureChannelCount_outputFeatureChannelCount_dataType(
width: NSUInteger,
height: NSUInteger,
input_feature_channel_count: NSUInteger,
output_feature_channel_count: NSUInteger,
data_type: MLCDataType,
) -> Option<Retained<Self>>
๐DeprecatedAvailable on crate feature MLCTypes
only.
pub unsafe fn convolutionWeightsDescriptorWithWidth_height_inputFeatureChannelCount_outputFeatureChannelCount_dataType( width: NSUInteger, height: NSUInteger, input_feature_channel_count: NSUInteger, output_feature_channel_count: NSUInteger, data_type: MLCDataType, ) -> Option<Retained<Self>>
MLCTypes
only.Create a MLCTensorDescriptor object
Parameter width
: The tensor width
Parameter height
: The tensor height
Parameter inputFeatureChannelCount
: The number of input feature channels
Parameter outputFeatureChannelCount
: The number of output feature channels
Parameter dataType
: The tensor data type
Returns: A new MLCTensorDescriptor object or nil if failure.
This method is provided as an easy to use API to create a weight tensor.
Sourcepub unsafe fn convolutionWeightsDescriptorWithInputFeatureChannelCount_outputFeatureChannelCount_dataType(
input_feature_channel_count: NSUInteger,
output_feature_channel_count: NSUInteger,
data_type: MLCDataType,
) -> Option<Retained<Self>>
๐DeprecatedAvailable on crate feature MLCTypes
only.
pub unsafe fn convolutionWeightsDescriptorWithInputFeatureChannelCount_outputFeatureChannelCount_dataType( input_feature_channel_count: NSUInteger, output_feature_channel_count: NSUInteger, data_type: MLCDataType, ) -> Option<Retained<Self>>
MLCTypes
only.Create a MLCTensorDescriptor object
Parameter inputFeatureChannelCount
: The number of input feature channels
Parameter outputFeatureChannelCount
: The number of output feature channels
Parameter dataType
: The tensor data type
Returns: A new MLCTensorDescriptor object or nil if failure.
This method is provided as an easy to use API to create a weight tensor for a kernel of size 1.
Sourcepub unsafe fn convolutionBiasesDescriptorWithFeatureChannelCount_dataType(
feature_channel_count: NSUInteger,
data_type: MLCDataType,
) -> Option<Retained<Self>>
๐DeprecatedAvailable on crate feature MLCTypes
only.
pub unsafe fn convolutionBiasesDescriptorWithFeatureChannelCount_dataType( feature_channel_count: NSUInteger, data_type: MLCDataType, ) -> Option<Retained<Self>>
MLCTypes
only.Create a MLCTensorDescriptor object
Parameter featureChannelCount
: The number of input feature channels
Parameter dataType
: The tensor data type
Returns: A new MLCTensorDescriptor object or nil if failure.
This method is provided as an easy to use API to create a bias 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 AsRef<AnyObject> for MLCTensorDescriptor
impl AsRef<AnyObject> for MLCTensorDescriptor
Sourceยงimpl AsRef<NSObject> for MLCTensorDescriptor
impl AsRef<NSObject> for MLCTensorDescriptor
Sourceยงimpl Borrow<AnyObject> for MLCTensorDescriptor
impl Borrow<AnyObject> for MLCTensorDescriptor
Sourceยงimpl Borrow<NSObject> for MLCTensorDescriptor
impl Borrow<NSObject> for MLCTensorDescriptor
Sourceยงimpl ClassType for MLCTensorDescriptor
impl ClassType for MLCTensorDescriptor
Sourceยงconst NAME: &'static str = "MLCTensorDescriptor"
const NAME: &'static str = "MLCTensorDescriptor"
Sourceยงtype ThreadKind = <<MLCTensorDescriptor as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<MLCTensorDescriptor as ClassType>::Super as ClassType>::ThreadKind
Sourceยงimpl CopyingHelper for MLCTensorDescriptor
impl CopyingHelper for MLCTensorDescriptor
Sourceยงtype Result = MLCTensorDescriptor
type Result = MLCTensorDescriptor
Self
if the type has no
immutable counterpart. Read moreSourceยงimpl Debug for MLCTensorDescriptor
impl Debug for MLCTensorDescriptor
Sourceยงimpl Deref for MLCTensorDescriptor
impl Deref for MLCTensorDescriptor
Sourceยงimpl Hash for MLCTensorDescriptor
impl Hash for MLCTensorDescriptor
Sourceยงimpl Message for MLCTensorDescriptor
impl Message for MLCTensorDescriptor
Sourceยงimpl NSCopying for MLCTensorDescriptor
impl NSCopying for MLCTensorDescriptor
Sourceยงimpl NSObjectProtocol for MLCTensorDescriptor
impl NSObjectProtocol for MLCTensorDescriptor
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