<s> import numpy as np <EOL> from numba import cuda <EOL> from numba . cuda . testing import unittest <EOL> class TestArrayAttr ( unittest . TestCase ) : <EOL> def test_contigous_2d ( self ) : <EOL> ary = np . arange ( <NUM_LIT:10> ) <EOL> cary = ary . reshape ( <NUM_LIT:2> , <NUM_LIT:5> ) <EOL> fary = np . asfortranarray ( cary ) <EOL> dcary = cuda . to_device ( cary ) <EOL> dfary = cuda . to_device ( fary ) <EOL> self . assertTrue ( dcary . is_c_contiguous ( ) ) <EOL> self . assertTrue ( not dfary . is_c_contiguous ( ) ) <EOL> self . assertTrue ( not dcary . is_f_contiguous ( ) ) <EOL> self . assertTrue ( dfary . is_f_contiguous ( ) ) <EOL> def test_contigous_3d ( self ) : <EOL> ary = np . arange ( <NUM_LIT:20> ) <EOL> cary = ary . reshape ( <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT:2> ) <EOL> fary = np . asfortranarray ( cary ) <EOL> dcary = cuda . to_device ( cary ) <EOL> dfary = cuda . to_device ( fary ) <EOL> self . assertTrue ( dcary . is_c_contiguous ( ) ) <EOL> self . assertTrue ( not dfary . is_c_contiguous ( ) ) <EOL> self . assertTrue ( not dcary . is_f_contiguous ( ) ) <EOL> self . assertTrue ( dfary . is_f_contiguous ( ) ) <EOL> def test_contigous_4d ( self ) : <EOL> ary = np . arange ( <NUM_LIT> ) <EOL> cary = ary . reshape ( <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> fary = np . asfortranarray ( cary ) <EOL> dcary = cuda . to_device ( cary ) <EOL> dfary = cuda . to_device ( fary ) <EOL> self . assertTrue ( dcary . is_c_contiguous ( ) ) <EOL> self . assertTrue ( not dfary . is_c_contiguous ( ) ) <EOL> self . assertTrue ( not dcary . is_f_contiguous ( ) ) <EOL> self . assertTrue ( dfary . is_f_contiguous ( ) ) <EOL> def test_ravel_c ( self ) : <EOL> ary = np . arange ( <NUM_LIT> ) <EOL> reshaped = ary . reshape ( <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> expect = reshaped . ravel ( order = '<STR_LIT:C>' ) <EOL> dary = cuda . to_device ( reshaped ) <EOL> dflat = dary . ravel ( ) <EOL> flat = dflat . copy_to_host ( ) <EOL> self . assertTrue ( flat . ndim == <NUM_LIT:1> ) <EOL> self . assertTrue ( np . all ( expect == flat ) ) <EOL> def test_ravel_f ( self ) : <EOL> ary = np . arange ( <NUM_LIT> ) <EOL> reshaped = np . asfortranarray ( ary . reshape ( <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> expect = reshaped . ravel ( order = '<STR_LIT:F>' ) <EOL> dary = cuda . to_device ( reshaped ) <EOL> dflat = dary . ravel ( order = '<STR_LIT:F>' ) <EOL> flat = dflat . copy_to_host ( ) <EOL> self . assertTrue ( flat . ndim == <NUM_LIT:1> ) <EOL> self . assertTrue ( np . all ( expect == flat ) ) <EOL> def test_reshape_c ( self ) : <EOL> ary = np . arange ( <NUM_LIT:10> ) <EOL> expect = ary . reshape ( <NUM_LIT:2> , <NUM_LIT:5> ) <EOL> dary = cuda . to_device ( ary ) <EOL> dary_reshaped = dary . reshape ( <NUM_LIT:2> , <NUM_LIT:5> ) <EOL> got = dary_reshaped . copy_to_host ( ) <EOL> self . assertTrue ( np . all ( expect == got ) ) <EOL> def test_reshape_f ( self ) : <EOL> ary = np . arange ( <NUM_LIT:10> ) <EOL> expect = ary . reshape ( <NUM_LIT:2> , <NUM_LIT:5> , order = '<STR_LIT:F>' ) <EOL> dary = cuda . to_device ( ary ) <EOL> dary_reshaped = dary . reshape ( <NUM_LIT:2> , <NUM_LIT:5> , order = '<STR_LIT:F>' ) <EOL> got = dary_reshaped . copy_to_host ( ) <EOL> self . assertTrue ( np . all ( expect == got ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
