Hi Tyler,
On 18 Apr, 2013, at 09:51, Tyler Reddy wrote:
> Hi,
>
> After discussing this with a colleague, I was a bit surprised to find that skipping frames in a trajectory using [::skip_value] notation preforms worse than an explicit modulus test, as my understanding was that we (Oli, I think) implemented this functionality as a modulus test for the skip_value under the hood (I'm pretty sure I remember when this was patched about 3 years ago).
I think that the code below pretty much does that:
In coordinates.xdrfile.core.TrjReader.__getitem__():
def iterDCD(start=frame.start, stop=frame.stop, step=frame.step):
start, stop, step = self._check_slice_indices(start, stop, step)
if step < 0:
raise NotImplementedError("XTC/TRR do not support reverse iterating for performance reasons")
for ts in self:
# simple sequential plodding through trajectory --- SLOW!
frameindex = ts.frame - 1
if frameindex < start: continue
if frameindex >= stop: break
if (frameindex - start) % step != 0: continue
yield self.ts
> My test code and the results (similar over 10 replicates and on two different machines) are below. A quick look at the source code (iterDCD() function in MDAnalysis/coordinates/xdrfile/core.py) suggests that there's a bit more than a simple modulus check there--I do see the modulus check, but there's also self._check_slice_indices(start, stop, step) in iterDCD(),
The _check_slice_indices() is not expensive and in any case, once we're in the 'for ts in self' loop (i.e. __iter__()), we only do the if statements and iterate through the frames sequentially.
I don't understand where a factor of 2 in execution time comes from. Did you try running it through a profiler (line_profiler or cProfile)?
> and maybe I'll have to look at this in more detail, but I can't imagine that the baked-in 'frame skipping' should be slower than performing an external modulus if done right.
It should take pretty much the same amount of time if done as a skipping forward.
If you can shed some light on this I would be really curious as to what's going on.
By the way, you might be interested in following the discussion on Issue 127: (
https://groups.google.com/forum/#!msg/mdnalysis-devel/szaMMcvY3Ik/i90t5l2Mth0J ).
Oliver
--
Oliver Beckstein *
orbe...@gmx.net
skype: orbeckst *
orbe...@gmail.com