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

Method test_trace

numpy/_core/tests/test_multiarray.py:4006–4025  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

4004 assert_(sys.getrefcount(x) < 50)
4005
4006 def test_trace(self):
4007 a = np.arange(12).reshape((3, 4))
4008 assert_equal(a.trace(), 15)
4009 assert_equal(a.trace(0), 15)
4010 assert_equal(a.trace(1), 18)
4011 assert_equal(a.trace(-1), 13)
4012
4013 b = np.arange(8).reshape((2, 2, 2))
4014 assert_equal(b.trace(), [6, 8])
4015 assert_equal(b.trace(0), [6, 8])
4016 assert_equal(b.trace(1), [2, 3])
4017 assert_equal(b.trace(-1), [4, 5])
4018 assert_equal(b.trace(0, 0, 1), [6, 8])
4019 assert_equal(b.trace(0, 0, 2), [5, 9])
4020 assert_equal(b.trace(0, 1, 2), [3, 11])
4021 assert_equal(b.trace(offset=1, axis1=0, axis2=2), [1, 3])
4022
4023 out = np.array(1)
4024 ret = a.trace(out=out)
4025 assert ret is out
4026
4027 def test_trace_subclass(self):
4028 # The class would need to overwrite trace to ensure single-element

Callers

nothing calls this directly

Calls 3

assert_equalFunction · 0.90
reshapeMethod · 0.80
traceMethod · 0.80

Tested by

no test coverage detected