Sfoglia il codice sorgente

if LinAL is not used, choleskySolveMatrixLargeScale now also works for non-quadratic RHS

bodesheim 11 anni fa
parent
commit
ab86fb0c12
3 ha cambiato i file con 40 aggiunte e 4 eliminazioni
  1. 2 1
      core/basics/Config.cpp
  2. 23 2
      core/basics/StringTools.cpp
  3. 15 1
      core/vector/Algorithms.cpp

+ 2 - 1
core/basics/Config.cpp

@@ -232,6 +232,7 @@ void Config::restore (istream & is, int format)
         continue;
 
       line = StringTools::chomp ( line );
+      len = line.size();
 
   #if defined DEBUGCONFIG
       DEBUGPRINT ("Config: (%d) '%s' (len = %d) / %s\n", (int)count, line.c_str(), (int)len,
@@ -274,7 +275,7 @@ void Config::restore (istream & is, int format)
       while ( (line[p]!='=') && (p<len) ) p++;
       if ( (p >= len-1) || (p<=i) ) continue;
       key = line.substr( i, p-i );
-      value = line.substr( p+1, len-p );
+      value = line.substr( p+1 ); // with only one argument, substr copies from the specified position until the end of the string
 
       StringTools::normalize_string(value);
       StringTools::normalize_string(key);

+ 23 - 2
core/basics/StringTools.cpp

@@ -136,8 +136,29 @@ void StringTools::trimbounds ( std::string & value, char trimChar )
 /** @author Matti Bickel */
 std::string StringTools::trim(string s, const std::string& drop)
 {
-    std::string r=s.erase(s.find_last_not_of(drop)+1);
-    return r.erase(0,r.find_first_not_of(drop));
+    size_t findLastIndex = s.find_last_not_of(drop);
+    if ( findLastIndex < s.size() )
+    {
+      std::string r=s.erase(findLastIndex+1);
+      
+      size_t findFirstIndex = r.find_first_not_of(drop);
+      
+      if ( findFirstIndex > 0 )
+        return r.erase(0,findFirstIndex);
+      else
+        return r;
+      
+    } else
+    {
+      size_t findFirstIndex = s.find_first_not_of(drop);
+
+      if ( findFirstIndex > 0 )
+        return s.erase(0,findFirstIndex);
+      else
+        return s;
+      
+    }
+      
 }
 
 std::string StringTools::chomp(string s)

+ 15 - 1
core/vector/Algorithms.cpp

@@ -105,7 +105,21 @@ void choleskySolveMatrixLargeScale ( const Matrix & G, Matrix & B )
 	#warning "LinAl is not installed: choleskyInvertLargeScale will not be optimized."
   #define CHOLESKYLINAL_WARNING
   #endif
-	choleskyInvert ( G, B );
+  if (G.rows() != G.cols())
+    fthrow(Exception, "Matrix G is not quadratic !");
+  if ( G.rows() != B.rows() )
+    fthrow(Exception, "Matrices sizes do not fit together.");
+  if (B.rows() == B.cols())
+    choleskyInvert ( G, B );
+  else
+  {
+    Vector b(B.rows(),0.0);
+    for (size_t i=0;i<B.cols();i++)
+    {
+      choleskySolveLargeScale (G, B.getColumn(i), b);
+      B.getColumnRef(i) = b;
+    }
+  }
 #endif
 }