@@ -741,18 +741,33 @@ def test_copy_object(do_minimal):
741
741
0.5 ,
742
742
np .array ([[0.5 , 0.51763809 , 30.0 , 12.13818192 ], [1.5 , 1.0 , 60.0 , 6.28318531 ]]),
743
743
),
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
+ ),
744
757
],
745
758
)
746
759
def test_scalar_operations (operation , starting_all_arrays , scalar_value , expected_all_arrays , do_minimal_tth ):
747
760
do = do_minimal_tth
748
761
assert np .allclose (do .all_arrays , starting_all_arrays )
749
-
750
762
if operation == "add" :
751
763
result_right = do + scalar_value
752
764
result_left = scalar_value + do
753
765
elif operation == "sub" :
754
766
result_right = do - scalar_value
755
767
result_left = scalar_value - do
768
+ elif operation == "mul" :
769
+ result_right = do * scalar_value
770
+ result_left = scalar_value * do
756
771
757
772
assert np .allclose (result_right .all_arrays , expected_all_arrays )
758
773
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
773
788
np .array ([[0.0 , 0.51763809 , 30.0 , 12.13818192 ], [0.0 , 1.0 , 60.0 , 6.28318531 ]]),
774
789
np .array ([[0.0 , 6.28318531 , 100.70777771 , 1 ], [0.0 , 3.14159265 , 45.28748053 , 2.0 ]]),
775
790
),
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
+ ),
776
796
],
777
797
)
778
798
def test_binary_operator_on_do (
@@ -797,6 +817,9 @@ def test_binary_operator_on_do(
797
817
elif operation == "sub" :
798
818
do_1_y_modified = do_1 - do_2
799
819
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
800
823
801
824
assert np .allclose (do_1_y_modified .all_arrays , expected_do_1_all_arrays_with_y_modified )
802
825
assert np .allclose (do_2_y_modified .all_arrays , expected_do_2_all_arrays_with_y_modified )
0 commit comments