pub struct NDArrayIdentity { /* private fields */ }Expand description
Wraps MPSNDArrayIdentity.
Implementations§
Source§impl NDArrayIdentity
impl NDArrayIdentity
Sourcepub fn new(device: &MetalDevice) -> Option<Self>
pub fn new(device: &MetalDevice) -> Option<Self>
Wraps a constructor on MPSNDArrayIdentity.
Examples found in repository?
examples/03_ndarray_identity.rs (line 25)
4fn main() {
5 let device = MetalDevice::system_default().expect("no Metal device available");
6 let queue = device.new_command_queue().expect("command queue");
7
8 let descriptor =
9 NDArrayDescriptor::with_dimension_sizes(data_type::FLOAT32, &[4]).expect("descriptor");
10 assert_eq!(descriptor.number_of_dimensions(), 1);
11 assert_eq!(descriptor.length_of_dimension(0), 4);
12
13 descriptor.reshape_with_dimension_sizes(&[2, 2]);
14 assert_eq!(descriptor.number_of_dimensions(), 2);
15 assert_eq!(descriptor.length_of_dimension(0), 2);
16 assert_eq!(descriptor.length_of_dimension(1), 2);
17
18 let array_descriptor = NDArrayDescriptor::with_dimension_sizes(data_type::FLOAT32, &[2, 2])
19 .expect("array descriptor");
20 let array = NDArray::new(&device, &array_descriptor).expect("ndarray");
21 assert_eq!(array.number_of_dimensions(), 2);
22 assert_eq!(array.length_of_dimension(0), 2);
23 assert!(array.resource_size() > 0);
24
25 if let Some(identity) = NDArrayIdentity::new(&device) {
26 let destination_descriptor =
27 NDArrayDescriptor::with_dimension_sizes(data_type::FLOAT32, &[4])
28 .expect("destination descriptor");
29 let destination =
30 NDArray::new(&device, &destination_descriptor).expect("destination ndarray");
31 let command_buffer = queue.new_command_buffer().expect("command buffer");
32 assert!(identity.reshape_into(Some(&command_buffer), &array, &[4], &destination));
33 command_buffer.commit();
34 command_buffer.wait_until_completed();
35 assert_eq!(destination.number_of_dimensions(), 1);
36 assert_eq!(destination.length_of_dimension(0), 4);
37 println!(
38 "ndarray smoke passed: resource_size={} dims={}x{}",
39 array.resource_size(),
40 array.length_of_dimension(0),
41 array.length_of_dimension(1)
42 );
43 } else {
44 println!("ndarray smoke skipped: MPSNDArrayIdentity unavailable on this macOS version");
45 }
46}Sourcepub fn reshape(
&self,
source: &NDArray,
dimension_sizes: &[usize],
) -> Option<NDArray>
pub fn reshape( &self, source: &NDArray, dimension_sizes: &[usize], ) -> Option<NDArray>
Wraps the corresponding MPSNDArrayIdentity method.
Sourcepub fn reshape_with_command_buffer(
&self,
command_buffer: &MetalCommandBuffer,
source: &NDArray,
dimension_sizes: &[usize],
) -> Option<NDArray>
pub fn reshape_with_command_buffer( &self, command_buffer: &MetalCommandBuffer, source: &NDArray, dimension_sizes: &[usize], ) -> Option<NDArray>
Wraps the corresponding MPSNDArrayIdentity method.
Sourcepub fn reshape_into(
&self,
command_buffer: Option<&MetalCommandBuffer>,
source: &NDArray,
dimension_sizes: &[usize],
destination: &NDArray,
) -> bool
pub fn reshape_into( &self, command_buffer: Option<&MetalCommandBuffer>, source: &NDArray, dimension_sizes: &[usize], destination: &NDArray, ) -> bool
Wraps the corresponding MPSNDArrayIdentity method.
Examples found in repository?
examples/03_ndarray_identity.rs (line 32)
4fn main() {
5 let device = MetalDevice::system_default().expect("no Metal device available");
6 let queue = device.new_command_queue().expect("command queue");
7
8 let descriptor =
9 NDArrayDescriptor::with_dimension_sizes(data_type::FLOAT32, &[4]).expect("descriptor");
10 assert_eq!(descriptor.number_of_dimensions(), 1);
11 assert_eq!(descriptor.length_of_dimension(0), 4);
12
13 descriptor.reshape_with_dimension_sizes(&[2, 2]);
14 assert_eq!(descriptor.number_of_dimensions(), 2);
15 assert_eq!(descriptor.length_of_dimension(0), 2);
16 assert_eq!(descriptor.length_of_dimension(1), 2);
17
18 let array_descriptor = NDArrayDescriptor::with_dimension_sizes(data_type::FLOAT32, &[2, 2])
19 .expect("array descriptor");
20 let array = NDArray::new(&device, &array_descriptor).expect("ndarray");
21 assert_eq!(array.number_of_dimensions(), 2);
22 assert_eq!(array.length_of_dimension(0), 2);
23 assert!(array.resource_size() > 0);
24
25 if let Some(identity) = NDArrayIdentity::new(&device) {
26 let destination_descriptor =
27 NDArrayDescriptor::with_dimension_sizes(data_type::FLOAT32, &[4])
28 .expect("destination descriptor");
29 let destination =
30 NDArray::new(&device, &destination_descriptor).expect("destination ndarray");
31 let command_buffer = queue.new_command_buffer().expect("command buffer");
32 assert!(identity.reshape_into(Some(&command_buffer), &array, &[4], &destination));
33 command_buffer.commit();
34 command_buffer.wait_until_completed();
35 assert_eq!(destination.number_of_dimensions(), 1);
36 assert_eq!(destination.length_of_dimension(0), 4);
37 println!(
38 "ndarray smoke passed: resource_size={} dims={}x{}",
39 array.resource_size(),
40 array.length_of_dimension(0),
41 array.length_of_dimension(1)
42 );
43 } else {
44 println!("ndarray smoke skipped: MPSNDArrayIdentity unavailable on this macOS version");
45 }
46}Trait Implementations§
Source§impl Drop for NDArrayIdentity
impl Drop for NDArrayIdentity
impl Send for NDArrayIdentity
impl Sync for NDArrayIdentity
Auto Trait Implementations§
impl Freeze for NDArrayIdentity
impl RefUnwindSafe for NDArrayIdentity
impl Unpin for NDArrayIdentity
impl UnsafeUnpin for NDArrayIdentity
impl UnwindSafe for NDArrayIdentity
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more