
Hi,
Whilst looking into performance of various DIALS routines recently, I noticed that the flex.int.as_double() conversion takes roughly 3x as long as the equivalent functionality in numpy:
(the choice of a 2527x2463 array is simply because this is the size of the raw data array for a Pilatus 6M detector)
import time
from dials.array_family import flex
n = 100
a = flex.int(flex.grid(2527, 2463))
t0 = time.time()
for i in range(n):
b = a.as_double()
t1 = time.time()
t = t1-t0
print "flex.int.as_double(): %.2fs (%.3fs/call)" %(t, t/n)
import numpy as np
a = np.random.randint(100, size=a.all())
t0 = time.time()
for i in range(n):
b = a.astype(np.float64)
t1 = time.time()
t = t1-t0
print "numpy.astype(np.float64): %.2fs (%.3fs/call)" %(t, t/n)
$ libtbx.python time_as_double.py
flex.int.as_double(): 5.76s (0.058s/call)
numpy.astype(np.float64): 1.86s (0.019s/call)
This is the current version of the as_double function:
static flex_double
as_double(f_t const& a)
{
shared_plain<double> result(a.size(), init_functor_null<double>());
for(std::size_t i=0;i