@@ -622,41 +622,68 @@ def test_Convolve3D(par, dtype):
622622 assert xadj .dtype == dtype
623623
624624
625- @pytest .mark .parametrize ("ndims " , [3 , 4 ])
625+ @pytest .mark .parametrize ("par " , [( par1_3d ), ( par2_3d ) ])
626626@pytest .mark .parametrize ("axes" , [(0 , 1 , 2 ), (1 , 2 , 0 ), (2 , 0 , 1 ), (- 1 , - 3 , - 2 )])
627627@pytest .mark .parametrize ("dtype" , [np .float32 , np .float64 , np .complex128 ])
628- def test_Convolve3D_axes (ndims , axes , dtype ):
628+ def test_Convolve3D_axes (par , axes , dtype ):
629629 """Dot-test and modelling with permuted axes, on 3D and 4D models."""
630630 np .random .seed (10 )
631- dims = (5 , 6 , 7 , 8 )[:ndims ]
632- h = np .random .normal (0.0 , 1.0 , (2 , 3 , 4 )).astype (dtype )
631+ h = np .random .normal (0.0 , 1.0 , nfilt ).astype (dtype )
633632 if np .issubdtype (dtype , np .complexfloating ):
634633 h += 1j * np .random .normal (0.0 , 1.0 , h .shape )
635- offset = (0 , 1 , 2 )
636634 permutation = tuple (axis % 3 for axis in axes )
637- model_axes = (
638- axes if ndims == 3 else tuple (axis - 1 if axis < 0 else axis for axis in axes )
635+
636+ # 3D on 3D
637+ dims = (par ["nz" ], par ["ny" ], par ["nx" ])
638+ Cop = ConvolveND (
639+ dims ,
640+ h = h .transpose (permutation ),
641+ offset = tuple (par ["offset" ][i ] for i in permutation ),
642+ axes = axes ,
643+ dtype = dtype ,
639644 )
645+ Cop_ref = ConvolveND (dims , h = h , offset = par ["offset" ], axes = (0 , 1 , 2 ), dtype = dtype )
646+ assert dottest (
647+ Cop ,
648+ par ["nz" ] * par ["ny" ] * par ["nx" ],
649+ par ["nz" ] * par ["ny" ] * par ["nx" ],
650+ backend = backend ,
651+ complexflag = 3 if np .issubdtype (dtype , np .complexfloating ) else 0 ,
652+ rtol = 1e-4 if dtype == np .float32 else 1e-6 ,
653+ )
654+ # Forward and adjoint dtype check
655+ x = np .random .normal (0.0 , 1.0 , dims ).astype (dtype )
656+ y = Cop * x
657+ xadj = Cop .H * x
658+ assert y .dtype == dtype
659+ assert xadj .dtype == dtype
660+ assert_array_almost_equal (y , Cop_ref * x , decimal = 3 )
661+ assert_array_almost_equal (xadj , Cop_ref .H * x , decimal = 3 )
662+
663+ # 3D on 4D (only modelling)
664+ dims = (par ["nz" ], par ["ny" ], par ["nx" ], par ["nt" ])
640665 Cop = ConvolveND (
641666 dims ,
642667 h = h .transpose (permutation ),
643- offset = tuple (offset [i ] for i in permutation ),
644- axes = model_axes ,
668+ offset = tuple (par [ " offset" ] [i ] for i in permutation ),
669+ axes = tuple ( axis - 1 if axis < 0 else axis for axis in axes ) ,
645670 dtype = dtype ,
646671 )
647- reference = ConvolveND (dims , h = h , offset = offset , axes = (0 , 1 , 2 ), dtype = dtype )
672+ Cop_ref = ConvolveND (dims , h = h , offset = par [ " offset" ] , axes = (0 , 1 , 2 ), dtype = dtype )
648673 assert dottest (
649674 Cop ,
650- Cop . shape [ 0 ],
651- Cop . shape [ 1 ],
675+ par [ "nz" ] * par [ "ny" ] * par [ "nx" ] * par [ "nt" ],
676+ par [ "nz" ] * par [ "ny" ] * par [ "nx" ] * par [ "nt" ],
652677 backend = backend ,
653678 complexflag = 3 if np .issubdtype (dtype , np .complexfloating ) else 0 ,
654679 rtol = 1e-4 if dtype == np .float32 else 1e-6 ,
655680 )
681+
682+ # Forward and adjoint dtype check
656683 x = np .random .normal (0.0 , 1.0 , dims ).astype (dtype )
657684 y = Cop * x
658685 xadj = Cop .H * x
659686 assert y .dtype == dtype
660687 assert xadj .dtype == dtype
661- assert_array_almost_equal (y , reference * x , decimal = 3 )
662- assert_array_almost_equal (xadj , reference .H * x , decimal = 3 )
688+ assert_array_almost_equal (y , Cop_ref * x , decimal = 3 )
689+ assert_array_almost_equal (xadj , Cop_ref .H * x , decimal = 3 )
0 commit comments