<s> import arrayfire as af <EOL> import sys <EOL> from math import sqrt <EOL> width = <NUM_LIT> <EOL> height = <NUM_LIT> <EOL> def complex_grid ( w , h , zoom , center ) : <EOL> x = ( af . iota ( d0 = <NUM_LIT:1> , d1 = h , tile_dims = ( w , <NUM_LIT:1> ) ) - h / <NUM_LIT:2> ) / zoom + center [ <NUM_LIT:0> ] <EOL> y = ( af . iota ( d0 = w , d1 = <NUM_LIT:1> , tile_dims = ( <NUM_LIT:1> , h ) ) - w / <NUM_LIT:2> ) / zoom + center [ <NUM_LIT:1> ] <EOL> return af . cplx ( x , y ) <EOL> def mandelbrot ( data , it , maxval ) : <EOL> C = data <EOL> Z = data <EOL> mag = af . constant ( <NUM_LIT:0> , * C . dims ( ) ) <EOL> for ii in range ( <NUM_LIT:1> , <NUM_LIT:1> + it ) : <EOL> Z = Z * Z + C <EOL> cond = ( ( af . abs ( Z ) > maxval ) ) . as_type ( af . Dtype . f32 ) <EOL> mag = af . maxof ( mag , cond * ii ) <EOL> C = C * ( <NUM_LIT:1> - cond ) <EOL> Z = Z * ( <NUM_LIT:1> - cond ) <EOL> af . eval ( C ) <EOL> af . eval ( Z ) <EOL> return mag / maxval <EOL> def normalize ( a ) : <EOL> mx = af . max ( a ) <EOL> mn = af . min ( a ) <EOL> return ( a - mn ) / ( mx - mn ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> if ( len ( sys . argv ) > <NUM_LIT:1> ) : <EOL> af . set_device ( int ( sys . argv [ <NUM_LIT:1> ] ) ) <EOL> af . info ( ) <EOL> print ( "<STR_LIT>" ) <EOL> win = af . Window ( width , height , "<STR_LIT>" ) <EOL> win . set_colormap ( af . COLORMAP . SPECTRUM ) <EOL> center = ( - <NUM_LIT> , <NUM_LIT:0.1> ) <EOL> for i in range ( <NUM_LIT:10> , <NUM_LIT> ) : <EOL> zoom = i * i <EOL> if not ( i % <NUM_LIT:10> ) : <EOL> print ( "<STR_LIT>" % ( i , zoom ) ) <EOL> c = complex_grid ( width , height , zoom , center ) <EOL> it = sqrt ( <NUM_LIT:2> * sqrt ( abs ( <NUM_LIT:1> - sqrt ( <NUM_LIT:5> * zoom ) ) ) ) * <NUM_LIT:100> <EOL> if ( win . close ( ) ) : break <EOL> mag = mandelbrot ( c , int ( it ) , <NUM_LIT:1000> ) <EOL> win . image ( normalize ( mag ) ) </s>
