@@ -741,18 +741,33 @@ def test_copy_object(do_minimal):
741741 0.5 ,
742742 np .array ([[0.5 , 0.51763809 , 30.0 , 12.13818192 ], [1.5 , 1.0 , 60.0 , 6.28318531 ]]),
743743 ),
744+ # C2. Test scalar multiplication to yarray values (intensity), expect no change to xarrays (q, tth, d)
745+ ( # 1. Multipliy by integer 2
746+ "mul" ,
747+ np .array ([[1.0 , 0.51763809 , 30.0 , 12.13818192 ], [2.0 , 1.0 , 60.0 , 6.28318531 ]]),
748+ 2 ,
749+ np .array ([[2.0 , 0.51763809 , 30.0 , 12.13818192 ], [4.0 , 1.0 , 60.0 , 6.28318531 ]]),
750+ ),
751+ ( # 2. Multipliy by float 0.5
752+ "mul" ,
753+ np .array ([[1.0 , 0.51763809 , 30.0 , 12.13818192 ], [2.0 , 1.0 , 60.0 , 6.28318531 ]]),
754+ 2.5 ,
755+ np .array ([[2.5 , 0.51763809 , 30.0 , 12.13818192 ], [5.0 , 1.0 , 60.0 , 6.28318531 ]]),
756+ ),
744757 ],
745758)
746759def test_scalar_operations (operation , starting_all_arrays , scalar_value , expected_all_arrays , do_minimal_tth ):
747760 do = do_minimal_tth
748761 assert np .allclose (do .all_arrays , starting_all_arrays )
749-
750762 if operation == "add" :
751763 result_right = do + scalar_value
752764 result_left = scalar_value + do
753765 elif operation == "sub" :
754766 result_right = do - scalar_value
755767 result_left = scalar_value - do
768+ elif operation == "mul" :
769+ result_right = do * scalar_value
770+ result_left = scalar_value * do
756771
757772 assert np .allclose (result_right .all_arrays , expected_all_arrays )
758773 assert np .allclose (result_left .all_arrays , expected_all_arrays )
@@ -773,6 +788,11 @@ def test_scalar_operations(operation, starting_all_arrays, scalar_value, expecte
773788 np .array ([[0.0 , 0.51763809 , 30.0 , 12.13818192 ], [0.0 , 1.0 , 60.0 , 6.28318531 ]]),
774789 np .array ([[0.0 , 6.28318531 , 100.70777771 , 1 ], [0.0 , 3.14159265 , 45.28748053 , 2.0 ]]),
775790 ),
791+ (
792+ "mul" ,
793+ np .array ([[1.0 , 0.51763809 , 30.0 , 12.13818192 ], [4.0 , 1.0 , 60.0 , 6.28318531 ]]),
794+ np .array ([[1.0 , 6.28318531 , 100.70777771 , 1 ], [4.0 , 3.14159265 , 45.28748053 , 2.0 ]]),
795+ ),
776796 ],
777797)
778798def test_binary_operator_on_do (
@@ -797,6 +817,9 @@ def test_binary_operator_on_do(
797817 elif operation == "sub" :
798818 do_1_y_modified = do_1 - do_2
799819 do_2_y_modified = do_2 - do_1
820+ elif operation == "mul" :
821+ do_1_y_modified = do_1 * do_2
822+ do_2_y_modified = do_2 * do_1
800823
801824 assert np .allclose (do_1_y_modified .all_arrays , expected_do_1_all_arrays_with_y_modified )
802825 assert np .allclose (do_2_y_modified .all_arrays , expected_do_2_all_arrays_with_y_modified )
0 commit comments