1+ from  __future__ import  annotations 
2+ 
3+ import  os 
14import  tempfile 
25import  unittest 
36
811import  dpnp  as  cupy 
912from  dpnp .tests .helper  import  has_support_aspect64 , is_cuda_device 
1013from  dpnp .tests .third_party .cupy  import  testing 
14+ from  dpnp .tests .third_party .cupy .testing ._protocol_helpers  import  (
15+     DummyObjectWithCudaArrayInterface ,
16+     DummyObjectWithCuPyGetNDArray ,
17+ )
1118
1219
1320class  TestFromData (unittest .TestCase ):
@@ -37,6 +44,11 @@ def test_array_from_numpy(self, xp, dtype, order):
3744        a  =  testing .shaped_arange ((2 , 3 , 4 ), numpy , dtype )
3845        return  xp .array (a , order = order )
3946
47+     @pytest .mark .skip ("no blocking keyword" ) 
48+     def  test_array_from_numpy_blocking (self ):
49+         a  =  testing .shaped_arange ((2 , 3 , 4 ), numpy , numpy .float32 )
50+         testing .assert_array_equal (cupy .array (a , blocking = True ), a )
51+ 
4052    @testing .for_orders ("CFAK" ) 
4153    @testing .for_all_dtypes () 
4254    @testing .numpy_cupy_array_equal () 
@@ -242,7 +254,7 @@ def test_array_copy_with_dtype_being_none(self, xp, order):
242254    @testing .for_orders ("CFAK" , name = "dst_order" ) 
243255    @testing .for_all_dtypes (name = "dtype1" , no_complex = True ) 
244256    @testing .for_all_dtypes (name = "dtype2" ) 
245-     @testing .numpy_cupy_array_equal () 
257+     @testing .numpy_cupy_array_equal (strides_check = True ) 
246258    def  test_array_copy_list_of_numpy_with_dtype (
247259        self , xp , dtype1 , dtype2 , src_order , dst_order 
248260    ):
@@ -258,7 +270,7 @@ def test_array_copy_list_of_numpy_with_dtype(
258270    @testing .for_orders ("CFAK" , name = "dst_order" ) 
259271    @testing .for_all_dtypes (name = "dtype1" , no_complex = True ) 
260272    @testing .for_all_dtypes (name = "dtype2" ) 
261-     @testing .numpy_cupy_array_equal () 
273+     @testing .numpy_cupy_array_equal (strides_check = True ) 
262274    def  test_array_copy_list_of_numpy_with_dtype_char (
263275        self , xp , dtype1 , dtype2 , src_order , dst_order 
264276    ):
@@ -274,7 +286,7 @@ def test_array_copy_list_of_numpy_with_dtype_char(
274286    @testing .for_orders ("CFAK" , name = "dst_order" ) 
275287    @testing .for_all_dtypes (name = "dtype1" , no_complex = True ) 
276288    @testing .for_all_dtypes (name = "dtype2" ) 
277-     @testing .numpy_cupy_array_equal () 
289+     @testing .numpy_cupy_array_equal (strides_check = True ) 
278290    def  test_array_copy_list_of_cupy_with_dtype (
279291        self , xp , dtype1 , dtype2 , src_order , dst_order 
280292    ):
@@ -290,7 +302,7 @@ def test_array_copy_list_of_cupy_with_dtype(
290302    @testing .for_orders ("CFAK" , name = "dst_order" ) 
291303    @testing .for_all_dtypes (name = "dtype1" , no_complex = True ) 
292304    @testing .for_all_dtypes (name = "dtype2" ) 
293-     @testing .numpy_cupy_array_equal () 
305+     @testing .numpy_cupy_array_equal (strides_check = True ) 
294306    def  test_array_copy_list_of_cupy_with_dtype_char (
295307        self , xp , dtype1 , dtype2 , src_order , dst_order 
296308    ):
@@ -401,6 +413,11 @@ def test_asarray(self, xp, dtype):
401413        a  =  testing .shaped_arange ((2 , 3 , 4 ), xp , dtype )
402414        return  xp .asarray (a )
403415
416+     @pytest .mark .skip ("no blocking keyword" ) 
417+     def  test_asarray_blocking (self ):
418+         a  =  testing .shaped_arange ((2 , 3 , 4 ), numpy , numpy .float32 )
419+         testing .assert_array_equal (cupy .asarray (a , blocking = True ), a )
420+ 
404421    @testing .for_all_dtypes () 
405422    @testing .numpy_cupy_array_equal () 
406423    def  test_asarray_is_not_copied (self , xp , dtype ):
@@ -454,6 +471,11 @@ def test_asanyarray_from_big_endian(self, xp, dtype):
454471        # happens to work before the change in #5828 
455472        return  b  +  b 
456473
474+     @pytest .mark .skip ("no blocking keyword" ) 
475+     def  test_asanyarray_blocking (self ):
476+         a  =  testing .shaped_arange ((2 , 3 , 4 ), numpy , numpy .float32 )
477+         testing .assert_array_equal (cupy .asanyarray (a , blocking = True ), a )
478+ 
457479    @testing .for_CF_orders () 
458480    @testing .for_all_dtypes () 
459481    @testing .numpy_cupy_array_equal () 
@@ -727,67 +749,6 @@ def test_with_over_size_array(self):
727749        testing .assert_array_equal (a , b )
728750
729751
730- class  DummyObjectWithCudaArrayInterface :
731-     def  __init__ (self , a , ver , include_strides = False , mask = None , stream = None ):
732-         assert  ver  in  tuple (range (max_cuda_array_interface_version  +  1 ))
733-         self .a  =  None 
734-         if  isinstance (a , cupy .ndarray ):
735-             self .a  =  a 
736-         else :
737-             self .shape , self .strides , self .typestr , self .descr , self .data  =  a 
738-         self .ver  =  ver 
739-         self .include_strides  =  include_strides 
740-         self .mask  =  mask 
741-         self .stream  =  stream 
742- 
743-     @property  
744-     def  __cuda_array_interface__ (self ):
745-         if  self .a  is  not None :
746-             desc  =  {
747-                 "shape" : self .a .shape ,
748-                 "typestr" : self .a .dtype .str ,
749-                 "descr" : self .a .dtype .descr ,
750-                 "data" : (self .a .data .ptr , False ),
751-                 "version" : self .ver ,
752-             }
753-             if  self .a .flags .c_contiguous :
754-                 if  self .include_strides  is  True :
755-                     desc ["strides" ] =  self .a .strides 
756-                 elif  self .include_strides  is  None :
757-                     desc ["strides" ] =  None 
758-                 else :  # self.include_strides is False 
759-                     pass 
760-             else :  # F contiguous or neither 
761-                 desc ["strides" ] =  self .a .strides 
762-         else :
763-             desc  =  {
764-                 "shape" : self .shape ,
765-                 "typestr" : self .typestr ,
766-                 "descr" : self .descr ,
767-                 "data" : (self .data , False ),
768-                 "version" : self .ver ,
769-             }
770-             if  self .include_strides  is  True :
771-                 desc ["strides" ] =  self .strides 
772-             elif  self .include_strides  is  None :
773-                 desc ["strides" ] =  None 
774-             else :  # self.include_strides is False 
775-                 pass 
776-         if  self .mask  is  not None :
777-             desc ["mask" ] =  self .mask 
778-         # The stream field is kept here for compliance. However, since the 
779-         # synchronization is done via calling a cpdef function, which cannot 
780-         # be mock-tested. 
781-         if  self .stream  is  not None :
782-             if  self .stream  is  cuda .Stream .null :
783-                 desc ["stream" ] =  cuda .runtime .streamLegacy 
784-             elif  (not  cuda .runtime .is_hip ) and  self .stream  is  cuda .Stream .ptds :
785-                 desc ["stream" ] =  cuda .runtime .streamPerThread 
786-             else :
787-                 desc ["stream" ] =  self .stream .ptr 
788-         return  desc 
789- 
790- 
791752@testing .parameterize ( 
792753    * testing .product ( 
793754        { 
@@ -848,3 +809,12 @@ def test_invalid_type(self):
848809        a  =  numpy .array ([1 , 2 , 3 ], dtype = object )
849810        with  self .assertRaises (TypeError ):
850811            cupy .array (a )
812+ 
813+ 
814+ @pytest .mark .skip ("CUDA array interface is not supported" ) 
815+ class  TestArrayCuPyGetNDArray (unittest .TestCase ):
816+     def  test_cupy_get_ndarray (self ):
817+         a  =  cupy .array ([1 , 2 , 3 ])
818+         dummy  =  DummyObjectWithCuPyGetNDArray (a )
819+         res  =  cupy .asarray (dummy )
820+         assert  a  is  res   # OK if it was a view 
0 commit comments