changeset 203:3662865740da memory

Make isRowAvailable/isColAvailable operate on first matcher only
author Chris Cannam
date Fri, 27 Feb 2015 12:09:43 +0000
parents b5deca82e074
children 006fd4cb95b3
files src/Matcher.cpp src/Matcher.h
diffstat 2 files changed, 54 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/src/Matcher.cpp	Fri Feb 27 11:38:04 2015 +0000
+++ b/src/Matcher.cpp	Fri Feb 27 12:09:43 2015 +0000
@@ -77,23 +77,51 @@
 }
 
 bool
-Matcher::isRowAvailable(int i)
+Matcher::isAvailable(int i, int j)
 {
-    if (i < 0 || i >= int(m_first.size())) return false;
-
-    for (int j = m_first[i]; j < int(m_first[i] + m_bestPathCost[i].size()); ++j) {
-        if (isAvailable(i, j)) {
-            return true;
+    if (m_firstPM) {
+        if (isInRange(i, j)) {
+            return (m_bestPathCost[i][j - m_first[i]] != InvalidPathCost);
+        } else {
+            return false;
         }
+    } else {
+        return m_otherMatcher->isAvailable(j, i);
     }
-
-    return false;
 }
 
 bool
-Matcher::isColAvailable(int i)
+Matcher::isRowAvailable(int i)
 {
-    return m_otherMatcher->isRowAvailable(i);
+    if (m_firstPM) {
+
+        if (i < 0 || i >= int(m_first.size())) return false;
+        for (auto c: m_bestPathCost[i]) {
+            if (c != InvalidPathCost) return true;
+        }
+        return false;
+
+    } else {
+        return m_otherMatcher->isColAvailable(i);
+    }
+}
+
+bool
+Matcher::isColAvailable(int j)
+{
+    if (m_firstPM) {
+        for (int i = 0; i < int(m_first.size()); ++i) {
+            if (j >= m_first[i] &&
+                j < int(m_first[i] + m_bestPathCost[i].size())) {//!!! m_last[i]?
+                if (m_bestPathCost[i][j - m_first[i]] != InvalidPathCost) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    } else {
+        return m_otherMatcher->isRowAvailable(j);
+    }
 }
 
 bool
@@ -109,20 +137,6 @@
     }
 }
 
-bool
-Matcher::isAvailable(int i, int j)
-{
-    if (m_firstPM) {
-        if (isInRange(i, j)) {
-            return (m_bestPathCost[i][j - m_first[i]] >= 0);
-        } else {
-            return false;
-        }
-    } else {
-        return m_otherMatcher->isAvailable(j, i);
-    }
-}
-
 pair<int, int>
 Matcher::getColRange(int i)
 {
@@ -191,6 +205,7 @@
 Matcher::getPathCost(int i, int j)
 {
     if (m_firstPM) {
+#ifdef PERFORM_ERROR_CHECKS
         if (!isAvailable(i, j)) {
             if (!isInRange(i, j)) {
                 cerr << "ERROR: Matcher::getPathCost(" << i << ", " << j << "): "
@@ -203,6 +218,7 @@
             }
             throw "Path cost not available";
         }
+#endif
         return m_bestPathCost[i][j - m_first[i]];
     } else {
         return m_otherMatcher->getPathCost(j, i);
@@ -493,7 +509,7 @@
         cerr << "- have no cells in matrix" << endl;
     } else {
         cerr << "- have " << m_distance.size() << " cols in matrix with avg "
-             << double(cells) / m_distance.size() << " rows, total "
+             << double(cells) / double(m_distance.size()) << " rows, total "
              << cells << " cells" << endl;
         cerr << "- path costs " << k(cells * sizeof(pathcost_t))
              << "K, distances " << k(cells * sizeof(distance_t))
--- a/src/Matcher.h	Fri Feb 27 11:38:04 2015 +0000
+++ b/src/Matcher.h	Fri Feb 27 12:09:43 2015 +0000
@@ -157,6 +157,19 @@
      *  @return true if the location is in range
      */
     bool isInRange(int i, int j);
+    
+    /** Tests whether a location is available in the minimum cost
+     *  matrix, that is, whether it is in range and contains a valid
+     *  cost value.  Note this and its associated isRowAvailable,
+     *  isColAvailable checks are more expensive than isInRange and
+     *  are really intended for error checking. (If a row is in range,
+     *  it should always be available.)
+     *
+     *  @param i the frame number of this Matcher
+     *  @param j the frame number of the other Matcher
+     *  @return true if the location is in range and contains a valid cost
+     */
+    bool isAvailable(int i, int j);
 
     /** Tests whether any locations in the given row are available.
      */
@@ -165,14 +178,6 @@
     /** Tests whether any locations in the given column are available.
      */
     bool isColAvailable(int i);
-    
-    /** Tests whether a location is available in the minimum cost matrix.
-     *
-     *  @param i the frame number of this Matcher
-     *  @param j the frame number of the other Matcher
-     *  @return true if the location is in range and contains a valid cost
-     */
-    bool isAvailable(int i, int j);
 
     /** Returns the valid range of columns for the given row, that is,
      *  the range of frames in the other Matcher for the given frame