| 47 | } |
| 48 | |
| 49 | void train(const QList<TemplateList> &data) |
| 50 | { |
| 51 | if (!trainable) return; |
| 52 | |
| 53 | QList<TemplateList> dataLines(data); |
| 54 | |
| 55 | int i = 0; |
| 56 | while (i < transforms.size()) { |
| 57 | // Conditional statement covers likely case that first transform is untrainable |
| 58 | if (transforms[i]->trainable) { |
| 59 | qDebug() << "Training" << transforms[i]->description() << "\n..."; |
| 60 | transforms[i]->train(dataLines); |
| 61 | } |
| 62 | |
| 63 | // if the transform is time varying, we can't project it in parallel |
| 64 | if (transforms[i]->timeVarying()) { |
| 65 | qDebug() << "Projecting" << transforms[i]->description() << "\n..."; |
| 66 | for (int j=0; j < dataLines.size();j++) { |
| 67 | TemplateList junk; |
| 68 | splitFTEs(dataLines[j], junk); |
| 69 | |
| 70 | transforms[i]->projectUpdate(dataLines[j], dataLines[j]); |
| 71 | } |
| 72 | |
| 73 | // advance i since we already projected for this stage. |
| 74 | i++; |
| 75 | |
| 76 | // the next stage might be trainable, so continue to evaluate it. |
| 77 | continue; |
| 78 | } |
| 79 | |
| 80 | // We project through any subsequent untrainable transforms at once |
| 81 | // as a memory optimization in case any of these intermediate |
| 82 | // transforms allocate a lot of memory (like OpenTransform) |
| 83 | // then we don't want all the training templates to be processed |
| 84 | // by that transform at once if we can avoid it. |
| 85 | int nextTrainableTransform = i+1; |
| 86 | while ((nextTrainableTransform < transforms.size()) && |
| 87 | !transforms[nextTrainableTransform]->trainable && |
| 88 | !transforms[nextTrainableTransform]->timeVarying()) |
| 89 | nextTrainableTransform++; |
| 90 | |
| 91 | // No more trainable transforms? Don't need any more projects then |
| 92 | if (nextTrainableTransform == transforms.size()) |
| 93 | break; |
| 94 | |
| 95 | fprintf(stderr, "Projecting %s", qPrintable(transforms[i]->description())); |
| 96 | for (int j=i+1; j < nextTrainableTransform; j++) |
| 97 | fprintf(stderr,"+%s", qPrintable(transforms[j]->description())); |
| 98 | fprintf(stderr, "\n...\n"); |
| 99 | fflush(stderr); |
| 100 | |
| 101 | QFutureSynchronizer<void> futures; |
| 102 | for (int j=0; j < dataLines.size(); j++) |
| 103 | futures.addFuture(QtConcurrent::run(this, &PipeTransform::_projectPartial, &dataLines[j], i, nextTrainableTransform)); |
| 104 | futures.waitForFinished(); |
| 105 | |
| 106 | i = nextTrainableTransform; |
nothing calls this directly
no test coverage detected