pub struct MPSNDArrayDescriptor { /* private fields */ }MPSNDArray only.Expand description
Dependencies: This depends on Metal.framework
A MPSNDArrayDescriptor object describes a attributes of MPSNDArray and is used to create one (see MPSNDArray discussion below)
See also Apple’s documentation
Implementations§
Source§impl MPSNDArrayDescriptor
impl MPSNDArrayDescriptor
Sourcepub unsafe fn dataType(&self) -> MPSDataType
Available on crate features MPSCore and MPSCoreTypes only.
pub unsafe fn dataType(&self) -> MPSDataType
MPSCore and MPSCoreTypes only.Data Type of the MPSNDArray elements
Sourcepub unsafe fn setDataType(&self, data_type: MPSDataType)
Available on crate features MPSCore and MPSCoreTypes only.
pub unsafe fn setDataType(&self, data_type: MPSDataType)
MPSCore and MPSCoreTypes only.Setter for dataType.
Sourcepub unsafe fn numberOfDimensions(&self) -> NSUInteger
Available on crate feature MPSCore only.
pub unsafe fn numberOfDimensions(&self) -> NSUInteger
MPSCore only.The number of dimensions in the NDArray.
May not exceed 16. A 0-diumension MPSNDArray is a single scalar value. Undefined dimensions are implicitly length 1.
Sourcepub unsafe fn setNumberOfDimensions(&self, number_of_dimensions: NSUInteger)
Available on crate feature MPSCore only.
pub unsafe fn setNumberOfDimensions(&self, number_of_dimensions: NSUInteger)
MPSCore only.Setter for numberOfDimensions.
Sourcepub unsafe fn preferPackedRows(&self) -> bool
Available on crate feature MPSCore only.
pub unsafe fn preferPackedRows(&self) -> bool
MPSCore only.If YES, then new NDArrays created with this descriptor will pack the rows. Default: NO.
Sourcepub unsafe fn setPreferPackedRows(&self, prefer_packed_rows: bool)
Available on crate feature MPSCore only.
pub unsafe fn setPreferPackedRows(&self, prefer_packed_rows: bool)
MPSCore only.Setter for preferPackedRows.
Sourcepub unsafe fn lengthOfDimension(
&self,
dimension_index: NSUInteger,
) -> NSUInteger
Available on crate feature MPSCore only.
pub unsafe fn lengthOfDimension( &self, dimension_index: NSUInteger, ) -> NSUInteger
MPSCore only.The number of elements of type dataType in the indicated dimension.
If dimensionIndex >= numberOfDimensions, 1 will be returned.
Parameter dimensionIndex: dimension the MPSNDArray for which to return the length
Returns: The number of elements in that dimension.
Sourcepub unsafe fn sliceRangeForDimension(
&self,
dimension_index: NSUInteger,
) -> MPSDimensionSlice
Available on crate features MPSCore and MPSCoreTypes only.
pub unsafe fn sliceRangeForDimension( &self, dimension_index: NSUInteger, ) -> MPSDimensionSlice
MPSCore and MPSCoreTypes only.The slice dimensions for each dimension
A slice is a subregion of a dimension. It is used to calve off a fraction of a larger NDArray.
Parameter dimensionIndex: The index of the dimension
Returns: Returns the slice range for the index. If the dimensionIndex >= numberOfDimensions, {0,1} is returned.
Sourcepub unsafe fn sliceDimension_withSubrange(
&self,
dimension_index: NSUInteger,
sub_range: MPSDimensionSlice,
)
Available on crate features MPSCore and MPSCoreTypes only.
pub unsafe fn sliceDimension_withSubrange( &self, dimension_index: NSUInteger, sub_range: MPSDimensionSlice, )
MPSCore and MPSCoreTypes only.The slice dimensions for each dimension
A slice is a subregion of a dimension. It is used to calve off a fraction of a larger NDArray.
Default: NSRange(0, lengthOfDimension(i))
Parameter subRange: The region of the slice, start value is wrt dimensionLength of the NDArray.
Parameter dimensionIndex: The index of the dimension. Must be
<
numberOfDimensions
Sourcepub unsafe fn transposeDimension_withDimension(
&self,
dimension_index: NSUInteger,
dimension_index2: NSUInteger,
)
Available on crate feature MPSCore only.
pub unsafe fn transposeDimension_withDimension( &self, dimension_index: NSUInteger, dimension_index2: NSUInteger, )
MPSCore only.transpose two dimensions
If the intention is to insert a length 1 dimension, increment the numberOfDimensions first.
Parameter dimensionIndex: The first dimension. Must be
<
numberOfDimensions
Parameter dimensionIndex2: The second dimension. Must be
<
number of Dimensions.
Sourcepub unsafe fn permuteWithDimensionOrder(
&self,
dimension_order: NonNull<NSUInteger>,
)
Available on crate feature MPSCore only.
pub unsafe fn permuteWithDimensionOrder( &self, dimension_order: NonNull<NSUInteger>, )
MPSCore only.Permutes the dimensions of the current descriptor
Parameter dimensionOrder: A permutation of the dimensions of the NDArray.
dimensionOrder[i] must contain the new postion of dimenson i.
Size of the array must be equal to the original number of dimensions in the descriptor.
Must have all the indices in [0, numberOfDimensions) present uniquely.
This permutation is applied on top of whatever transpostions/permutations that may have been performed on the descriptor before.
§Safety
dimension_order must be a valid pointer.
Sourcepub unsafe fn getShape(&self) -> Retained<NSArray<NSNumber>>
Available on crate feature MPSCore only.
pub unsafe fn getShape(&self) -> Retained<NSArray<NSNumber>>
MPSCore only.Returns the shape of the NDArray as MPSShape
The length of the array is the number of dimensions and the size of the fastest running dimension is the last element in the array.
Sourcepub unsafe fn descriptorWithDataType_dimensionCount_dimensionSizes(
data_type: MPSDataType,
number_of_dimensions: NSUInteger,
dimension_sizes: NonNull<NSUInteger>,
) -> Retained<Self>
Available on crate features MPSCore and MPSCoreTypes only.
pub unsafe fn descriptorWithDataType_dimensionCount_dimensionSizes( data_type: MPSDataType, number_of_dimensions: NSUInteger, dimension_sizes: NonNull<NSUInteger>, ) -> Retained<Self>
MPSCore and MPSCoreTypes only.Create an MPSNDArrayDescriptor object for a given size of dimensions.
Sample code:
// Creates an NDArrayDescriptor of dimensions [32, 6, 5, 3]
NSUInteger sizes[] = {3,5,6,32};
[ MPSNDArray descriptorWithDataType: MPSDataTypeFloat32
dimensionCount: 4
dimensionSizes: sizes ]; // array of numberOfDimensions dimensions. Starts with dimension 0Parameter dataType: MPSDataType of elements in the MPSNDArray
Parameter numberOfDimensions: Number of dimensions in the NDArray. May not exceed 16.
Parameter dimensionSizes: An array of NSUIntegers where dimension lengths provided by the user goes from fastest
moving to slowest moving dimension.
The product of all dimension lengths must be less than 2**31.
Additional system memory limits may apply
Returns: A valid MPSNDArrayDescriptor object or nil, if failure.
§Safety
dimension_sizes must be a valid pointer.
Sourcepub unsafe fn descriptorWithDataType_shape(
data_type: MPSDataType,
shape: &NSArray<NSNumber>,
) -> Retained<Self>
Available on crate features MPSCore and MPSCoreTypes only.
pub unsafe fn descriptorWithDataType_shape( data_type: MPSDataType, shape: &NSArray<NSNumber>, ) -> Retained<Self>
MPSCore and MPSCoreTypes only.A convenience function to create an MPSNDArrayDescriptor object for a given size of dimensions.
Sample code:
// Creates an NDArrayDescriptor of dimensions [32, 6, 5, 3]
NSArray<NSNumber *> sizes = {@32,@6,@5,@3};
[ MPSNDArray descriptorWithDataType: MPSDataTypeFloat32
shape: &sizes];Parameter dataType: MPSDataType of elements in the MPSNDArray
Parameter shape: An array of NSUIntegers where dimension lengths provided by the user goes from slowest
moving to fastest moving dimension. This is same order as MLMultiArray in coreML and most frameworks in Python
The product of all dimension lengths must be less than 2**31.
Additional system memory limits may apply
Returns: A valid MPSNDArrayDescriptor object or nil, if failure.
Sourcepub unsafe fn reshapeWithDimensionCount_dimensionSizes(
&self,
number_of_dimensions: NSUInteger,
dimension_sizes: NonNull<NSUInteger>,
)
Available on crate feature MPSCore only.
pub unsafe fn reshapeWithDimensionCount_dimensionSizes( &self, number_of_dimensions: NSUInteger, dimension_sizes: NonNull<NSUInteger>, )
MPSCore only.Changes dimension sizes and number of dimensions on the current descriptor
Parameter numberOfDimensions: Number of dimensions in the NDArray. May not exceed 16.
Parameter dimensionSizes: An array of NSUIntegers where dimension lengths provided by the user goes from fastest
moving to slowest moving dimension.
The product of all dimension lengths must be less than 2**31.
Additional system memory limits may apply
§Safety
dimension_sizes must be a valid pointer.
Sourcepub unsafe fn reshapeWithShape(&self, shape: &NSArray<NSNumber>)
Available on crate feature MPSCore only.
pub unsafe fn reshapeWithShape(&self, shape: &NSArray<NSNumber>)
MPSCore only.Changes dimension sizes and number of dimensions on the current descriptor
Parameter shape: An array of NSUIntegers where dimension lengths provided by the user goes from slowest
moving to fastest moving dimension. This is same order as MLMultiArray in coreML and most frameworks in Python
The product of all dimension lengths must be less than 2**31.
Additional system memory limits may apply
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 MPSNDArrayDescriptor
Available on crate feature MPSCore only.
impl AsRef<AnyObject> for MPSNDArrayDescriptor
MPSCore only.Source§impl AsRef<MPSNDArrayDescriptor> for MPSNDArrayDescriptor
Available on crate feature MPSCore only.
impl AsRef<MPSNDArrayDescriptor> for MPSNDArrayDescriptor
MPSCore only.Source§impl AsRef<NSObject> for MPSNDArrayDescriptor
Available on crate feature MPSCore only.
impl AsRef<NSObject> for MPSNDArrayDescriptor
MPSCore only.Source§impl Borrow<AnyObject> for MPSNDArrayDescriptor
Available on crate feature MPSCore only.
impl Borrow<AnyObject> for MPSNDArrayDescriptor
MPSCore only.Source§impl Borrow<NSObject> for MPSNDArrayDescriptor
Available on crate feature MPSCore only.
impl Borrow<NSObject> for MPSNDArrayDescriptor
MPSCore only.Source§impl ClassType for MPSNDArrayDescriptor
Available on crate feature MPSCore only.
impl ClassType for MPSNDArrayDescriptor
MPSCore only.Source§const NAME: &'static str = "MPSNDArrayDescriptor"
const NAME: &'static str = "MPSNDArrayDescriptor"
Source§type ThreadKind = <<MPSNDArrayDescriptor as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<MPSNDArrayDescriptor as ClassType>::Super as ClassType>::ThreadKind
Source§impl Debug for MPSNDArrayDescriptor
Available on crate feature MPSCore only.
impl Debug for MPSNDArrayDescriptor
MPSCore only.Source§impl Deref for MPSNDArrayDescriptor
Available on crate feature MPSCore only.
impl Deref for MPSNDArrayDescriptor
MPSCore only.Source§impl Hash for MPSNDArrayDescriptor
Available on crate feature MPSCore only.
impl Hash for MPSNDArrayDescriptor
MPSCore only.Source§impl Message for MPSNDArrayDescriptor
Available on crate feature MPSCore only.
impl Message for MPSNDArrayDescriptor
MPSCore only.Source§impl NSObjectProtocol for MPSNDArrayDescriptor
Available on crate feature MPSCore only.
impl NSObjectProtocol for MPSNDArrayDescriptor
MPSCore only.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_refSource§fn isMemberOfClass(&self, cls: &AnyClass) -> bool
fn isMemberOfClass(&self, cls: &AnyClass) -> bool
Source§fn respondsToSelector(&self, aSelector: Sel) -> bool
fn respondsToSelector(&self, aSelector: Sel) -> bool
Source§fn conformsToProtocol(&self, aProtocol: &AnyProtocol) -> bool
fn conformsToProtocol(&self, aProtocol: &AnyProtocol) -> bool
Source§fn debugDescription(&self) -> Retained<NSObject>
fn debugDescription(&self) -> Retained<NSObject>
Source§impl PartialEq for MPSNDArrayDescriptor
Available on crate feature MPSCore only.
impl PartialEq for MPSNDArrayDescriptor
MPSCore only.Source§impl RefEncode for MPSNDArrayDescriptor
Available on crate feature MPSCore only.
impl RefEncode for MPSNDArrayDescriptor
MPSCore only.Source§const ENCODING_REF: Encoding = <NSObject as ::objc2::RefEncode>::ENCODING_REF
const ENCODING_REF: Encoding = <NSObject as ::objc2::RefEncode>::ENCODING_REF
impl DowncastTarget for MPSNDArrayDescriptor
MPSCore only.impl Eq for MPSNDArrayDescriptor
MPSCore only.