Example #1
0
def _1d_histogram_tester(binlowhighs, x, weights=1):
    h = Histogram(binlowhighs)
    h.fill(x, weights=weights)
    if np.isscalar(weights):
        ynp = np.histogram(x, h.edges[0])[0]
    else:
        ynp = np.histogram(x, h.edges[0], weights=weights)[0]
    assert_array_almost_equal(ynp, h.values)
    h.reset()
    h._always_use_fillnd = True
    h.fill(x, weights=weights)
    assert_array_almost_equal(ynp, h.values)
Example #2
0
import itertools
if __name__ == '__main__':
    x = [1000, 0, 10.01]
    y = [1000, 0, 9.01]
    xf = np.random.random(1000000)*10*4
    yf = np.random.random(1000000)*9*15
    xi = xf.astype(int)
    yi = yf.astype(int)
    wf = np.linspace(1, 10, len(xf))
    wi = wf.copy()
    times = []
    print("Testing 2D histogram timings")
    for xvals, yvals, weights in itertools.product([xf, xi], [yf, yi], [wf, wi]):
        t0 = time()
        h = Histogram(x, y)
        h.fill(xvals, yvals, weights=weights)
        skxray_time = time() - t0

        edges = h.edges
        t0 = time()
        ynp = np.histogram2d(xvals, yvals, bins=edges, weights=weights)[0]
        numpy_time = time() - t0
        times.append(numpy_time / skxray_time)
        assert_almost_equal(np.sum(h.values), np.sum(ynp))
    print('skxray is %s times faster than numpy, on average' % np.average(times))
    #
    # test_1d_histogram()
    # test_2d_histogram()

#TODO do a better job sampling the variable space
Example #3
0
import timeit
import time
import numpy as np
from skxray.core.accumulators.histogram import Histogram

h = Histogram((10, 0, 10.1), (7, 0, 7.1));
x = np.random.random(1000000)*40
y = np.random.random(1000000)*10
w = np.ones_like(x)
xi = x.astype(int)
xi = xi.astype(float)
wi = np.ones_like(xi)
gg = globals()

def timethis(stmt):
    return np.mean(timeit.repeat(stmt, number=10, repeat=5, globals=gg))

def histfromzero(h, fncname, x, w):
    h.data[:] = 0
    getattr(h, fncname)(x, w)
    return h.data.copy()


print("Timing h.fill",
        timethis('h.fill(x, y, weights=w)'))

h._always_use_fillnd = True
print("Timing h.fill with _always_use_fillnd",
        timethis('h.fill(x, y, weights=w)'))