# HG changeset patch # User Chris Cannam # Date 1399384629 -3600 # Node ID 8259193b3b169fc88e66e5245bf529a180436ca9 # Parent 9ecad4c9c2a2658bc735b48c729526cc7fb02f0e Cut allocations with temporary storage ready to swap in diff -r 9ecad4c9c2a2 -r 8259193b3b16 src/EM.cpp --- a/src/EM.cpp Tue May 06 14:53:11 2014 +0100 +++ b/src/EM.cpp Tue May 06 14:57:09 2014 +0100 @@ -44,11 +44,13 @@ m_highestPitch(silvet_templates_highest_note) { m_pitches = allocate(m_noteCount); + m_updatePitches = allocate(m_noteCount); for (int n = 0; n < m_noteCount; ++n) { m_pitches[n] = drand48(); } m_shifts = allocate_channels(m_shiftCount, m_noteCount); + m_updateShifts = allocate_channels(m_shiftCount, m_noteCount); for (int f = 0; f < m_shiftCount; ++f) { for (int n = 0; n < m_noteCount; ++n) { m_shifts[f][n] = drand48(); @@ -56,6 +58,7 @@ } m_sources = allocate_channels(m_sourceCount, m_noteCount); + m_updateSources = allocate_channels(m_sourceCount, m_noteCount); for (int i = 0; i < m_sourceCount; ++i) { for (int n = 0; n < m_noteCount; ++n) { m_sources[i][n] = (inRange(i, n) ? 1.0 : 0.0); @@ -71,8 +74,11 @@ deallocate(m_q); deallocate(m_estimate); deallocate_channels(m_sources, m_sourceCount); + deallocate_channels(m_updateSources, m_sourceCount); deallocate_channels(m_shifts, m_shiftCount); + deallocate_channels(m_updateShifts, m_shiftCount); deallocate(m_pitches); + deallocate(m_updatePitches); } void @@ -160,17 +166,12 @@ void EM::maximisation(const double *column) { - double *newPitches = allocate(m_noteCount); - v_set(newPitches, epsilon, m_noteCount); - - double **newShifts = allocate_channels(m_shiftCount, m_noteCount); + v_set(m_updatePitches, epsilon, m_noteCount); for (int i = 0; i < m_shiftCount; ++i) { - v_set(newShifts[i], epsilon, m_noteCount); + v_set(m_updateShifts[i], epsilon, m_noteCount); } - - double **newSources = allocate_channels(m_sourceCount, m_noteCount); for (int i = 0; i < m_sourceCount; ++i) { - v_set(newSources[i], epsilon, m_noteCount); + v_set(m_updateSources[i], epsilon, m_noteCount); } double *contributions = allocate(m_binCount); @@ -197,40 +198,36 @@ if (n >= m_lowestPitch && n <= m_highestPitch) { - newPitches[n] += total; + m_updatePitches[n] += total; if (inRange(i, n)) { - newSources[i][n] += total; + m_updateSources[i][n] += total; } } - newShifts[f][n] += total; + m_updateShifts[f][n] += total; } } } for (int n = 0; n < m_noteCount; ++n) { if (m_pitchSparsity != 1.0) { - newPitches[n] = pow(newPitches[n], m_pitchSparsity); + m_updatePitches[n] = pow(m_updatePitches[n], m_pitchSparsity); } if (m_sourceSparsity != 1.0) { for (int i = 0; i < m_sourceCount; ++i) { - newSources[i][n] = pow(newSources[i][n], m_sourceSparsity); + m_updateSources[i][n] = pow(m_updateSources[i][n], m_sourceSparsity); } } } - normaliseColumn(newPitches, m_noteCount); - normaliseGrid(newShifts, m_shiftCount, m_noteCount); - normaliseGrid(newSources, m_sourceCount, m_noteCount); + normaliseColumn(m_updatePitches, m_noteCount); + normaliseGrid(m_updateShifts, m_shiftCount, m_noteCount); + normaliseGrid(m_updateSources, m_sourceCount, m_noteCount); - deallocate(m_pitches); - deallocate_channels(m_shifts, m_shiftCount); - deallocate_channels(m_sources, m_sourceCount); - - m_pitches = newPitches; - m_shifts = newShifts; - m_sources = newSources; + std::swap(m_pitches, m_updatePitches); + std::swap(m_shifts, m_updateShifts); + std::swap(m_sources, m_updateSources); } diff -r 9ecad4c9c2a2 -r 8259193b3b16 src/EM.h --- a/src/EM.h Tue May 06 14:53:11 2014 +0100 +++ b/src/EM.h Tue May 06 14:57:09 2014 +0100 @@ -45,6 +45,10 @@ double **m_shifts; double **m_sources; + double *m_updatePitches; + double **m_updateShifts; + double **m_updateSources; + double *m_estimate; double *m_q;