templates.py 994 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env python
  2. # Copyright Jim Bosch & Ankit Daftery 2010-2012.
  3. # Distributed under the Boost Software License, Version 1.0.
  4. # (See accompanying file LICENSE_1_0.txt or copy at
  5. # http://www.boost.org/LICENSE_1_0.txt)
  6. import templates_ext
  7. import unittest
  8. import numpy
  9. class TestTemplates(unittest.TestCase):
  10. def testTemplates(self):
  11. for dtype in (numpy.int16, numpy.int32, numpy.float32, numpy.complex128):
  12. v = numpy.arange(12, dtype=dtype)
  13. for shape in ((12,), (4, 3), (2, 6)):
  14. a1 = numpy.zeros(shape, dtype=dtype)
  15. a2 = v.reshape(a1.shape)
  16. templates_ext.fill(a1)
  17. self.assert_((a1 == a2).all())
  18. a1 = numpy.zeros((12,), dtype=numpy.float64)
  19. self.assertRaises(TypeError, templates_ext.fill, a1)
  20. a1 = numpy.zeros((12,2,3), dtype=numpy.float32)
  21. self.assertRaises(TypeError, templates_ext.fill, a1)
  22. if __name__=="__main__":
  23. unittest.main()