@@ -1734,6 +1734,19 @@ def test_Image_inplace_add():
1734
1734
err_msg = "Inplace add in Image class does not match reference for dtypes = "
1735
1735
+ str (types [i ])+ " and " + str (types [j ]))
1736
1736
1737
+ # Adding via array:
1738
+ image4 = image2 .copy ()
1739
+ image4 .array += image2 .array
1740
+ np .testing .assert_allclose (image4 .array , 2 * image2 .array )
1741
+ image4 .array [:] += image2 .array
1742
+ np .testing .assert_allclose (image4 .array , 3 * image2 .array )
1743
+ image4 .array = image4 .array + image2 .array
1744
+ np .testing .assert_allclose (image4 .array , 4 * image2 .array )
1745
+ with assert_raises (ValueError ):
1746
+ image4 .array += image2 .array [:2 ,:]
1747
+ with assert_raises (ValueError ):
1748
+ image4 .array = image4 .array [:2 ,:] + image2 .array [:2 ,:]
1749
+
1737
1750
with assert_raises (ValueError ):
1738
1751
image1 += image1 .subImage (galsim .BoundsI (0 ,4 ,0 ,4 ))
1739
1752
@@ -1776,6 +1789,19 @@ def test_Image_inplace_subtract():
1776
1789
err_msg = "Inplace subtract in Image class does not match reference for dtypes = "
1777
1790
+ str (types [i ])+ " and " + str (types [j ]))
1778
1791
1792
+ # Subtracting via array:
1793
+ image4 = 5 * image2
1794
+ image4 .array -= image2 .array
1795
+ np .testing .assert_allclose (image4 .array , 4 * image2 .array )
1796
+ image4 .array [:] -= image2 .array
1797
+ np .testing .assert_allclose (image4 .array , 3 * image2 .array )
1798
+ image4 .array = image4 .array - image2 .array
1799
+ np .testing .assert_allclose (image4 .array , 2 * image2 .array )
1800
+ with assert_raises (ValueError ):
1801
+ image4 .array -= image2 .array [:2 ,:]
1802
+ with assert_raises (ValueError ):
1803
+ image4 .array = image4 .array [:2 ,:] - image2 .array [:2 ,:]
1804
+
1779
1805
with assert_raises (ValueError ):
1780
1806
image1 -= image1 .subImage (galsim .BoundsI (0 ,4 ,0 ,4 ))
1781
1807
@@ -1907,6 +1933,17 @@ def test_Image_inplace_scalar_add():
1907
1933
err_msg = "Inplace scalar add in Image class does not match reference for dtype = "
1908
1934
+ str (types [i ]))
1909
1935
1936
+ # Adding via array:
1937
+ image4 = image1 .copy ()
1938
+ image4 .array += 1
1939
+ np .testing .assert_allclose (image4 .array , image1 .array + 1 )
1940
+ image4 .array [:] += 1
1941
+ np .testing .assert_allclose (image4 .array , image1 .array + 2 )
1942
+ image4 .array = image4 .array + 1
1943
+ np .testing .assert_allclose (image4 .array , image1 .array + 3 )
1944
+ with assert_raises (ValueError ):
1945
+ image4 .array = image4 .array [:2 ,:] + 1
1946
+
1910
1947
1911
1948
@timer
1912
1949
def test_Image_inplace_scalar_subtract ():
@@ -1961,6 +1998,17 @@ def test_Image_inplace_scalar_multiply():
1961
1998
err_msg = "Inplace scalar multiply in Image class does"
1962
1999
+ " not match reference for dtype = " + str (types [i ]))
1963
2000
2001
+ # Multiplying via array:
2002
+ image4 = image2 .copy ()
2003
+ image4 .array *= 2
2004
+ np .testing .assert_allclose (image4 .array , 2 * image2 .array )
2005
+ image4 .array [:] *= 2
2006
+ np .testing .assert_allclose (image4 .array , 4 * image2 .array )
2007
+ image4 .array = image4 .array * 2
2008
+ np .testing .assert_allclose (image4 .array , 8 * image2 .array )
2009
+ with assert_raises (ValueError ):
2010
+ image4 .array = image4 .array [:2 ,:] * 2
2011
+
1964
2012
1965
2013
@timer
1966
2014
def test_Image_inplace_scalar_divide ():
@@ -1988,6 +2036,36 @@ def test_Image_inplace_scalar_divide():
1988
2036
err_msg = "Inplace scalar divide in Image class does"
1989
2037
+ " not match reference for dtype = " + str (types [i ]))
1990
2038
2039
+ # Dividing via array:
2040
+ image4 = 16 * image2
2041
+ if simple_types [i ] is int :
2042
+ with assert_raises (TypeError ):
2043
+ image4 .array /= 2
2044
+ with assert_raises (TypeError ):
2045
+ image4 .array [:] /= 2
2046
+ np .testing .assert_array_equal (image4 .array , 16 * image2 .array ) # unchanged yet
2047
+ image4 .array //= 2
2048
+ np .testing .assert_array_equal (image4 .array , 8 * image2 .array )
2049
+ image4 .array [:] //= 2
2050
+ np .testing .assert_array_equal (image4 .array , 4 * image2 .array )
2051
+ image4 .array = image4 .array // 2
2052
+ np .testing .assert_array_equal (image4 .array , 2 * image2 .array )
2053
+ # The following works for integer by explicitly rounding and casting.
2054
+ # The native numpy operation would use floor to cast to int, which is 1 smaller.
2055
+ image4 .array = (image4 .array / 2.0001 )
2056
+ np .testing .assert_array_equal (image4 .array , image2 .array )
2057
+ with assert_raises (ValueError ):
2058
+ image4 .array = image4 .array [:2 ,:] // 2
2059
+ else :
2060
+ image4 .array /= 2
2061
+ np .testing .assert_allclose (image4 .array , 8 * image2 .array )
2062
+ image4 .array [:] /= 2
2063
+ np .testing .assert_allclose (image4 .array , 4 * image2 .array )
2064
+ image4 .array = image4 .array / 2
2065
+ np .testing .assert_allclose (image4 .array , 2 * image2 .array )
2066
+ with assert_raises (ValueError ):
2067
+ image4 .array = image4 .array [:2 ,:] / 2
2068
+
1991
2069
1992
2070
@timer
1993
2071
def test_Image_inplace_scalar_pow ():
0 commit comments