Mercurial > hg > orthanc-stone
comparison Framework/Toolbox/LinearAlgebra.cpp @ 790:9f68155c75b0
speeding up LinearAlgebra::ParseVector()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 28 May 2019 08:29:01 +0200 |
parents | 5aa728500586 |
children | 61ba4b504e9a |
comparison
equal
deleted
inserted
replaced
786:5aa728500586 | 790:9f68155c75b0 |
---|---|
24 #include <Core/Logging.h> | 24 #include <Core/Logging.h> |
25 #include <Core/OrthancException.h> | 25 #include <Core/OrthancException.h> |
26 #include <Core/Toolbox.h> | 26 #include <Core/Toolbox.h> |
27 | 27 |
28 #include <stdio.h> | 28 #include <stdio.h> |
29 #include <boost/lexical_cast.hpp> | |
30 #include <boost/numeric/ublas/lu.hpp> | 29 #include <boost/numeric/ublas/lu.hpp> |
31 | 30 |
32 namespace OrthancStone | 31 namespace OrthancStone |
33 { | 32 { |
34 namespace LinearAlgebra | 33 namespace LinearAlgebra |
69 | 68 |
70 for (size_t i = 0; i < items.size(); i++) | 69 for (size_t i = 0; i < items.size(); i++) |
71 { | 70 { |
72 try | 71 try |
73 { | 72 { |
74 target[i] = boost::lexical_cast<double>(items[i]); | 73 /** |
75 } | 74 * We don't use "boost::lexical_cast<>" here, as it is very |
76 catch (boost::bad_lexical_cast&) | 75 * slow. As we are parsing many doubles, we prefer to use |
76 * the standard "std::stod" function: | |
77 * http://www.cplusplus.com/reference/string/stod/ | |
78 **/ | |
79 | |
80 target[i] = std::stod(items[i]); | |
81 } | |
82 catch (std::exception&) | |
77 { | 83 { |
78 target.clear(); | 84 target.clear(); |
79 return false; | 85 return false; |
80 } | 86 } |
81 } | 87 } |