@@ -430,27 +430,23 @@ def test_vectorized_scatcoeffs(self, num_wavelen, num_layer):
430430 assert_equal (coeffs , coeffs_direct )
431431
432432 # make sure shape is correct
433- if num_wavelen == 1 :
434- expected_shape = (2 , nstop )
435- assert coeffs .shape == expected_shape
436- # no further test since no loop required in this case
437- else :
438- expected_shape = (2 , num_wavelen , nstop )
439- assert coeffs .shape == expected_shape
440-
441- # we should get same value from loop
442- coeffs_loop = np .zeros (expected_shape , dtype = complex )
443- for i in range (m .shape [0 ]):
444- if num_layer == 1 :
445- c = mie ._scatcoeffs (m [i ], x [i ], nstop )
446- else :
447- # need to specify nstop here; otherwise we will get a
448- # different number of scattering coefficients for each
449- # wavelength, since _scatcoeffs_multi() picks the largest x
450- # for each wavelength.
451- c = mie ._scatcoeffs_multi (m [i ], x [i ], nstop )
452- coeffs_loop [:, i ] = c
453- assert_equal (coeffs , coeffs_loop )
433+ expected_shape = (2 , num_wavelen , nstop )
434+ assert coeffs .shape == expected_shape
435+
436+ # we should get same value from loop
437+ coeffs_loop = []
438+ for i in range (m .shape [0 ]):
439+ if num_layer == 1 :
440+ coeffs_loop .append (mie ._scatcoeffs (m [i ], x [i ], nstop ))
441+ else :
442+ # need to specify nstop here; otherwise we will get a
443+ # different number of scattering coefficients for each
444+ # wavelength, since _scatcoeffs_multi() picks the largest x
445+ # for each wavelength.
446+ coeffs_loop .append (mie ._scatcoeffs_multi (m [i ], x [i ], nstop ))
447+ # concatenate along wavelength axis
448+ coeffs_loop = np .concatenate (coeffs_loop , axis = 1 )
449+ assert_equal (coeffs , coeffs_loop )
454450
455451 @pytest .mark .parametrize ("num_wavelen,num_layer" ,
456452 [(1 , 1 ), (10 , 1 ), (1 , 5 ), (10 , 5 )])
@@ -631,10 +627,7 @@ def test_vectorized_angular_functions(self, num_wavelen,
631627
632628 # check that shapes of all the computed quantities are correct
633629 for element in vsa + mat :
634- if num_wavelen > 1 :
635- assert element .shape == (num_wavelen , ) + thetas .shape
636- else :
637- assert element .shape == thetas .shape
630+ assert element .shape == (num_wavelen , ) + thetas .shape
638631 assert i12 .shape == (2 , num_wavelen ) + thetas .shape
639632
640633 # check that vectorized calculations match looped calculations over
@@ -691,13 +684,13 @@ def test_vectorized_angular_functions(self, num_wavelen,
691684 dsigma_1 [i ] = integral_loop [3 ].squeeze ()
692685 dsigma_2 [i ] = integral_loop [4 ].squeeze ()
693686
694- assert_equal (mat [0 ], S1 . squeeze () )
695- assert_equal (mat [1 ], S2 . squeeze () )
696- assert_equal (mat [2 ], S3 . squeeze () )
697- assert_equal (mat [3 ], S4 . squeeze () )
687+ assert_equal (mat [0 ], S1 )
688+ assert_equal (mat [1 ], S2 )
689+ assert_equal (mat [2 ], S3 )
690+ assert_equal (mat [3 ], S4 )
698691
699- assert_equal (vsa [0 ], amp0 . squeeze () )
700- assert_equal (vsa [1 ], amp1 . squeeze () )
692+ assert_equal (vsa [0 ], amp0 )
693+ assert_equal (vsa [1 ], amp1 )
701694
702695 assert_equal (i12 [0 ], i1 )
703696 assert_equal (i12 [1 ], i2 )
@@ -763,10 +756,11 @@ def test_vectorized_asymmetry_parameter(self, num_wavelen, num_layer):
763756
764757 # we should get same values from loop. Need to set nstop to the
765758 # same value as used in the vectorized calculation.
766- g_loop = np . zeros ( expected_shape , dtype = float )
759+ g_loop = []
767760 nstop = mie ._nstop (x .max ())
768761 for i in range (num_wavelen ):
769- g_loop [i ] = mie .calc_g (m [i ], x [i ], nstop = nstop )
762+ g_loop .append (mie .calc_g (m [i ], x [i ], nstop = nstop ))
763+ g_loop = np .concatenate (g_loop , axis = 0 )
770764 assert_equal (g , g_loop )
771765
772766 @pytest .mark .parametrize ("num_wavelen, num_layer" ,
@@ -782,10 +776,7 @@ def test_vectorized_cross_sections(self, num_wavelen, num_layer):
782776 cscat , cext , cback , cabs , asym = mie .calc_cross_sections (m , x )
783777
784778 # test shape
785- if num_wavelen > 1 :
786- expected_shape = (num_wavelen ,)
787- else :
788- expected_shape = ()
779+ expected_shape = (num_wavelen ,)
789780 for cs in [cscat , cext , cback , cabs , asym ]:
790781 assert cs .shape == expected_shape
791782
@@ -798,7 +789,7 @@ def test_vectorized_cross_sections(self, num_wavelen, num_layer):
798789 for i in range (num_wavelen ):
799790 cs = mie .calc_cross_sections (m [i ], x [i ])
800791 cscat_loop [i ], cext_loop [i ], cback_loop [i ], \
801- cabs_loop [i ], asym_loop [i ] = (c for c in cs )
792+ cabs_loop [i ], asym_loop [i ] = (c . squeeze () for c in cs )
802793 assert_equal (cscat , cscat_loop )
803794 assert_equal (cext , cext_loop )
804795 assert_equal (cback , cback_loop )
@@ -855,20 +846,16 @@ def test_vectorized_calc_ang_scat(self, num_wavelen, num_layer):
855846 """
856847 m , x = mx (num_wavelen , num_layer , ** self .mxargs )
857848 form_factor = mie .calc_ang_scat (m , x , self .angles )
858- if num_wavelen == 1 :
859- expected_shape = (2 , self .num_angle ,)
860- assert form_factor .shape == expected_shape
861- # no further test required since there is only one wavelength
862- return
863- else :
864- expected_shape = (2 , num_wavelen , self .num_angle )
865- assert form_factor .shape == expected_shape
849+ expected_shape = (2 , num_wavelen , self .num_angle )
850+ assert form_factor .shape == expected_shape
866851
867852 # we should get same values from loop
868- iparperp_loop = np . zeros ( expected_shape , dtype = float )
853+ iparperp_loop = []
869854 for i in range (num_wavelen ):
870855 iparperp = mie .calc_ang_scat (m [i ], x [i ], self .angles )
871- iparperp_loop [:, i ] = iparperp
856+ iparperp_loop .append (iparperp )
857+ # concatenate along wavelength axis
858+ iparperp_loop = np .concatenate (iparperp_loop , axis = 1 )
872859 assert_equal (form_factor , iparperp_loop )
873860
874861 # check vectorization for Rayleigh-Gans approximation
0 commit comments