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