@@ -7,7 +7,7 @@ use libc::c_void;
77use libc:: size_t;
88use std:: ffi:: { CStr , CString } ;
99use std:: marker:: PhantomData ;
10- use std:: mem:: { self , ManuallyDrop } ;
10+ use std:: mem:: ManuallyDrop ;
1111use std:: os:: raw:: c_void as std_c_void;
1212use std:: ptr;
1313
@@ -365,7 +365,7 @@ impl<'a> Op<'a> {
365365 /// For sync execution, if any of the inputs to `op` are not ready, this call
366366 /// will block till they become ready and then return when the kernel execution
367367 /// is done.
368- fn execute < const N : usize > ( self , ctx : & ' a Context ) -> Result < [ TensorHandle ; N ] > {
368+ fn execute < const N : usize > ( self , ctx : & ' a Context ) -> Result < [ TensorHandle < ' a > ; N ] > {
369369 let status = Status :: new ( ) ;
370370
371371 let mut num_retvals = N as i32 ;
@@ -399,23 +399,8 @@ impl<'a> Op<'a> {
399399 return Err ( status) ;
400400 }
401401
402- let mut handles_uninit: [ mem:: MaybeUninit < TensorHandle > ; N ] =
403- unsafe { mem:: MaybeUninit :: uninit ( ) . assume_init ( ) } ;
404-
405- for i in 0 ..N {
406- let t = unsafe { TensorHandle :: from_tensor_handle ( ctx, retvals[ i] ) } ;
407- handles_uninit[ i] . write ( t) ;
408- }
409-
410- // Transmute uninitialized handles to initialized handles. Ideally, we would use
411- // `mem::transmute` here, but it is not stable yet for generic sized arrays.
412- // ref : https://github.com/rust-lang/rust/issues/61956
413- //
414- // Following is a workaround for this issue:
415- // Using &mut as an assertion of unique "ownership"
416- let ptr = & mut handles_uninit as * mut _ as * mut [ TensorHandle ; N ] ;
417- let handles: [ TensorHandle ; N ] = unsafe { ptr. read ( ) } ;
418- mem:: forget ( handles_uninit) ;
402+ let handles: [ TensorHandle ; N ] =
403+ std:: array:: from_fn ( |i| unsafe { TensorHandle :: from_tensor_handle ( ctx, retvals[ i] ) } ) ;
419404
420405 Ok ( handles)
421406 }
0 commit comments