MCPcopy
hub / github.com/numpy/numpy / testNorm

Method testNorm

tools/swig/test/testSuperTensor.py:25–34  ·  view source on GitHub ↗

Test norm function

(self)

Source from the content-addressed store, hash-verified

23
24 # Test (type IN_ARRAY3[ANY][ANY][ANY]) typemap
25 def testNorm(self):
26 "Test norm function"
27 print(self.typeStr, "... ", file=sys.stderr)
28 norm = SuperTensor.__dict__[self.typeStr + "Norm"]
29 supertensor = np.arange(2 * 2 * 2 * 2,
30 dtype=self.typeCode).reshape((2, 2, 2, 2))
31 # Note: cludge to get an answer of the same type as supertensor.
32 # Answer is simply sqrt(sum(supertensor*supertensor)/16)
33 answer = np.array([np.sqrt(np.sum(supertensor.astype('d') * supertensor) / 16.)], dtype=self.typeCode)[0] # noqa: E501
34 self.assertAlmostEqual(norm(supertensor), answer, 6)
35
36 # Test (type IN_ARRAY3[ANY][ANY][ANY]) typemap
37 def testNormBadList(self):

Callers

nothing calls this directly

Calls 4

normFunction · 0.85
reshapeMethod · 0.80
astypeMethod · 0.80
sumMethod · 0.45

Tested by

no test coverage detected