MCPcopy Index your code
hub / github.com/numpy/numpy / test_trace

Method test_trace

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

Source from the content-addressed store, hash-verified

4227 [[-0.5, 0.5, mval], [-1.0, mval, 1.0]])
4228
4229 def test_trace(self):
4230 # Tests trace on MaskedArrays.
4231 _, X, _, _, _, mX, _, _, _, _ = self._create_data()
4232 mXdiag = mX.diagonal()
4233 assert_equal(mX.trace(), mX.diagonal().compressed().sum())
4234 assert_almost_equal(mX.trace(),
4235 X.trace() - sum(mXdiag.mask * X.diagonal(),
4236 axis=0))
4237 assert_equal(np.trace(mX), mX.trace())
4238
4239 # gh-5560
4240 arr = np.arange(2 * 4 * 4).reshape(2, 4, 4)
4241 m_arr = np.ma.masked_array(arr, False)
4242 assert_equal(arr.trace(axis1=1, axis2=2), m_arr.trace(axis1=1, axis2=2))
4243
4244 def test_dot(self):
4245 # Tests dot on MaskedArrays.

Callers

nothing calls this directly

Calls 8

_create_dataMethod · 0.95
assert_equalFunction · 0.90
assert_almost_equalFunction · 0.90
sumFunction · 0.90
traceMethod · 0.80
reshapeMethod · 0.80
sumMethod · 0.45
compressedMethod · 0.45

Tested by

no test coverage detected