Commit d3815649dd58dd49ebba00d5d0aa0972b3be37f0

Authored by Josh Klontz
1 parent 134c356d

core cleanup

Showing 1 changed file with 11 additions and 16 deletions
sdk/core/core.cpp
@@ -42,7 +42,7 @@ struct AlgorithmCore @@ -42,7 +42,7 @@ struct AlgorithmCore
42 { 42 {
43 TemplateList data(TemplateList::fromInput(input)); 43 TemplateList data(TemplateList::fromInput(input));
44 44
45 - if (transform.isNull()) qFatal("AlgorithmCore::train null transform."); 45 + if (transform.isNull()) qFatal("Null transform.");
46 qDebug("%d training files", data.size()); 46 qDebug("%d training files", data.size());
47 47
48 QTime time; time.start(); 48 QTime time; time.start();
@@ -108,19 +108,20 @@ struct AlgorithmCore @@ -108,19 +108,20 @@ struct AlgorithmCore
108 FileList enroll(File input, File gallery = File()) 108 FileList enroll(File input, File gallery = File())
109 { 109 {
110 FileList fileList; 110 FileList fileList;
111 - try {  
112 if (gallery.isNull()) gallery = getMemoryGallery(input); 111 if (gallery.isNull()) gallery = getMemoryGallery(input);
113 112
114 QScopedPointer<Gallery> g(Gallery::make(gallery)); 113 QScopedPointer<Gallery> g(Gallery::make(gallery));
115 if (g.isNull()) return FileList(); 114 if (g.isNull()) return FileList();
116 - fileList = g->files(); 115 +
  116 + if (gallery.contains("read") || gallery.contains("cache"))
  117 + fileList = g->files();
117 if (!fileList.isEmpty() && gallery.contains("cache")) 118 if (!fileList.isEmpty() && gallery.contains("cache"))
118 - return fileList; // Already enrolled 119 + return fileList;
119 120
120 const TemplateList i(TemplateList::fromInput(input)); 121 const TemplateList i(TemplateList::fromInput(input));
121 if (i.isEmpty()) return fileList; // Nothing to enroll 122 if (i.isEmpty()) return fileList; // Nothing to enroll
122 123
123 - if (transform.isNull()) qFatal("AlgorithmCore::enroll null transform."); 124 + if (transform.isNull()) qFatal("Null transform.");
124 const int blocks = Globals->blocks(i.size()); 125 const int blocks = Globals->blocks(i.size());
125 Globals->currentStep = 0; 126 Globals->currentStep = 0;
126 Globals->totalSteps = i.size(); 127 Globals->totalSteps = i.size();
@@ -167,9 +168,7 @@ struct AlgorithmCore @@ -167,9 +168,7 @@ struct AlgorithmCore
167 fprintf(stderr, "\rSPEED=%.1e SIZE=%.4g FAILURES=%d/%d \n", 168 fprintf(stderr, "\rSPEED=%.1e SIZE=%.4g FAILURES=%d/%d \n",
168 speed, totalBytes/totalCount, failureCount, totalCount); 169 speed, totalBytes/totalCount, failureCount, totalCount);
169 Globals->totalSteps = 0; 170 Globals->totalSteps = 0;
170 - } catch (...) {  
171 - qFatal("Exception triggered during enrollment!");  
172 - } 171 +
173 return fileList; 172 return fileList;
174 } 173 }
175 174
@@ -187,7 +186,6 @@ struct AlgorithmCore @@ -187,7 +186,6 @@ struct AlgorithmCore
187 186
188 void compare(File targetGallery, File queryGallery, File output) 187 void compare(File targetGallery, File queryGallery, File output)
189 { 188 {
190 - try {  
191 if (output.exists() && output.getBool("cache")) return; 189 if (output.exists() && output.getBool("cache")) return;
192 if (queryGallery == ".") queryGallery = targetGallery; 190 if (queryGallery == ".") queryGallery = targetGallery;
193 191
@@ -198,7 +196,7 @@ struct AlgorithmCore @@ -198,7 +196,7 @@ struct AlgorithmCore
198 196
199 QScopedPointer<Output> o(Output::make(output, targetFiles, queryFiles)); 197 QScopedPointer<Output> o(Output::make(output, targetFiles, queryFiles));
200 198
201 - if (distance.isNull()) qFatal("AlgorithmCore::compare null distance."); 199 + if (distance.isNull()) qFatal("Null distance.");
202 Globals->currentStep = 0; 200 Globals->currentStep = 0;
203 Globals->totalSteps = double(targetFiles.size()) * double(queryFiles.size()); 201 Globals->totalSteps = double(targetFiles.size()) * double(queryFiles.size());
204 Globals->startTime.start(); 202 Globals->startTime.start();
@@ -226,9 +224,6 @@ struct AlgorithmCore @@ -226,9 +224,6 @@ struct AlgorithmCore
226 const float speed = 1000 * Globals->totalSteps / Globals->startTime.elapsed() / std::max(1, abs(Globals->parallelism)); 224 const float speed = 1000 * Globals->totalSteps / Globals->startTime.elapsed() / std::max(1, abs(Globals->parallelism));
227 if (!Globals->quiet && (Globals->totalSteps > 1)) fprintf(stderr, "\rSPEED=%.1e \n", speed); 225 if (!Globals->quiet && (Globals->totalSteps > 1)) fprintf(stderr, "\rSPEED=%.1e \n", speed);
228 Globals->totalSteps = 0; 226 Globals->totalSteps = 0;
229 - } catch (...) {  
230 - qFatal("Exception triggered during comparison!");  
231 - }  
232 } 227 }
233 228
234 private: 229 private:
@@ -257,7 +252,7 @@ private: @@ -257,7 +252,7 @@ private:
257 return init(Globals->abbreviations[description]); 252 return init(Globals->abbreviations[description]);
258 253
259 QStringList words = description.split(':'); 254 QStringList words = description.split(':');
260 - if (words.size() > 2) qFatal("AlgorithmCore::init invalid algorithm format."); 255 + if (words.size() > 2) qFatal("Invalid algorithm format.");
261 256
262 transform = QSharedPointer<Transform>(Transform::make(words[0], NULL)); 257 transform = QSharedPointer<Transform>(Transform::make(words[0], NULL));
263 if (words.size() > 1) distance = QSharedPointer<Distance>(Distance::make(words[1], NULL)); 258 if (words.size() > 1) distance = QSharedPointer<Distance>(Distance::make(words[1], NULL));
@@ -282,7 +277,7 @@ public: @@ -282,7 +277,7 @@ public:
282 277
283 static QSharedPointer<AlgorithmCore> getAlgorithm(const QString &algorithm) 278 static QSharedPointer<AlgorithmCore> getAlgorithm(const QString &algorithm)
284 { 279 {
285 - if (algorithm.isEmpty()) qFatal("AlgorithmManager::getAlgorithm no default algorithm set."); 280 + if (algorithm.isEmpty()) qFatal("No default algorithm set.");
286 281
287 if (!algorithms.contains(algorithm)) { 282 if (!algorithms.contains(algorithm)) {
288 algorithmsLock.lock(); 283 algorithmsLock.lock();
@@ -341,7 +336,7 @@ void br::Cat(const QStringList &amp;inputGalleries, const QString &amp;outputGallery) @@ -341,7 +336,7 @@ void br::Cat(const QStringList &amp;inputGalleries, const QString &amp;outputGallery)
341 qDebug("Concatenating %d galleries to %s", inputGalleries.size(), qPrintable(outputGallery)); 336 qDebug("Concatenating %d galleries to %s", inputGalleries.size(), qPrintable(outputGallery));
342 foreach (const QString &inputGallery, inputGalleries) 337 foreach (const QString &inputGallery, inputGalleries)
343 if (inputGallery == outputGallery) 338 if (inputGallery == outputGallery)
344 - qFatal("br::Cat outputGallery must not be in inputGalleries."); 339 + qFatal("outputGallery must not be in inputGalleries.");
345 QScopedPointer<Gallery> og(Gallery::make(outputGallery)); 340 QScopedPointer<Gallery> og(Gallery::make(outputGallery));
346 foreach (const QString &inputGallery, inputGalleries) { 341 foreach (const QString &inputGallery, inputGalleries) {
347 QScopedPointer<Gallery> ig(Gallery::make(inputGallery)); 342 QScopedPointer<Gallery> ig(Gallery::make(inputGallery));