MCPcopy
hub / github.com/numpy/numpy / test_basic_arithmetic

Method test_basic_arithmetic

numpy/ma/tests/test_core.py:1160–1193  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1158 return x, y, a10, m1, m2, xm, ym, z, zm, xf
1159
1160 def test_basic_arithmetic(self):
1161 # Test of basic arithmetic.
1162 x, y, a10, _, _, xm, ym, _, _, xf = self._create_data()
1163 a2d = array([[1, 2], [0, 4]])
1164 a2dm = masked_array(a2d, [[0, 0], [1, 0]])
1165 assert_equal(a2d * a2d, a2d * a2dm)
1166 assert_equal(a2d + a2d, a2d + a2dm)
1167 assert_equal(a2d - a2d, a2d - a2dm)
1168 for s in [(12,), (4, 3), (2, 6)]:
1169 x = x.reshape(s)
1170 y = y.reshape(s)
1171 xm = xm.reshape(s)
1172 ym = ym.reshape(s)
1173 xf = xf.reshape(s)
1174 assert_equal(-x, -xm)
1175 assert_equal(x + y, xm + ym)
1176 assert_equal(x - y, xm - ym)
1177 assert_equal(x * y, xm * ym)
1178 assert_equal(x / y, xm / ym)
1179 assert_equal(a10 + y, a10 + ym)
1180 assert_equal(a10 - y, a10 - ym)
1181 assert_equal(a10 * y, a10 * ym)
1182 assert_equal(a10 / y, a10 / ym)
1183 assert_equal(x + a10, xm + a10)
1184 assert_equal(x - a10, xm - a10)
1185 assert_equal(x * a10, xm * a10)
1186 assert_equal(x / a10, xm / a10)
1187 assert_equal(x ** 2, xm ** 2)
1188 assert_equal(abs(x) ** 2.5, abs(xm) ** 2.5)
1189 assert_equal(x ** y, xm ** ym)
1190 assert_equal(np.add(x, y), add(xm, ym))
1191 assert_equal(np.subtract(x, y), subtract(xm, ym))
1192 assert_equal(np.multiply(x, y), multiply(xm, ym))
1193 assert_equal(np.divide(x, y), divide(xm, ym))
1194
1195 def test_divide_on_different_shapes(self):
1196 x = arange(6, dtype=float).reshape((2, 3))

Callers

nothing calls this directly

Calls 7

_create_dataMethod · 0.95
arrayFunction · 0.90
assert_equalFunction · 0.90
multiplyFunction · 0.90
addFunction · 0.85
reshapeMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected