<s> import numpy as np <EOL> from holoviews import Dimension , DynamicMap , Image , HoloMap <EOL> from holoviews . core . operation import DynamicFunction <EOL> from holoviews . element . comparison import ComparisonTestCase <EOL> frequencies = np . linspace ( <NUM_LIT:0.5> , <NUM_LIT> , <NUM_LIT:5> ) <EOL> phases = np . linspace ( <NUM_LIT:0> , np . pi * <NUM_LIT:2> , <NUM_LIT:5> ) <EOL> x , y = np . mgrid [ - <NUM_LIT:5> : <NUM_LIT:6> , - <NUM_LIT:5> : <NUM_LIT:6> ] * <NUM_LIT:0.1> <EOL> def sine_array ( phase , freq ) : <EOL> return np . sin ( phase + ( freq * x ** <NUM_LIT:2> + freq * y ** <NUM_LIT:2> ) ) <EOL> class DynamicTestGeneratorOpen ( ComparisonTestCase ) : <EOL> def test_generator_open_init ( self ) : <EOL> generator = ( Image ( sine_array ( <NUM_LIT:0> , i ) ) for i in range ( <NUM_LIT:10> ) ) <EOL> dmap = DynamicMap ( generator ) <EOL> self . assertEqual ( dmap . mode , '<STR_LIT>' ) <EOL> def test_generator_open_clone ( self ) : <EOL> generator = ( Image ( sine_array ( <NUM_LIT:0> , i ) ) for i in range ( <NUM_LIT:10> ) ) <EOL> dmap = DynamicMap ( generator ) <EOL> self . assertEqual ( dmap , dmap . clone ( ) ) <EOL> def test_generator_open_stopiteration ( self ) : <EOL> generator = ( Image ( sine_array ( <NUM_LIT:0> , i ) ) for i in range ( <NUM_LIT:10> ) ) <EOL> dmap = DynamicMap ( generator ) <EOL> for i in range ( <NUM_LIT:10> ) : <EOL> el = next ( dmap ) <EOL> self . assertEqual ( type ( el ) , Image ) <EOL> try : <EOL> el = next ( dmap ) <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> except Exception as e : <EOL> if e . __class__ != StopIteration : <EOL> raise AssertionError ( "<STR_LIT>" % e ) <EOL> class DynamicTestCallableOpen ( ComparisonTestCase ) : <EOL> def test_callable_open_init ( self ) : <EOL> fn = lambda i : Image ( sine_array ( <NUM_LIT:0> , i ) ) <EOL> dmap = DynamicMap ( fn ) <EOL> self . assertEqual ( dmap . mode , '<STR_LIT>' ) <EOL> def test_callable_open_clone ( self ) : <EOL> fn = lambda i : Image ( sine_array ( <NUM_LIT:0> , i ) ) <EOL> dmap = DynamicMap ( fn ) <EOL> self . assertEqual ( dmap , dmap . clone ( ) ) <EOL> class DynamicTestCallableBounded ( ComparisonTestCase ) : <EOL> def test_callable_bounded_init ( self ) : <EOL> fn = lambda i : Image ( sine_array ( <NUM_LIT:0> , i ) ) <EOL> dmap = DynamicMap ( fn , kdims = [ Dimension ( '<STR_LIT>' , range = ( <NUM_LIT:0> , <NUM_LIT:10> ) ) ] ) <EOL> self . assertEqual ( dmap . mode , '<STR_LIT>' ) <EOL> def test_generator_bounded_clone ( self ) : <EOL> fn = lambda i : Image ( sine_array ( <NUM_LIT:0> , i ) ) <EOL> dmap = DynamicMap ( fn , kdims = [ Dimension ( '<STR_LIT>' , range = ( <NUM_LIT:0> , <NUM_LIT:10> ) ) ] ) <EOL> self . assertEqual ( dmap , dmap . clone ( ) ) <EOL> class DynamicTestSampledBounded ( ComparisonTestCase ) : <EOL> def test_sampled_bounded_init ( self ) : <EOL> fn = lambda i : Image ( sine_array ( <NUM_LIT:0> , i ) ) <EOL> dmap = DynamicMap ( fn , sampled = True ) <EOL> self . assertEqual ( dmap . mode , '<STR_LIT>' ) <EOL> def test_sampled_bounded_resample ( self ) : <EOL> fn = lambda i : Image ( sine_array ( <NUM_LIT:0> , i ) ) <EOL> dmap = DynamicMap ( fn , sampled = True ) <EOL> self . assertEqual ( dmap [ { <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> } ] . keys ( ) , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> class DynamicTestOperation ( ComparisonTestCase ) : <EOL> def test_dynamic_function ( self ) : <EOL> fn = lambda i : Image ( sine_array ( <NUM_LIT:0> , i ) ) <EOL> dmap = DynamicMap ( fn , sampled = True ) <EOL> dmap_with_fn = DynamicFunction ( dmap , function = lambda x : x . clone ( x . data * <NUM_LIT:2> ) ) <EOL> self . assertEqual ( dmap_with_fn [ <NUM_LIT:5> ] , Image ( sine_array ( <NUM_LIT:0> , <NUM_LIT:5> ) * <NUM_LIT:2> ) ) <EOL> def test_dynamic_function_with_kwargs ( self ) : <EOL> fn = lambda i : Image ( sine_array ( <NUM_LIT:0> , i ) ) <EOL> dmap = DynamicMap ( fn , sampled = True ) <EOL> def fn ( x , multiplier = <NUM_LIT:2> ) : <EOL> return x . clone ( x . data * multiplier ) <EOL> dmap_with_fn = DynamicFunction ( dmap , function = fn , kwargs = dict ( multiplier = <NUM_LIT:3> ) ) <EOL> self . assertEqual ( dmap_with_fn [ <NUM_LIT:5> ] , Image ( sine_array ( <NUM_LIT:0> , <NUM_LIT:5> ) * <NUM_LIT:3> ) ) <EOL> class DynamicTestOverlay ( ComparisonTestCase ) : <EOL> def test_dynamic_element_overlay ( self ) : <EOL> fn = lambda i : Image ( sine_array ( <NUM_LIT:0> , i ) ) <EOL> dmap = DynamicMap ( fn , sampled = True ) <EOL> dynamic_overlay = dmap * Image ( sine_array ( <NUM_LIT:0> , <NUM_LIT:10> ) ) <EOL> overlaid = Image ( sine_array ( <NUM_LIT:0> , <NUM_LIT:5> ) ) * Image ( sine_array ( <NUM_LIT:0> , <NUM_LIT:10> ) ) <EOL> self . assertEqual ( dynamic_overlay [ <NUM_LIT:5> ] , overlaid ) <EOL> def test_dynamic_element_underlay ( self ) : <EOL> fn = lambda i : Image ( sine_array ( <NUM_LIT:0> , i ) ) <EOL> dmap = DynamicMap ( fn , sampled = True ) <EOL> dynamic_overlay = Image ( sine_array ( <NUM_LIT:0> , <NUM_LIT:10> ) ) * dmap <EOL> overlaid = Image ( sine_array ( <NUM_LIT:0> , <NUM_LIT:10> ) ) * Image ( sine_array ( <NUM_LIT:0> , <NUM_LIT:5> ) ) <EOL> self . assertEqual ( dynamic_overlay [ <NUM_LIT:5> ] , overlaid ) <EOL> def test_dynamic_dynamicmap_overlay ( self ) : <EOL> fn = lambda i : Image ( sine_array ( <NUM_LIT:0> , i ) ) <EOL> dmap = DynamicMap ( fn , sampled = True ) <EOL> fn2 = lambda i : Image ( sine_array ( <NUM_LIT:0> , i * <NUM_LIT:2> ) ) <EOL> dmap2 = DynamicMap ( fn2 , sampled = True ) <EOL> dynamic_overlay = dmap * dmap2 <EOL> overlaid = Image ( sine_array ( <NUM_LIT:0> , <NUM_LIT:5> ) ) * Image ( sine_array ( <NUM_LIT:0> , <NUM_LIT:10> ) ) <EOL> self . assertEqual ( dynamic_overlay [ <NUM_LIT:5> ] , overlaid ) <EOL> def test_dynamic_holomap_overlay ( self ) : <EOL> fn = lambda i : Image ( sine_array ( <NUM_LIT:0> , i ) ) <EOL> dmap = DynamicMap ( fn , sampled = True ) <EOL> hmap = HoloMap ( { i : Image ( sine_array ( <NUM_LIT:0> , i * <NUM_LIT:2> ) ) for i in range ( <NUM_LIT:10> ) } ) <EOL> dynamic_overlay = dmap * hmap <EOL> overlaid = Image ( sine_array ( <NUM_LIT:0> , <NUM_LIT:5> ) ) * Image ( sine_array ( <NUM_LIT:0> , <NUM_LIT:10> ) ) <EOL> self . assertEqual ( dynamic_overlay [ <NUM_LIT:5> ] , overlaid ) </s>
