MCPcopy Create free account
hub / github.com/numpy/numpy / test_trace

Method test_trace

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

Source from the content-addressed store, hash-verified

3990 [[-0.5, 0.5, mval], [-1.0, mval, 1.0]])
3991
3992 def test_trace(self):
3993 # Tests trace on MaskedArrays.
3994 (x, X, XX, m, mx, mX, mXX, m2x, m2X, m2XX) = self.d
3995 mXdiag = mX.diagonal()
3996 assert_equal(mX.trace(), mX.diagonal().compressed().sum())
3997 assert_almost_equal(mX.trace(),
3998 X.trace() - sum(mXdiag.mask * X.diagonal(),
3999 axis=0))
4000 assert_equal(np.trace(mX), mX.trace())
4001
4002 # gh-5560
4003 arr = np.arange(2*4*4).reshape(2,4,4)
4004 m_arr = np.ma.masked_array(arr, False)
4005 assert_equal(arr.trace(axis1=1, axis2=2), m_arr.trace(axis1=1, axis2=2))
4006
4007 def test_dot(self):
4008 # Tests dot on MaskedArrays.

Callers

nothing calls this directly

Calls 7

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