MCPcopy Create free account
hub / github.com/boostorg/histogram / test_numpy_conversion_0

Method test_numpy_conversion_0

test/python_suite_test.py:753–777  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

751
752 @unittest.skipUnless(HAVE_NUMPY, "requires build with numpy-support")
753 def test_numpy_conversion_0(self):
754 a = histogram(integer(0, 3, uoflow=False))
755 a(0)
756 for i in range(5):
757 a(1)
758 c = numpy.array(a) # a copy
759 v = numpy.asarray(a) # a view
760
761 for t in (c, v):
762 self.assertEqual(t.dtype, numpy.uint8)
763 self.assertTrue(numpy.all(t == numpy.array((1, 5, 0))))
764
765 for i in range(10):
766 a(2)
767 # copy does not change, but view does
768 self.assertTrue(numpy.all(c == numpy.array((1, 5, 0))))
769 self.assertTrue(numpy.all(v == numpy.array((1, 5, 10))))
770
771 for i in range(255):
772 a(1)
773 c = numpy.array(a)
774 self.assertEqual(c.dtype, numpy.uint16)
775 self.assertTrue(numpy.all(c == numpy.array((1, 260, 10))))
776 # view does not follow underlying switch in word size
777 self.assertFalse(numpy.all(c == v))
778
779 @unittest.skipUnless(HAVE_NUMPY, "requires build with numpy-support")
780 def test_numpy_conversion_1(self):

Callers

nothing calls this directly

Calls 2

integerClass · 0.90
histogramClass · 0.50

Tested by

no test coverage detected