Test norm function
(self)
| 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): |