<s> '''<STR_LIT>''' <EOL> from __future__ import division , print_function , absolute_import <EOL> import sys <EOL> import numpy as np <EOL> from numpy . testing import ( assert_equal , assert_raises , assert_allclose , <EOL> assert_array_equal , TestCase , run_module_suite ) <EOL> import scipy . ndimage as sndi <EOL> def test_ticket_701 ( ) : <EOL> arr = np . arange ( <NUM_LIT:4> ) . reshape ( ( <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> func = lambda x : np . min ( x ) <EOL> res = sndi . generic_filter ( arr , func , size = ( <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> res2 = sndi . generic_filter ( arr , func , size = <NUM_LIT:1> ) <EOL> assert_equal ( res , res2 ) <EOL> def test_gh_5430 ( ) : <EOL> sigma = np . int32 ( <NUM_LIT:1> ) <EOL> out = sndi . _ni_support . _normalize_sequence ( sigma , <NUM_LIT:1> ) <EOL> assert_equal ( out , [ sigma ] ) <EOL> sigma = np . int64 ( <NUM_LIT:1> ) <EOL> out = sndi . _ni_support . _normalize_sequence ( sigma , <NUM_LIT:1> ) <EOL> assert_equal ( out , [ sigma ] ) <EOL> sigma = <NUM_LIT:1> <EOL> out = sndi . _ni_support . _normalize_sequence ( sigma , <NUM_LIT:1> ) <EOL> assert_equal ( out , [ sigma ] ) <EOL> sigma = [ <NUM_LIT:1> , <NUM_LIT:1> ] <EOL> out = sndi . _ni_support . _normalize_sequence ( sigma , <NUM_LIT:2> ) <EOL> assert_equal ( out , sigma ) <EOL> x = np . random . normal ( size = ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> perlin = np . zeros_like ( x ) <EOL> for i in <NUM_LIT:2> ** np . arange ( <NUM_LIT:6> ) : <EOL> perlin += sndi . filters . gaussian_filter ( x , i , mode = "<STR_LIT>" ) * i ** <NUM_LIT:2> <EOL> x = np . int64 ( <NUM_LIT> ) <EOL> sndi . _ni_support . _normalize_sequence ( x , <NUM_LIT:0> ) <EOL> def test_orders_gauss ( ) : <EOL> arr = np . zeros ( ( <NUM_LIT:1> , ) ) <EOL> yield assert_equal , <NUM_LIT:0> , sndi . gaussian_filter ( arr , <NUM_LIT:1> , order = <NUM_LIT:0> ) <EOL> yield assert_equal , <NUM_LIT:0> , sndi . gaussian_filter ( arr , <NUM_LIT:1> , order = <NUM_LIT:3> ) <EOL> yield assert_raises , ValueError , sndi . gaussian_filter , arr , <NUM_LIT:1> , - <NUM_LIT:1> <EOL> yield assert_raises , ValueError , sndi . gaussian_filter , arr , <NUM_LIT:1> , <NUM_LIT:4> <EOL> yield assert_equal , <NUM_LIT:0> , sndi . gaussian_filter1d ( arr , <NUM_LIT:1> , axis = - <NUM_LIT:1> , order = <NUM_LIT:0> ) <EOL> yield assert_equal , <NUM_LIT:0> , sndi . gaussian_filter1d ( arr , <NUM_LIT:1> , axis = - <NUM_LIT:1> , order = <NUM_LIT:3> ) <EOL> yield assert_raises , ValueError , sndi . gaussian_filter1d , arr , <NUM_LIT:1> , - <NUM_LIT:1> , - <NUM_LIT:1> <EOL> yield assert_raises , ValueError , sndi . gaussian_filter1d , arr , <NUM_LIT:1> , - <NUM_LIT:1> , <NUM_LIT:4> <EOL> def test_valid_origins ( ) : <EOL> """<STR_LIT>""" <EOL> func = lambda x : np . mean ( x ) <EOL> data = np . array ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] , dtype = np . float64 ) <EOL> assert_raises ( ValueError , sndi . generic_filter , data , func , size = <NUM_LIT:3> , <EOL> origin = <NUM_LIT:2> ) <EOL> func2 = lambda x , y : np . mean ( x + y ) <EOL> assert_raises ( ValueError , sndi . generic_filter1d , data , func , <EOL> filter_size = <NUM_LIT:3> , origin = <NUM_LIT:2> ) <EOL> assert_raises ( ValueError , sndi . percentile_filter , data , <NUM_LIT> , size = <NUM_LIT:3> , <EOL> origin = <NUM_LIT:2> ) <EOL> for filter in [ sndi . uniform_filter , sndi . minimum_filter , <EOL> sndi . maximum_filter , sndi . maximum_filter1d , <EOL> sndi . median_filter , sndi . minimum_filter1d ] : <EOL> list ( filter ( data , <NUM_LIT:3> , origin = - <NUM_LIT:1> ) ) <EOL> list ( filter ( data , <NUM_LIT:3> , origin = <NUM_LIT:1> ) ) <EOL> assert_raises ( ValueError , filter , data , <NUM_LIT:3> , origin = <NUM_LIT:2> ) <EOL> def test_gaussian_truncate ( ) : <EOL> arr = np . zeros ( ( <NUM_LIT:100> , <NUM_LIT:100> ) , float ) <EOL> arr [ <NUM_LIT:50> , <NUM_LIT:50> ] = <NUM_LIT:1> <EOL> num_nonzeros_2 = ( sndi . gaussian_filter ( arr , <NUM_LIT:5> , truncate = <NUM_LIT:2> ) > <NUM_LIT:0> ) . sum ( ) <EOL> assert_equal ( num_nonzeros_2 , <NUM_LIT> ** <NUM_LIT:2> ) <EOL> num_nonzeros_5 = ( sndi . gaussian_filter ( arr , <NUM_LIT:5> , truncate = <NUM_LIT:5> ) > <NUM_LIT:0> ) . sum ( ) <EOL> assert_equal ( num_nonzeros_5 , <NUM_LIT> ** <NUM_LIT:2> ) <EOL> f = sndi . gaussian_filter ( arr , [ <NUM_LIT:0.5> , <NUM_LIT> ] , truncate = <NUM_LIT> ) <EOL> fpos = f > <NUM_LIT:0> <EOL> n0 = fpos . any ( axis = <NUM_LIT:0> ) . sum ( ) <EOL> assert_equal ( n0 , <NUM_LIT> ) <EOL> n1 = fpos . any ( axis = <NUM_LIT:1> ) . sum ( ) <EOL> assert_equal ( n1 , <NUM_LIT:5> ) <EOL> x = np . zeros ( <NUM_LIT> ) <EOL> x [ <NUM_LIT> ] = <NUM_LIT:1> <EOL> f = sndi . gaussian_filter1d ( x , sigma = <NUM_LIT:2> , truncate = <NUM_LIT> ) <EOL> n = ( f > <NUM_LIT:0> ) . sum ( ) <EOL> assert_equal ( n , <NUM_LIT:15> ) <EOL> y = sndi . gaussian_laplace ( x , sigma = <NUM_LIT:2> , truncate = <NUM_LIT> ) <EOL> nonzero_indices = np . where ( y != <NUM_LIT:0> ) [ <NUM_LIT:0> ] <EOL> n = nonzero_indices . ptp ( ) + <NUM_LIT:1> <EOL> assert_equal ( n , <NUM_LIT:15> ) <EOL> y = sndi . gaussian_gradient_magnitude ( x , sigma = <NUM_LIT:2> , truncate = <NUM_LIT> ) <EOL> nonzero_indices = np . where ( y != <NUM_LIT:0> ) [ <NUM_LIT:0> ] <EOL> n = nonzero_indices . ptp ( ) + <NUM_LIT:1> <EOL> assert_equal ( n , <NUM_LIT:15> ) <EOL> class TestThreading ( TestCase ) : <EOL> def check_func_thread ( self , n , fun , args , out ) : <EOL> from threading import Thread <EOL> thrds = [ Thread ( target = fun , args = args , kwargs = { '<STR_LIT>' : out [ x ] } ) for x in range ( n ) ] <EOL> [ t . start ( ) for t in thrds ] <EOL> [ t . join ( ) for t in thrds ] <EOL> def check_func_serial ( self , n , fun , args , out ) : <EOL> for i in range ( n ) : <EOL> fun ( * args , output = out [ i ] ) <EOL> def test_correlate1d ( self ) : <EOL> d = np . random . randn ( <NUM_LIT> ) <EOL> os = np . empty ( ( <NUM_LIT:4> , d . size ) ) <EOL> ot = np . empty_like ( os ) <EOL> self . check_func_serial ( <NUM_LIT:4> , sndi . correlate1d , ( d , np . arange ( <NUM_LIT:5> ) ) , os ) <EOL> self . check_func_thread ( <NUM_LIT:4> , sndi . correlate1d , ( d , np . arange ( <NUM_LIT:5> ) ) , ot ) <EOL> assert_array_equal ( os , ot ) <EOL> def test_correlate ( self ) : <EOL> d = np . random . randn ( <NUM_LIT> , <NUM_LIT> ) <EOL> k = np . random . randn ( <NUM_LIT:10> , <NUM_LIT:10> ) <EOL> os = np . empty ( [ <NUM_LIT:4> ] + list ( d . shape ) ) <EOL> ot = np . empty_like ( os ) <EOL> self . check_func_serial ( <NUM_LIT:4> , sndi . correlate , ( d , k ) , os ) <EOL> self . check_func_thread ( <NUM_LIT:4> , sndi . correlate , ( d , k ) , ot ) <EOL> assert_array_equal ( os , ot ) <EOL> def test_median_filter ( self ) : <EOL> d = np . random . randn ( <NUM_LIT> , <NUM_LIT> ) <EOL> os = np . empty ( [ <NUM_LIT:4> ] + list ( d . shape ) ) <EOL> ot = np . empty_like ( os ) <EOL> self . check_func_serial ( <NUM_LIT:4> , sndi . median_filter , ( d , <NUM_LIT:3> ) , os ) <EOL> self . check_func_thread ( <NUM_LIT:4> , sndi . median_filter , ( d , <NUM_LIT:3> ) , ot ) <EOL> assert_array_equal ( os , ot ) <EOL> def test_uniform_filter1d ( self ) : <EOL> d = np . random . randn ( <NUM_LIT> ) <EOL> os = np . empty ( ( <NUM_LIT:4> , d . size ) ) <EOL> ot = np . empty_like ( os ) <EOL> self . check_func_serial ( <NUM_LIT:4> , sndi . uniform_filter1d , ( d , <NUM_LIT:5> ) , os ) <EOL> self . check_func_thread ( <NUM_LIT:4> , sndi . uniform_filter1d , ( d , <NUM_LIT:5> ) , ot ) <EOL> assert_array_equal ( os , ot ) <EOL> def test_minmax_filter ( self ) : <EOL> d = np . random . randn ( <NUM_LIT> , <NUM_LIT> ) <EOL> os = np . empty ( [ <NUM_LIT:4> ] + list ( d . shape ) ) <EOL> ot = np . empty_like ( os ) <EOL> self . check_func_serial ( <NUM_LIT:4> , sndi . maximum_filter , ( d , <NUM_LIT:3> ) , os ) <EOL> self . check_func_thread ( <NUM_LIT:4> , sndi . maximum_filter , ( d , <NUM_LIT:3> ) , ot ) <EOL> assert_array_equal ( os , ot ) <EOL> self . check_func_serial ( <NUM_LIT:4> , sndi . minimum_filter , ( d , <NUM_LIT:3> ) , os ) <EOL> self . check_func_thread ( <NUM_LIT:4> , sndi . minimum_filter , ( d , <NUM_LIT:3> ) , ot ) <EOL> assert_array_equal ( os , ot ) <EOL> def test_minmaximum_filter1d ( ) : <EOL> in_ = np . arange ( <NUM_LIT:10> ) <EOL> out = sndi . minimum_filter1d ( in_ , <NUM_LIT:1> ) <EOL> assert_equal ( in_ , out ) <EOL> out = sndi . maximum_filter1d ( in_ , <NUM_LIT:1> ) <EOL> assert_equal ( in_ , out ) <EOL> out = sndi . minimum_filter1d ( in_ , <NUM_LIT:5> , mode = '<STR_LIT>' ) <EOL> assert_equal ( [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> ] , out ) <EOL> out = sndi . maximum_filter1d ( in_ , <NUM_LIT:5> , mode = '<STR_LIT>' ) <EOL> assert_equal ( [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:9> , <NUM_LIT:9> ] , out ) <EOL> out = sndi . minimum_filter1d ( in_ , <NUM_LIT:5> , mode = '<STR_LIT>' , cval = - <NUM_LIT:1> ) <EOL> assert_equal ( [ - <NUM_LIT:1> , - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , - <NUM_LIT:1> , - <NUM_LIT:1> ] , out ) <EOL> out = sndi . maximum_filter1d ( in_ , <NUM_LIT:5> , mode = '<STR_LIT>' , cval = <NUM_LIT:10> ) <EOL> assert_equal ( [ <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> , <NUM_LIT:10> ] , out ) <EOL> out = sndi . minimum_filter1d ( in_ , <NUM_LIT:5> , mode = '<STR_LIT>' ) <EOL> assert_equal ( [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> ] , out ) <EOL> out = sndi . maximum_filter1d ( in_ , <NUM_LIT:5> , mode = '<STR_LIT>' ) <EOL> assert_equal ( [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:9> , <NUM_LIT:9> ] , out ) <EOL> out = sndi . minimum_filter1d ( in_ , <NUM_LIT:5> , mode = '<STR_LIT>' ) <EOL> assert_equal ( [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:0> , <NUM_LIT:0> ] , out ) <EOL> out = sndi . maximum_filter1d ( in_ , <NUM_LIT:5> , mode = '<STR_LIT>' ) <EOL> assert_equal ( [ <NUM_LIT:9> , <NUM_LIT:9> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:9> , <NUM_LIT:9> ] , out ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> run_module_suite ( argv = sys . argv ) </s>
