In [1]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

from npgamma import calc_gamma

In [2]:
grid = 0.02
scale_factor = 1.3

x = np.arange(-1.8, 1.8 + 0.001, grid)
y = np.arange(-1.5, 1.5 + 0.001, grid)
coords = (y, x)

xx, yy = np.meshgrid(x, y)

dose_ref = np.exp(-(xx**10 + yy**10))
dose_eval = dose_ref * scale_factor

On a 4 core computer using more threads improves calculation speed


In [3]:
%%timeit

calc_gamma(
    coords, dose_ref,
    coords, dose_eval,
    0.1, 0.03, lower_dose_cutoff=0.2, 
    maximum_test_distance=0.2, num_threads=1)


1 loop, best of 3: 1.11 s per loop

In [4]:
%%timeit

calc_gamma(
    coords, dose_ref,
    coords, dose_eval,
    0.1, 0.03, lower_dose_cutoff=0.2, 
    maximum_test_distance=0.2, num_threads=2)


1 loop, best of 3: 699 ms per loop

In [5]:
%%timeit

calc_gamma(
    coords, dose_ref,
    coords, dose_eval,
    0.1, 0.03, lower_dose_cutoff=0.2, 
    maximum_test_distance=0.2, num_threads=3)


1 loop, best of 3: 526 ms per loop

In [6]:
%%timeit

calc_gamma(
    coords, dose_ref,
    coords, dose_eval,
    0.1, 0.03, lower_dose_cutoff=0.2, 
    maximum_test_distance=0.2, num_threads=4)


1 loop, best of 3: 500 ms per loop

When more threads than is available is used the calculation time is longer


In [7]:
%%timeit

calc_gamma(
    coords, dose_ref,
    coords, dose_eval,
    0.1, 0.03, lower_dose_cutoff=0.2, 
    maximum_test_distance=0.2, num_threads=5)


1 loop, best of 3: 575 ms per loop

In [8]:
%%timeit

calc_gamma(
    coords, dose_ref,
    coords, dose_eval,
    0.1, 0.03, lower_dose_cutoff=0.2, 
    maximum_test_distance=0.2, num_threads=10)


1 loop, best of 3: 688 ms per loop