<s> from nose . tools import assert_equal , raises <EOL> from numpy . testing import assert_array_equal <EOL> import numpy as np <EOL> from skimage . util . montage import montage2d <EOL> def test_simple ( ) : <EOL> n_images = <NUM_LIT:3> <EOL> height , width = <NUM_LIT:2> , <NUM_LIT:3> , <EOL> arr_in = np . arange ( n_images * height * width ) <EOL> arr_in = arr_in . reshape ( n_images , height , width ) <EOL> arr_out = montage2d ( arr_in ) <EOL> gt = np . array ( <EOL> [ [ <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] <EOL> ) <EOL> assert_array_equal ( arr_out , gt ) <EOL> def test_fill ( ) : <EOL> n_images = <NUM_LIT:3> <EOL> height , width = <NUM_LIT:2> , <NUM_LIT:3> , <EOL> arr_in = np . arange ( n_images * height * width ) <EOL> arr_in = arr_in . reshape ( n_images , height , width ) <EOL> arr_out = montage2d ( arr_in , fill = <NUM_LIT:0> ) <EOL> gt = np . array ( <EOL> [ [ <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> ] ] <EOL> ) <EOL> assert_array_equal ( arr_out , gt ) <EOL> def test_shape ( ) : <EOL> n_images = <NUM_LIT:15> <EOL> height , width = <NUM_LIT:11> , <NUM_LIT:7> <EOL> arr_in = np . arange ( n_images * height * width ) <EOL> arr_in = arr_in . reshape ( n_images , height , width ) <EOL> alpha = int ( np . ceil ( np . sqrt ( n_images ) ) ) <EOL> arr_out = montage2d ( arr_in ) <EOL> assert_equal ( arr_out . shape , ( alpha * height , alpha * width ) ) <EOL> def test_grid_shape ( ) : <EOL> n_images = <NUM_LIT:6> <EOL> height , width = <NUM_LIT:2> , <NUM_LIT:2> <EOL> arr_in = np . arange ( n_images * height * width , dtype = np . float32 ) <EOL> arr_in = arr_in . reshape ( n_images , height , width ) <EOL> arr_out = montage2d ( arr_in , grid_shape = ( <NUM_LIT:3> , <NUM_LIT:2> ) ) <EOL> correct_arr_out = np . array ( <EOL> [ [ <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] <EOL> ) <EOL> assert_array_equal ( arr_out , correct_arr_out ) <EOL> def test_rescale_intensity ( ) : <EOL> n_images = <NUM_LIT:4> <EOL> height , width = <NUM_LIT:3> , <NUM_LIT:3> <EOL> arr_in = np . arange ( n_images * height * width , dtype = np . float32 ) <EOL> arr_in = arr_in . reshape ( n_images , height , width ) <EOL> arr_out = montage2d ( arr_in , rescale_intensity = True ) <EOL> gt = np . array ( <EOL> [ [ <NUM_LIT:0.> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0.5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.5> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1.> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1.> ] , <EOL> [ <NUM_LIT:0.> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0.5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.5> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1.> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1.> ] ] <EOL> ) <EOL> assert_equal ( arr_out . min ( ) , <NUM_LIT:0.0> ) <EOL> assert_equal ( arr_out . max ( ) , <NUM_LIT:1.0> ) <EOL> assert_array_equal ( arr_out , gt ) <EOL> @ raises ( AssertionError ) <EOL> def test_error_ndim ( ) : <EOL> arr_error = np . random . randn ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ) <EOL> montage2d ( arr_error ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> np . testing . run_module_suite ( ) </s>
