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