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

Method testNorm

tools/swig/test/testSuperTensor.py:24–32  ·  view source on GitHub ↗

Test norm function

(self)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected