changeset 116:91bb029a847a timing

Reorder the calculations to match the series of vector operations in the most recent bqvec code, just in case it's the order of vector calculations that is saving the time rather than the avoidance of std::vector
author Chris Cannam
date Wed, 07 May 2014 09:57:19 +0100
parents a6e136aaa202
children
files src/EM.cpp
diffstat 1 files changed, 21 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/EM.cpp	Tue May 06 12:56:18 2014 +0100
+++ b/src/EM.cpp	Wed May 07 09:57:19 2014 +0100
@@ -164,6 +164,8 @@
     Grid newShifts(m_shiftCount, V(m_noteCount, epsilon));
     Grid newSources(m_instrumentCount, V(m_noteCount, epsilon));
 
+    V contributions(m_binCount);
+
     for (int n = 0; n < m_noteCount; ++n) {
 
         const double pitch = m_pitches[n];
@@ -178,22 +180,31 @@
                 const double factor = pitch * source * shift;
                 const double *w = templateFor(i, n, f);
 
+                for (int j = 0; j < m_binCount; ++j) {
+                    contributions[j] = w[j];
+                }
+                for (int j = 0; j < m_binCount; ++j) {
+                    contributions[j] *= m_q.at(j);
+                }
+                for (int j = 0; j < m_binCount; ++j) {
+                    contributions[j] *= factor;
+                }
+
+                double total = 0.0;
+                for (int j = 0; j < m_binCount; ++j) {
+                    total += contributions.at(j);
+                }
+
                 if (n >= m_lowestPitch && n <= m_highestPitch) {
 
-                    for (int j = 0; j < m_binCount; ++j) {
-                        newPitches[n] += w[j] * m_q[j] * factor;
-                    }
-
+                    newPitches[n] += total;
+                    
                     if (inRange(i, n)) {
-                        for (int j = 0; j < m_binCount; ++j) {
-                            newSources[i][n] += w[j] * m_q[j] * factor;
-                        }
+                        newSources[i][n] += total;
                     }
                 }
 
-                for (int j = 0; j < m_binCount; ++j) {
-                    newShifts[f][n] += w[j] * m_q[j] * factor;
-                }
+                newShifts[f][n] += total;
             }
         }
     }