changeset 24:3973be829352

Keep the kernel dense for the moment, and use std::complex
author Chris Cannam <c.cannam@qmul.ac.uk>
date Mon, 04 Nov 2013 10:54:49 +0000
parents 4f2f28d5df58
children 5ca24ff67566
files cpp-qm-dsp/CQKernel.cpp cpp-qm-dsp/CQKernel.h
diffstat 2 files changed, 13 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/cpp-qm-dsp/CQKernel.cpp	Fri Nov 01 17:58:39 2013 +0000
+++ b/cpp-qm-dsp/CQKernel.cpp	Mon Nov 04 10:54:49 2013 +0000
@@ -11,6 +11,7 @@
 #include <iostream>
 
 using std::vector;
+using std::complex;
 using std::cerr;
 using std::endl;
 
@@ -107,44 +108,28 @@
 
 	    int firstNZ = -1, lastNZ = -1;
 
+	    vector<complex<double> > row;
+
 	    for (int j = 0; j < m_p.fftSize; ++j) {
-		if (sqrt(rout[j] * rout[j] + iout[j] * iout[j]) >= thresh) {
-		    lastNZ = j;
-		    if (firstNZ < 0) firstNZ = j;
+		if (sqrt(rout[j] * rout[j] + iout[j] * iout[j]) < thresh) {
+		    row.push_back(complex<double>(0, 0));
 		} else {
-		    rout[j] = iout[j] = 0;
+		    row.push_back(complex<double>(rout[j], iout[j]));
 		}
 	    }
 
-	    vector<double> rnz, inz;
-
-	    if (firstNZ >= 0) {
-		for (int j = firstNZ; j <= lastNZ; ++j) {
-		    rnz.push_back(rout[j] / m_p.fftSize);
-		    inz.push_back(iout[j] / m_p.fftSize);
-		}
-		m_kernel.offsets.push_back(firstNZ);
-	    } else {
-		m_kernel.offsets.push_back(0);
-	    }
-
-	    m_kernel.real.push_back(rnz);
-	    m_kernel.imag.push_back(inz);
+	    m_kernel.row.push_back(row);
 	}
     }
 
-    assert((int)m_kernel.offsets.size() == m_p.binsPerOctave * m_p.atomsPerFrame);
-    assert((int)m_kernel.real.size() == m_p.binsPerOctave * m_p.atomsPerFrame);
-    assert((int)m_kernel.imag.size() == m_p.binsPerOctave * m_p.atomsPerFrame);
+    assert((int)m_kernel.row.size() == m_p.binsPerOctave * m_p.atomsPerFrame);
 
     // print density as diagnostic
 
     int nnz = 0;
-    for (int i = 0; i < m_kernel.offsets.size(); ++i) {
-	assert(m_kernel.real[i].size() == m_kernel.imag[i].size());
-	for (int j = 0; j < m_kernel.real[i].size(); ++j) {
-	    if (m_kernel.real[i][j] != 0.0 ||
-		m_kernel.imag[i][j] != 0.0) {
+    for (int i = 0; i < m_kernel.row.size(); ++i) {
+	for (int j = 0; j < m_kernel.row[i].size(); ++j) {
+	    if (m_kernel.row[i][j] != complex<double>(0, 0)) {
 		++nnz;
 	    }
 	}
--- a/cpp-qm-dsp/CQKernel.h	Fri Nov 01 17:58:39 2013 +0000
+++ b/cpp-qm-dsp/CQKernel.h	Mon Nov 04 10:54:49 2013 +0000
@@ -3,6 +3,7 @@
 #define CQ_KERNEL_H
 
 #include <vector>
+#include <complex>
 
 class FFT;
 
@@ -32,9 +33,7 @@
     FFT *m_fft;
 
     struct KernelMatrix {
-	std::vector<int> offsets;
-	std::vector<std::vector<double> > real;
-	std::vector<std::vector<double> > imag;
+	std::vector<std::vector<std::complex<double> > > row;
     };
     KernelMatrix m_kernel;