<s> import pytest <EOL> import numpy <EOL> import random <EOL> from pyop2 import plan <EOL> from pyop2 import op2 <EOL> from coffee . base import * <EOL> def _seed ( ) : <EOL> return <NUM_LIT> <EOL> nelems = <NUM_LIT:8> <EOL> @ pytest . fixture <EOL> def iterset ( ) : <EOL> return op2 . Set ( nelems , "<STR_LIT>" ) <EOL> @ pytest . fixture <EOL> def indset ( ) : <EOL> return op2 . Set ( nelems , "<STR_LIT>" ) <EOL> @ pytest . fixture <EOL> def diterset ( iterset ) : <EOL> return op2 . DataSet ( iterset , <NUM_LIT:1> , "<STR_LIT>" ) <EOL> @ pytest . fixture <EOL> def dindset ( indset ) : <EOL> return op2 . DataSet ( indset , <NUM_LIT:1> , "<STR_LIT>" ) <EOL> @ pytest . fixture <EOL> def dindset2 ( indset ) : <EOL> return op2 . DataSet ( indset , <NUM_LIT:2> , "<STR_LIT>" ) <EOL> @ pytest . fixture <EOL> def g ( ) : <EOL> return op2 . Global ( <NUM_LIT:1> , <NUM_LIT:0> , numpy . uint32 , "<STR_LIT:g>" ) <EOL> @ pytest . fixture <EOL> def x ( dindset ) : <EOL> return op2 . Dat ( dindset , range ( nelems ) , numpy . uint32 , "<STR_LIT:x>" ) <EOL> @ pytest . fixture <EOL> def x2 ( dindset2 ) : <EOL> return op2 . Dat ( dindset2 , range ( nelems ) * <NUM_LIT:2> , numpy . uint32 , "<STR_LIT>" ) <EOL> @ pytest . fixture <EOL> def xl ( dindset ) : <EOL> return op2 . Dat ( dindset , range ( nelems ) , numpy . uint64 , "<STR_LIT>" ) <EOL> @ pytest . fixture <EOL> def y ( dindset ) : <EOL> return op2 . Dat ( dindset , [ <NUM_LIT:0> ] * nelems , numpy . uint32 , "<STR_LIT:y>" ) <EOL> @ pytest . fixture <EOL> def iter2ind1 ( iterset , indset ) : <EOL> u_map = numpy . array ( range ( nelems ) , dtype = numpy . uint32 ) <EOL> random . shuffle ( u_map , _seed ) <EOL> return op2 . Map ( iterset , indset , <NUM_LIT:1> , u_map , "<STR_LIT>" ) <EOL> @ pytest . fixture <EOL> def iter2ind2 ( iterset , indset ) : <EOL> u_map = numpy . array ( range ( nelems ) * <NUM_LIT:2> , dtype = numpy . uint32 ) <EOL> random . shuffle ( u_map , _seed ) <EOL> return op2 . Map ( iterset , indset , <NUM_LIT:2> , u_map , "<STR_LIT>" ) <EOL> class TestObjectCaching : <EOL> @ pytest . fixture ( scope = '<STR_LIT:class>' ) <EOL> def base_set ( self ) : <EOL> return op2 . Set ( <NUM_LIT:1> ) <EOL> @ pytest . fixture ( scope = '<STR_LIT:class>' ) <EOL> def base_set2 ( self ) : <EOL> return op2 . Set ( <NUM_LIT:1> ) <EOL> @ pytest . fixture ( scope = '<STR_LIT:class>' ) <EOL> def base_map ( self , base_set ) : <EOL> return op2 . Map ( base_set , base_set , <NUM_LIT:1> , [ <NUM_LIT:0> ] ) <EOL> @ pytest . fixture ( scope = '<STR_LIT:class>' ) <EOL> def base_map2 ( self , base_set , base_set2 ) : <EOL> return op2 . Map ( base_set , base_set2 , <NUM_LIT:1> , [ <NUM_LIT:0> ] ) <EOL> @ pytest . fixture ( scope = '<STR_LIT:class>' ) <EOL> def base_map3 ( self , base_set ) : <EOL> return op2 . Map ( base_set , base_set , <NUM_LIT:1> , [ <NUM_LIT:0> ] ) <EOL> def test_set_identity ( self , backend , base_set , base_set2 ) : <EOL> assert base_set is base_set <EOL> assert base_set is not base_set2 <EOL> assert base_set != base_set2 <EOL> assert not base_set == base_set2 <EOL> def test_map_identity ( self , backend , base_map , base_map2 ) : <EOL> assert base_map is base_map <EOL> assert base_map is not base_map2 <EOL> assert base_map != base_map2 <EOL> assert not base_map == base_map2 <EOL> def test_dataset_cache_hit ( self , backend , base_set ) : <EOL> d1 = base_set ** <NUM_LIT:2> <EOL> d2 = base_set ** <NUM_LIT:2> <EOL> assert d1 is d2 <EOL> assert d1 == d2 <EOL> assert not d1 != d2 <EOL> def test_dataset_cache_miss ( self , backend , base_set , base_set2 ) : <EOL> d1 = base_set ** <NUM_LIT:1> <EOL> d2 = base_set ** <NUM_LIT:2> <EOL> assert d1 is not d2 <EOL> assert d1 != d2 <EOL> assert not d1 == d2 <EOL> d3 = base_set2 ** <NUM_LIT:1> <EOL> assert d1 is not d3 <EOL> assert d1 != d3 <EOL> assert not d1 == d3 <EOL> def test_mixedset_cache_hit ( self , backend , base_set ) : <EOL> ms = op2 . MixedSet ( [ base_set , base_set ] ) <EOL> ms2 = op2 . MixedSet ( [ base_set , base_set ] ) <EOL> assert ms is ms2 <EOL> assert not ms != ms2 <EOL> assert ms == ms2 <EOL> def test_mixedset_cache_miss ( self , backend , base_set , base_set2 ) : <EOL> ms = op2 . MixedSet ( [ base_set , base_set2 ] ) <EOL> ms2 = op2 . MixedSet ( [ base_set2 , base_set ] ) <EOL> assert ms is not ms2 <EOL> assert ms != ms2 <EOL> assert not ms == ms2 <EOL> ms3 = op2 . MixedSet ( [ base_set , base_set2 ] ) <EOL> assert ms is ms3 <EOL> assert not ms != ms3 <EOL> assert ms == ms3 <EOL> def test_decoratedmap_cache_hit ( self , backend , base_map ) : <EOL> sm = op2 . DecoratedMap ( base_map , [ op2 . ALL ] ) <EOL> sm2 = op2 . DecoratedMap ( base_map , [ op2 . ALL ] ) <EOL> assert sm is sm2 <EOL> assert not sm != sm2 <EOL> assert sm == sm2 <EOL> def test_decoratedmap_cache_miss ( self , backend , base_map , base_map2 ) : <EOL> sm = op2 . DecoratedMap ( base_map , [ op2 . ALL ] ) <EOL> sm2 = op2 . DecoratedMap ( base_map2 , [ op2 . ALL ] ) <EOL> assert sm is not sm2 <EOL> assert sm != sm2 <EOL> assert not sm == sm2 <EOL> sm3 = op2 . DecoratedMap ( base_map , [ op2 . ON_BOTTOM ] ) <EOL> assert sm is not sm3 <EOL> assert sm != sm3 <EOL> assert not sm == sm3 <EOL> assert sm2 is not sm3 <EOL> assert sm2 != sm3 <EOL> assert not sm2 == sm3 <EOL> def test_decoratedmap_change_bcs ( self , backend , base_map ) : <EOL> sm = op2 . DecoratedMap ( base_map , [ op2 . ALL ] ) <EOL> smbc = op2 . DecoratedMap ( base_map , [ op2 . ALL ] , implicit_bcs = [ "<STR_LIT>" ] ) <EOL> assert "<STR_LIT>" in smbc . implicit_bcs <EOL> assert "<STR_LIT>" not in sm . implicit_bcs <EOL> smbc = op2 . DecoratedMap ( sm , implicit_bcs = [ "<STR_LIT>" ] ) <EOL> assert "<STR_LIT>" in smbc . implicit_bcs <EOL> assert op2 . ALL in smbc . iteration_region <EOL> assert len ( sm . implicit_bcs ) == <NUM_LIT:0> <EOL> assert op2 . ALL in smbc . iteration_region <EOL> def test_decoratedmap_le ( self , backend , base_map ) : <EOL> sm = op2 . DecoratedMap ( base_map , [ op2 . ALL ] ) <EOL> assert base_map <= sm <EOL> assert sm <= base_map <EOL> smbc = op2 . DecoratedMap ( base_map , [ op2 . ALL ] , implicit_bcs = [ "<STR_LIT>" ] ) <EOL> assert base_map <= smbc <EOL> assert smbc <= base_map <EOL> sm2 = op2 . DecoratedMap ( base_map , [ op2 . ON_BOTTOM ] ) <EOL> assert not base_map <= sm2 <EOL> assert not sm2 <= base_map <EOL> def test_mixedmap_cache_hit ( self , backend , base_map , base_map2 ) : <EOL> mm = op2 . MixedMap ( [ base_map , base_map2 ] ) <EOL> mm2 = op2 . MixedMap ( [ base_map , base_map2 ] ) <EOL> assert mm is mm2 <EOL> assert not mm != mm2 <EOL> assert mm == mm2 <EOL> def test_mixedmap_cache_miss ( self , backend , base_map , base_map2 ) : <EOL> ms = op2 . MixedMap ( [ base_map , base_map2 ] ) <EOL> ms2 = op2 . MixedMap ( [ base_map2 , base_map ] ) <EOL> assert ms is not ms2 <EOL> assert ms != ms2 <EOL> assert not ms == ms2 <EOL> ms3 = op2 . MixedMap ( [ base_map , base_map2 ] ) <EOL> assert ms is ms3 <EOL> assert not ms != ms3 <EOL> assert ms == ms3 <EOL> def test_mixeddataset_cache_hit ( self , backend , base_set , base_set2 ) : <EOL> mds = op2 . MixedDataSet ( [ base_set , base_set2 ] ) <EOL> mds2 = op2 . MixedDataSet ( [ base_set , base_set2 ] ) <EOL> assert mds is mds2 <EOL> assert not mds != mds2 <EOL> assert mds == mds2 <EOL> def test_mixeddataset_cache_miss ( self , backend , base_set , base_set2 ) : <EOL> mds = op2 . MixedDataSet ( [ base_set , base_set2 ] ) <EOL> mds2 = op2 . MixedDataSet ( [ base_set2 , base_set ] ) <EOL> mds3 = op2 . MixedDataSet ( [ base_set , base_set ] ) <EOL> assert mds is not mds2 <EOL> assert mds != mds2 <EOL> assert not mds == mds2 <EOL> assert mds is not mds3 <EOL> assert mds != mds3 <EOL> assert not mds == mds3 <EOL> assert mds2 is not mds3 <EOL> assert mds2 != mds3 <EOL> assert not mds2 == mds3 <EOL> def test_sparsity_cache_hit ( self , backend , base_set , base_map ) : <EOL> dsets = ( base_set , base_set ) <EOL> maps = ( base_map , base_map ) <EOL> sp = op2 . Sparsity ( dsets , maps ) <EOL> sp2 = op2 . Sparsity ( dsets , maps ) <EOL> assert sp is sp2 <EOL> assert not sp != sp2 <EOL> assert sp == sp2 <EOL> dsets = op2 . MixedSet ( [ base_set , base_set ] ) <EOL> maps = op2 . MixedMap ( [ base_map , base_map ] ) <EOL> sp = op2 . Sparsity ( dsets , maps ) <EOL> dsets2 = op2 . MixedSet ( [ base_set , base_set ] ) <EOL> maps2 = op2 . MixedMap ( [ base_map , base_map ] ) <EOL> sp2 = op2 . Sparsity ( dsets2 , maps2 ) <EOL> assert sp is sp2 <EOL> assert not sp != sp2 <EOL> assert sp == sp2 <EOL> def test_sparsity_cache_miss ( self , backend , base_set , base_set2 , <EOL> base_map , base_map2 ) : <EOL> dsets = ( base_set , base_set ) <EOL> maps = ( base_map , base_map ) <EOL> sp = op2 . Sparsity ( dsets , maps ) <EOL> dsets2 = op2 . MixedSet ( [ base_set , base_set ] ) <EOL> maps2 = op2 . MixedMap ( [ base_map , base_map ] ) <EOL> maps2 = op2 . DecoratedMap ( maps2 , [ op2 . ALL ] ) <EOL> sp2 = op2 . Sparsity ( dsets2 , maps2 ) <EOL> assert sp is not sp2 <EOL> assert sp != sp2 <EOL> assert not sp == sp2 <EOL> dsets2 = ( base_set , base_set2 ) <EOL> maps2 = ( base_map , base_map2 ) <EOL> sp2 = op2 . Sparsity ( dsets2 , maps2 ) <EOL> assert sp is not sp2 <EOL> assert sp != sp2 <EOL> assert not sp == sp2 <EOL> class TestPlanCache : <EOL> """<STR_LIT>""" <EOL> skip_backends = [ '<STR_LIT>' ] <EOL> cache = plan . Plan . _cache <EOL> cache_hit = plan . Plan . _cache_hit <EOL> @ pytest . fixture <EOL> def mat ( cls , iter2ind1 , dindset ) : <EOL> sparsity = op2 . Sparsity ( ( dindset , dindset ) , ( iter2ind1 , iter2ind1 ) , "<STR_LIT>" ) <EOL> return op2 . Mat ( sparsity , '<STR_LIT>' , "<STR_LIT>" ) <EOL> @ pytest . fixture <EOL> def a64 ( cls , iterset , diterset ) : <EOL> return op2 . Dat ( diterset , range ( nelems ) , numpy . uint64 , "<STR_LIT:a>" ) <EOL> def test_plan_per_iterset_partition ( self , backend ) : <EOL> set = op2 . Set ( [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:4> ] , "<STR_LIT>" ) <EOL> indset = op2 . Set ( <NUM_LIT:4> , "<STR_LIT>" ) <EOL> dat = op2 . Dat ( set ** <NUM_LIT:1> , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , dtype = numpy . int32 ) <EOL> inddat = op2 . Dat ( indset ** <NUM_LIT:1> , [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , dtype = numpy . int32 ) <EOL> map = op2 . Map ( set , indset , <NUM_LIT:1> , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> self . cache . clear ( ) <EOL> assert len ( self . cache ) == <NUM_LIT:0> <EOL> op2 . par_loop ( op2 . Kernel ( "<STR_LIT>" , <EOL> "<STR_LIT>" ) , <EOL> set , <EOL> dat ( op2 . READ ) , <EOL> inddat ( op2 . WRITE , map [ <NUM_LIT:0> ] ) ) <EOL> assert ( dat . data == inddat . data ) . all ( ) <EOL> assert len ( self . cache ) == <NUM_LIT:2> <EOL> def test_same_arg ( self , backend , iterset , iter2ind1 , x ) : <EOL> self . cache . clear ( ) <EOL> assert len ( self . cache ) == <NUM_LIT:0> <EOL> kernel_inc = "<STR_LIT>" <EOL> kernel_dec = "<STR_LIT>" <EOL> op2 . par_loop ( op2 . Kernel ( kernel_inc , "<STR_LIT>" ) , <EOL> iterset , <EOL> x ( op2 . RW , iter2ind1 [ <NUM_LIT:0> ] ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ x ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> op2 . par_loop ( op2 . Kernel ( kernel_dec , "<STR_LIT>" ) , <EOL> iterset , <EOL> x ( op2 . RW , iter2ind1 [ <NUM_LIT:0> ] ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ x ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> def test_arg_order ( self , backend , iterset , iter2ind1 , x , y ) : <EOL> self . cache . clear ( ) <EOL> assert len ( self . cache ) == <NUM_LIT:0> <EOL> kernel_swap = """<STR_LIT>""" <EOL> op2 . par_loop ( op2 . Kernel ( kernel_swap , "<STR_LIT>" ) , <EOL> iterset , <EOL> x ( op2 . RW , iter2ind1 [ <NUM_LIT:0> ] ) , <EOL> y ( op2 . RW , iter2ind1 [ <NUM_LIT:0> ] ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ x ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> op2 . par_loop ( op2 . Kernel ( kernel_swap , "<STR_LIT>" ) , <EOL> iterset , <EOL> y ( op2 . RW , iter2ind1 [ <NUM_LIT:0> ] ) , <EOL> x ( op2 . RW , iter2ind1 [ <NUM_LIT:0> ] ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ x ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> def test_idx_order ( self , backend , iterset , iter2ind2 , x ) : <EOL> self . cache . clear ( ) <EOL> assert len ( self . cache ) == <NUM_LIT:0> <EOL> kernel_swap = """<STR_LIT>""" <EOL> op2 . par_loop ( op2 . Kernel ( kernel_swap , "<STR_LIT>" ) , <EOL> iterset , <EOL> x ( op2 . RW , iter2ind2 [ <NUM_LIT:0> ] ) , <EOL> x ( op2 . RW , iter2ind2 [ <NUM_LIT:1> ] ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ x ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> op2 . par_loop ( op2 . Kernel ( kernel_swap , "<STR_LIT>" ) , <EOL> iterset , <EOL> x ( op2 . RW , iter2ind2 [ <NUM_LIT:1> ] ) , <EOL> x ( op2 . RW , iter2ind2 [ <NUM_LIT:0> ] ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ x ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> def test_dat_same_size_times_dim ( self , backend , iterset , iter2ind1 , iter2ind2 , x2 , xl ) : <EOL> self . cache . clear ( ) <EOL> assert len ( self . cache ) == <NUM_LIT:0> <EOL> kernel_swap = """<STR_LIT>""" <EOL> op2 . par_loop ( op2 . Kernel ( kernel_swap , "<STR_LIT>" ) , <EOL> iterset , <EOL> x2 ( op2 . RW , iter2ind2 [ <NUM_LIT:0> ] ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ x2 ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> kernel_inc = "<STR_LIT>" <EOL> op2 . par_loop ( op2 . Kernel ( kernel_inc , "<STR_LIT>" ) , <EOL> iterset , <EOL> xl ( op2 . RW , iter2ind1 [ <NUM_LIT:0> ] ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ xl ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:2> <EOL> def test_same_nonstaged_arg_count ( self , backend , iterset , iter2ind1 , x , a64 , g ) : <EOL> self . cache . clear ( ) <EOL> assert len ( self . cache ) == <NUM_LIT:0> <EOL> kernel_dummy = "<STR_LIT>" <EOL> op2 . par_loop ( op2 . Kernel ( kernel_dummy , "<STR_LIT>" ) , <EOL> iterset , <EOL> x ( op2 . INC , iter2ind1 [ <NUM_LIT:0> ] ) , <EOL> a64 ( op2 . RW ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ x ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> kernel_dummy = "<STR_LIT>" <EOL> op2 . par_loop ( op2 . Kernel ( kernel_dummy , "<STR_LIT>" ) , <EOL> iterset , <EOL> x ( op2 . INC , iter2ind1 [ <NUM_LIT:0> ] ) , <EOL> g ( op2 . READ ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ x ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> def test_same_conflicts ( self , backend , iterset , iter2ind2 , x , y ) : <EOL> self . cache . clear ( ) <EOL> assert len ( self . cache ) == <NUM_LIT:0> <EOL> kernel_dummy = "<STR_LIT>" <EOL> op2 . par_loop ( op2 . Kernel ( kernel_dummy , "<STR_LIT>" ) , <EOL> iterset , <EOL> x ( op2 . INC , iter2ind2 [ <NUM_LIT:0> ] ) , <EOL> x ( op2 . INC , iter2ind2 [ <NUM_LIT:1> ] ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ x ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> kernel_dummy = "<STR_LIT>" <EOL> op2 . par_loop ( op2 . Kernel ( kernel_dummy , "<STR_LIT>" ) , <EOL> iterset , <EOL> y ( op2 . INC , iter2ind2 [ <NUM_LIT:0> ] ) , <EOL> y ( op2 . INC , iter2ind2 [ <NUM_LIT:1> ] ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ y ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> def test_diff_conflicts ( self , backend , iterset , iter2ind2 , x , y ) : <EOL> self . cache . clear ( ) <EOL> assert len ( self . cache ) == <NUM_LIT:0> <EOL> kernel_dummy = "<STR_LIT>" <EOL> op2 . par_loop ( op2 . Kernel ( kernel_dummy , "<STR_LIT>" ) , <EOL> iterset , <EOL> x ( op2 . READ , iter2ind2 [ <NUM_LIT:0> ] ) , <EOL> x ( op2 . READ , iter2ind2 [ <NUM_LIT:1> ] , ) ) <EOL> op2 . base . _trace . evaluate ( set ( ) , set ( [ x ] ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> kernel_dummy = "<STR_LIT>" <EOL> op2 . par_loop ( op2 . Kernel ( kernel_dummy , "<STR_LIT>" ) , <EOL> iterset , <EOL> y ( op2 . INC , iter2ind2 [ <NUM_LIT:0> ] ) , <EOL> y ( op2 . INC , iter2ind2 [ <NUM_LIT:1> ] ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ y ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:2> <EOL> def test_same_with_mat ( self , backend , skip_opencl , iterset , x , iter2ind1 , mat ) : <EOL> self . cache . clear ( ) <EOL> assert len ( self . cache ) == <NUM_LIT:0> <EOL> self . cache_hit . clear ( ) <EOL> assert len ( self . cache_hit ) == <NUM_LIT:0> <EOL> plan1 = plan . Plan ( iterset . all_part , <EOL> mat ( op2 . INC , ( iter2ind1 [ op2 . i [ <NUM_LIT:0> ] ] , <EOL> iter2ind1 [ op2 . i [ <NUM_LIT:1> ] ] ) ) , <EOL> x ( op2 . READ , iter2ind1 [ <NUM_LIT:0> ] ) , <EOL> partition_size = <NUM_LIT:10> , <EOL> matrix_coloring = True ) <EOL> op2 . base . _trace . evaluate ( set ( [ mat ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> assert self . cache_hit [ plan1 ] == <NUM_LIT:1> <EOL> plan2 = plan . Plan ( iterset . all_part , <EOL> mat ( op2 . INC , ( iter2ind1 [ op2 . i [ <NUM_LIT:0> ] ] , <EOL> iter2ind1 [ op2 . i [ <NUM_LIT:1> ] ] ) ) , <EOL> x ( op2 . READ , iter2ind1 [ <NUM_LIT:0> ] ) , <EOL> partition_size = <NUM_LIT:10> , <EOL> matrix_coloring = True ) <EOL> op2 . base . _trace . evaluate ( set ( [ mat ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> assert plan1 is plan2 <EOL> assert self . cache_hit [ plan1 ] == <NUM_LIT:2> <EOL> def test_iteration_index_order_matters_with_mat ( self , backend , skip_opencl , <EOL> iterset , x , iter2ind1 , mat ) : <EOL> self . cache . clear ( ) <EOL> assert len ( self . cache ) == <NUM_LIT:0> <EOL> self . cache_hit . clear ( ) <EOL> assert len ( self . cache_hit ) == <NUM_LIT:0> <EOL> plan1 = plan . Plan ( iterset . all_part , <EOL> mat ( op2 . INC , ( iter2ind1 [ op2 . i [ <NUM_LIT:0> ] ] , <EOL> iter2ind1 [ op2 . i [ <NUM_LIT:1> ] ] ) ) , <EOL> x ( op2 . READ , iter2ind1 [ <NUM_LIT:0> ] ) , <EOL> partition_size = <NUM_LIT:10> , <EOL> matrix_coloring = True ) <EOL> op2 . base . _trace . evaluate ( set ( [ mat ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> assert self . cache_hit [ plan1 ] == <NUM_LIT:1> <EOL> plan2 = plan . Plan ( iterset . all_part , <EOL> mat ( op2 . INC , ( iter2ind1 [ op2 . i [ <NUM_LIT:1> ] ] , <EOL> iter2ind1 [ op2 . i [ <NUM_LIT:0> ] ] ) ) , <EOL> x ( op2 . READ , iter2ind1 [ <NUM_LIT:0> ] ) , <EOL> partition_size = <NUM_LIT:10> , <EOL> matrix_coloring = True ) <EOL> op2 . base . _trace . evaluate ( set ( [ mat ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:2> <EOL> assert plan1 is not plan2 <EOL> assert self . cache_hit [ plan1 ] == <NUM_LIT:1> <EOL> assert self . cache_hit [ plan2 ] == <NUM_LIT:1> <EOL> class TestGeneratedCodeCache : <EOL> """<STR_LIT>""" <EOL> cache = op2 . base . JITModule . _cache <EOL> @ pytest . fixture <EOL> def a ( cls , diterset ) : <EOL> return op2 . Dat ( diterset , range ( nelems ) , numpy . uint32 , "<STR_LIT:a>" ) <EOL> @ pytest . fixture <EOL> def b ( cls , diterset ) : <EOL> return op2 . Dat ( diterset , range ( nelems ) , numpy . uint32 , "<STR_LIT:b>" ) <EOL> def test_same_args ( self , backend , iterset , iter2ind1 , x , a ) : <EOL> self . cache . clear ( ) <EOL> assert len ( self . cache ) == <NUM_LIT:0> <EOL> kernel_cpy = "<STR_LIT>" <EOL> op2 . par_loop ( op2 . Kernel ( kernel_cpy , "<STR_LIT>" ) , <EOL> iterset , <EOL> a ( op2 . WRITE ) , <EOL> x ( op2 . READ , iter2ind1 [ <NUM_LIT:0> ] ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ a ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> op2 . par_loop ( op2 . Kernel ( kernel_cpy , "<STR_LIT>" ) , <EOL> iterset , <EOL> a ( op2 . WRITE ) , <EOL> x ( op2 . READ , iter2ind1 [ <NUM_LIT:0> ] ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ a ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> def test_diff_kernel ( self , backend , iterset , iter2ind1 , x , a ) : <EOL> self . cache . clear ( ) <EOL> assert len ( self . cache ) == <NUM_LIT:0> <EOL> kernel_cpy = "<STR_LIT>" <EOL> op2 . par_loop ( op2 . Kernel ( kernel_cpy , "<STR_LIT>" ) , <EOL> iterset , <EOL> a ( op2 . WRITE ) , <EOL> x ( op2 . READ , iter2ind1 [ <NUM_LIT:0> ] ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ a ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> kernel_cpy = "<STR_LIT>" <EOL> op2 . par_loop ( op2 . Kernel ( kernel_cpy , "<STR_LIT>" ) , <EOL> iterset , <EOL> a ( op2 . WRITE ) , <EOL> x ( op2 . READ , iter2ind1 [ <NUM_LIT:0> ] ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ a ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:2> <EOL> def test_invert_arg_similar_shape ( self , backend , iterset , iter2ind1 , x , y ) : <EOL> self . cache . clear ( ) <EOL> assert len ( self . cache ) == <NUM_LIT:0> <EOL> kernel_swap = """<STR_LIT>""" <EOL> op2 . par_loop ( op2 . Kernel ( kernel_swap , "<STR_LIT>" ) , <EOL> iterset , <EOL> x ( op2 . RW , iter2ind1 [ <NUM_LIT:0> ] ) , <EOL> y ( op2 . RW , iter2ind1 [ <NUM_LIT:0> ] ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ x ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> op2 . par_loop ( op2 . Kernel ( kernel_swap , "<STR_LIT>" ) , <EOL> iterset , <EOL> y ( op2 . RW , iter2ind1 [ <NUM_LIT:0> ] ) , <EOL> x ( op2 . RW , iter2ind1 [ <NUM_LIT:0> ] ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ y ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> def test_dloop_ignore_scalar ( self , backend , iterset , a , b ) : <EOL> self . cache . clear ( ) <EOL> assert len ( self . cache ) == <NUM_LIT:0> <EOL> kernel_swap = """<STR_LIT>""" <EOL> op2 . par_loop ( op2 . Kernel ( kernel_swap , "<STR_LIT>" ) , <EOL> iterset , <EOL> a ( op2 . RW ) , <EOL> b ( op2 . RW ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ a ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> op2 . par_loop ( op2 . Kernel ( kernel_swap , "<STR_LIT>" ) , <EOL> iterset , <EOL> b ( op2 . RW ) , <EOL> a ( op2 . RW ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ b ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> def test_vector_map ( self , backend , iterset , x2 , iter2ind2 ) : <EOL> self . cache . clear ( ) <EOL> assert len ( self . cache ) == <NUM_LIT:0> <EOL> kernel_swap = """<STR_LIT>""" <EOL> op2 . par_loop ( op2 . Kernel ( kernel_swap , "<STR_LIT>" ) , <EOL> iterset , <EOL> x2 ( op2 . RW , iter2ind2 ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ x2 ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> op2 . par_loop ( op2 . Kernel ( kernel_swap , "<STR_LIT>" ) , <EOL> iterset , <EOL> x2 ( op2 . RW , iter2ind2 ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ x2 ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> def test_map_index_order_matters ( self , backend , iterset , x2 , iter2ind2 ) : <EOL> self . cache . clear ( ) <EOL> assert len ( self . cache ) == <NUM_LIT:0> <EOL> k = op2 . Kernel ( """<STR_LIT>""" , '<STR_LIT:k>' ) <EOL> op2 . par_loop ( k , iterset , <EOL> x2 ( op2 . INC , iter2ind2 [ <NUM_LIT:0> ] ) , <EOL> x2 ( op2 . INC , iter2ind2 [ <NUM_LIT:1> ] ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ x2 ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> op2 . par_loop ( k , iterset , <EOL> x2 ( op2 . INC , iter2ind2 [ <NUM_LIT:1> ] ) , <EOL> x2 ( op2 . INC , iter2ind2 [ <NUM_LIT:0> ] ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ x2 ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:2> <EOL> def test_same_iteration_space_works ( self , backend , iterset , x2 , iter2ind2 ) : <EOL> self . cache . clear ( ) <EOL> assert len ( self . cache ) == <NUM_LIT:0> <EOL> kernel_code = FunDecl ( "<STR_LIT>" , "<STR_LIT:k>" , <EOL> [ Decl ( "<STR_LIT>" , c_sym ( "<STR_LIT:x>" ) , qualifiers = [ "<STR_LIT>" ] ) ] , <EOL> c_for ( "<STR_LIT:i>" , <NUM_LIT:1> , "<STR_LIT>" ) ) <EOL> k = op2 . Kernel ( kernel_code , '<STR_LIT:k>' ) <EOL> op2 . par_loop ( k , iterset , <EOL> x2 ( op2 . INC , iter2ind2 [ op2 . i [ <NUM_LIT:0> ] ] ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ x2 ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> op2 . par_loop ( k , iterset , <EOL> x2 ( op2 . INC , iter2ind2 [ op2 . i [ <NUM_LIT:0> ] ] ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ x2 ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> def test_change_const_dim_matters ( self , backend , iterset , diterset ) : <EOL> d = op2 . Dat ( diterset , range ( nelems ) , numpy . uint32 ) <EOL> self . cache . clear ( ) <EOL> assert len ( self . cache ) == <NUM_LIT:0> <EOL> k = op2 . Kernel ( """<STR_LIT>""" , '<STR_LIT:k>' ) <EOL> c = op2 . Const ( <NUM_LIT:1> , <NUM_LIT:1> , name = '<STR_LIT:c>' , dtype = numpy . uint32 ) <EOL> op2 . par_loop ( k , iterset , d ( op2 . WRITE ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ d ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> c . remove_from_namespace ( ) <EOL> c = op2 . Const ( <NUM_LIT:2> , ( <NUM_LIT:1> , <NUM_LIT:1> ) , name = '<STR_LIT:c>' , dtype = numpy . uint32 ) <EOL> op2 . par_loop ( k , iterset , d ( op2 . WRITE ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ d ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:2> <EOL> c . remove_from_namespace ( ) <EOL> def test_change_const_data_doesnt_matter ( self , backend , iterset , diterset ) : <EOL> d = op2 . Dat ( diterset , range ( nelems ) , numpy . uint32 ) <EOL> self . cache . clear ( ) <EOL> assert len ( self . cache ) == <NUM_LIT:0> <EOL> k = op2 . Kernel ( """<STR_LIT>""" , '<STR_LIT:k>' ) <EOL> c = op2 . Const ( <NUM_LIT:1> , <NUM_LIT:1> , name = '<STR_LIT:c>' , dtype = numpy . uint32 ) <EOL> op2 . par_loop ( k , iterset , d ( op2 . WRITE ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ d ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> c . data = <NUM_LIT:2> <EOL> op2 . par_loop ( k , iterset , d ( op2 . WRITE ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ d ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> c . remove_from_namespace ( ) <EOL> def test_change_dat_dtype_matters ( self , backend , iterset , diterset ) : <EOL> d = op2 . Dat ( diterset , range ( nelems ) , numpy . uint32 ) <EOL> self . cache . clear ( ) <EOL> assert len ( self . cache ) == <NUM_LIT:0> <EOL> k = op2 . Kernel ( """<STR_LIT>""" , '<STR_LIT:k>' ) <EOL> op2 . par_loop ( k , iterset , d ( op2 . WRITE ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ d ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> d = op2 . Dat ( diterset , range ( nelems ) , numpy . int32 ) <EOL> op2 . par_loop ( k , iterset , d ( op2 . WRITE ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ d ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:2> <EOL> def test_change_global_dtype_matters ( self , backend , iterset , diterset ) : <EOL> g = op2 . Global ( <NUM_LIT:1> , <NUM_LIT:0> , dtype = numpy . uint32 ) <EOL> self . cache . clear ( ) <EOL> assert len ( self . cache ) == <NUM_LIT:0> <EOL> k = op2 . Kernel ( """<STR_LIT>""" , '<STR_LIT:k>' ) <EOL> op2 . par_loop ( k , iterset , g ( op2 . INC ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ g ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:1> <EOL> g = op2 . Global ( <NUM_LIT:1> , <NUM_LIT:0> , dtype = numpy . float64 ) <EOL> op2 . par_loop ( k , iterset , g ( op2 . INC ) ) <EOL> op2 . base . _trace . evaluate ( set ( [ g ] ) , set ( ) ) <EOL> assert len ( self . cache ) == <NUM_LIT:2> <EOL> class TestKernelCache : <EOL> """<STR_LIT>""" <EOL> cache = op2 . base . Kernel . _cache <EOL> def test_kernels_same_code_same_name ( self , backend ) : <EOL> """<STR_LIT>""" <EOL> code = "<STR_LIT>" <EOL> self . cache . clear ( ) <EOL> k1 = op2 . Kernel ( code , '<STR_LIT:k>' ) <EOL> k2 = op2 . Kernel ( code , '<STR_LIT:k>' ) <EOL> assert k1 is k2 and len ( self . cache ) == <NUM_LIT:1> <EOL> def test_kernels_same_code_differing_name ( self , backend ) : <EOL> """<STR_LIT>""" <EOL> self . cache . clear ( ) <EOL> code = "<STR_LIT>" <EOL> k1 = op2 . Kernel ( code , '<STR_LIT:k>' ) <EOL> k2 = op2 . Kernel ( code , '<STR_LIT:l>' ) <EOL> assert k1 is not k2 and len ( self . cache ) == <NUM_LIT:2> <EOL> def test_kernels_differing_code_same_name ( self , backend ) : <EOL> """<STR_LIT>""" <EOL> self . cache . clear ( ) <EOL> k1 = op2 . Kernel ( "<STR_LIT>" , '<STR_LIT:k>' ) <EOL> k2 = op2 . Kernel ( "<STR_LIT>" , '<STR_LIT:k>' ) <EOL> assert k1 is not k2 and len ( self . cache ) == <NUM_LIT:2> <EOL> def test_kernels_differing_code_differing_name ( self , backend ) : <EOL> """<STR_LIT>""" <EOL> self . cache . clear ( ) <EOL> k1 = op2 . Kernel ( "<STR_LIT>" , '<STR_LIT:k>' ) <EOL> k2 = op2 . Kernel ( "<STR_LIT>" , '<STR_LIT:l>' ) <EOL> assert k1 is not k2 and len ( self . cache ) == <NUM_LIT:2> <EOL> class TestSparsityCache : <EOL> @ pytest . fixture <EOL> def s1 ( cls ) : <EOL> return op2 . Set ( <NUM_LIT:5> ) <EOL> @ pytest . fixture <EOL> def s2 ( cls ) : <EOL> return op2 . Set ( <NUM_LIT:5> ) <EOL> @ pytest . fixture <EOL> def ds2 ( cls , s2 ) : <EOL> return op2 . DataSet ( s2 , <NUM_LIT:1> ) <EOL> @ pytest . fixture <EOL> def m1 ( cls , s1 , s2 ) : <EOL> return op2 . Map ( s1 , s2 , <NUM_LIT:1> , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) <EOL> @ pytest . fixture <EOL> def m2 ( cls , s1 , s2 ) : <EOL> return op2 . Map ( s1 , s2 , <NUM_LIT:1> , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:0> ] ) <EOL> def test_sparsities_differing_maps_not_cached ( self , backend , m1 , m2 , ds2 ) : <EOL> """<STR_LIT>""" <EOL> sp1 = op2 . Sparsity ( ds2 , m1 ) <EOL> sp2 = op2 . Sparsity ( ds2 , m2 ) <EOL> assert sp1 is not sp2 <EOL> def test_sparsities_differing_map_pairs_not_cached ( self , backend , m1 , m2 , ds2 ) : <EOL> """<STR_LIT>""" <EOL> sp1 = op2 . Sparsity ( ( ds2 , ds2 ) , ( m1 , m2 ) ) <EOL> sp2 = op2 . Sparsity ( ( ds2 , ds2 ) , ( m2 , m1 ) ) <EOL> assert sp1 is not sp2 <EOL> def test_sparsities_differing_map_tuples_not_cached ( self , backend , m1 , m2 , ds2 ) : <EOL> """<STR_LIT>""" <EOL> sp1 = op2 . Sparsity ( ( ds2 , ds2 ) , ( ( m1 , m1 ) , ( m2 , m2 ) ) ) <EOL> sp2 = op2 . Sparsity ( ( ds2 , ds2 ) , ( ( m2 , m2 ) , ( m2 , m2 ) ) ) <EOL> assert sp1 is not sp2 <EOL> def test_sparsities_same_map_cached ( self , backend , m1 , ds2 ) : <EOL> """<STR_LIT>""" <EOL> sp1 = op2 . Sparsity ( ds2 , m1 ) <EOL> sp2 = op2 . Sparsity ( ds2 , m1 ) <EOL> assert sp1 is sp2 <EOL> def test_sparsities_same_map_pair_cached ( self , backend , m1 , ds2 ) : <EOL> """<STR_LIT>""" <EOL> sp1 = op2 . Sparsity ( ( ds2 , ds2 ) , ( m1 , m1 ) ) <EOL> sp2 = op2 . Sparsity ( ( ds2 , ds2 ) , ( m1 , m1 ) ) <EOL> assert sp1 is sp2 <EOL> def test_sparsities_same_map_tuple_cached ( self , backend , m1 , m2 , ds2 ) : <EOL> "<STR_LIT>" <EOL> sp1 = op2 . Sparsity ( ( ds2 , ds2 ) , ( ( m1 , m1 ) , ( m2 , m2 ) ) ) <EOL> sp2 = op2 . Sparsity ( ( ds2 , ds2 ) , ( ( m1 , m1 ) , ( m2 , m2 ) ) ) <EOL> assert sp1 is sp2 <EOL> def test_sparsities_different_ordered_map_tuple_cached ( self , backend , m1 , m2 , ds2 ) : <EOL> "<STR_LIT>" <EOL> sp1 = op2 . Sparsity ( ( ds2 , ds2 ) , ( ( m1 , m1 ) , ( m2 , m2 ) ) ) <EOL> sp2 = op2 . Sparsity ( ( ds2 , ds2 ) , ( ( m2 , m2 ) , ( m1 , m1 ) ) ) <EOL> assert sp1 is sp2 <EOL> def test_two_mats_on_same_sparsity_share_data ( self , backend , skip_opencl , m1 , skip_sequential , skip_openmp , ds2 ) : <EOL> """<STR_LIT>""" <EOL> sp = op2 . Sparsity ( ( ds2 , ds2 ) , ( m1 , m1 ) ) <EOL> mat1 = op2 . Mat ( sp , '<STR_LIT>' ) <EOL> mat2 = op2 . Mat ( sp , '<STR_LIT>' ) <EOL> assert mat1 . _colidx is mat2 . _colidx <EOL> assert mat1 . _rowptr is mat2 . _rowptr <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import os <EOL> pytest . main ( os . path . abspath ( __file__ ) ) </s>
