Back to the main page.

Bug 1916 - scalingfactor needs to be made faster

Status CLOSED FIXED
Reported 2012-12-31 10:43:00 +0100
Modified 2012-12-31 11:46:28 +0100
Product: FieldTrip
Component: core
Version: unspecified
Hardware: PC
Operating System: Mac OS
Importance: P3 normal
Assigned to: Robert Oostenveld
URL:
Tags:
Depends on:
Blocks: 953
See also:

Robert Oostenveld - 2012-12-31 10:43:31 +0100

from http://bugzilla.fcdonders.nl/show_bug.cgi?id=953#c12 I tried to integrate unit scaling in spm_eeg_convert. The current implementation is very slow. Line 1098 in ft_read_data takes 18 seconds to run on my Neuromag data example and it runs at every iteration of the data reading loop.


Robert Oostenveld - 2012-12-31 10:49:15 +0100

there is already this code persistent previous_old previous_new previous_factor if isequal(old, previous_old) && isequal(new, previous_new) factor = previous_factor; return end which works fine like this old = 'mT/mm'; new = 'fT/km'; stopwatch = tic; factor = scalingfactor(old, new); toc(stopwatch) n = 300; old = repmat({old}, 1, n); new = repmat({new}, 1, n); stopwatch = tic; factor = cellfun(@scalingfactor, old, new); toc(stopwatch) but fails if the input is alternating like A-A-B-A-A-B-A-A-B which is probably the case with the neuromag channel order.


Robert Oostenveld - 2012-12-31 10:51:42 +0100

yes, with identical inputs and 300 conversions it is ~0.2 seconds and with n = 100; old = repmat({'T/cm' 'T/cm' 'T'}, 1, n); new = repmat({'fT/m' 'fT/m' 'fT'}, 1, n); stopwatch = tic; factor = cellfun(@scalingfactor, old, new); toc(stopwatch) Elapsed time is 26.228476 seconds. Ok, I will change it such that a list of previous conversion factors is maintained, not only the latest.


Robert Oostenveld - 2012-12-31 11:05:31 +0100

I made the change as suggested and wrote a test script with three cases >> clear scalingfactor >> test_bug1916 Elapsed time is 0.145215 seconds. % one new conversion Elapsed time is 0.013033 seconds. % the same conversion repeated 300 times Elapsed time is 0.279860 seconds. % two new conversions, repeated 300 times >> test_bug1916 Elapsed time is 0.000170 seconds. Elapsed time is 0.013332 seconds. Elapsed time is 0.012126 seconds. The first instance of any conversion takes 150ms, after that it is very fast with about 12ms for 300 conversions. mbp> svn commit test/test_bug1916.m private/scalingfactor.m Sending private/scalingfactor.m Adding test/test_bug1916.m Transmitting file data .. Committed revision 7271.


Robert Oostenveld - 2012-12-31 11:46:28 +0100

closed several bugs that have been resolved for some time. Feel free to reopen the bug if you disagree.