def test_histogram2d(self): # in this special case, cf.histogram2d and np.histogram2d must yield equal results # check hist and edges cfh, cfex, cfey = cf.histogram2d(self.datax, self.datay, bins=(20,30), range=((0,1), (0,2)), shape=0) nph, npex, npey = np.histogram2d(self.datax, self.datay, bins=(20, 30), range=((0,1), (0,2))) totalmass = len(self.datax) self.assertAlmostEqual(np.sum(cfh.base) - totalmass, 0) self.assertAlmostEqual(np.sum(nph) - totalmass, 0) self.assertListEqual(list(npex), list(cfex)) self.assertListEqual(list(npey), list(cfey))
def time2D(datax, datay, bins, weights, shape, tn): t = timeit.Timer(lambda: cf.histogram2d(datax, datay, range=((0.01, 0.99), (0.01, 0.99)), bins=bins, weights=weights, shape=shape)) tc = t.timeit(number=3) / 3.0 ws = ' ' if weights is None else 'weights' print('2D, {:d} shape, {:s}: {:0.2e} sec -> factor {:5.2f} faster'. format(shape, ws, tc, tn / tc))
def test_histogram2do2(self): # in this special case, cf.histogram2d and np.histogram2d must yield equal results # check hist and edges cfh, cfex, cfey = cf.histogram2d(self.datax, self.datay, bins=(20, 30), range=((0, 1), (0, 2)), shape=2) nph, npex, npey = np.histogram2d(self.datax, self.datay, bins=(20, 30), range=((0, 1), (0, 2))) totalmass = len(self.datax) self.assertAlmostEqual(np.sum(cfh.base) - totalmass, 0) self.assertAlmostEqual(np.sum(nph) - totalmass, 0) self.assertListEqual(list(npex), list(cfex)) self.assertListEqual(list(npey), list(cfey))
def time2D(datax, datay, bins, weights, shape, tn): t = timeit.Timer(lambda: cf.histogram2d(datax, datay, range=((0.01,0.99),(0.01,0.99)), bins=bins, weights=weights, shape=shape)) tc = t.timeit(number=3)/3.0 ws = ' ' if weights is None else 'weights' print('2D, {:d} shape, {:s}: {:0.2e} sec -> factor {:5.2f} faster'.format(shape, ws, tc, tn/tc))