(Dl4j) performance improvments (#9078)

* Removed invoking the boolean constructor

Signed-off-by: Dariusz Zbyrad <dariusz.zbyrad@gmail.com>

* Use bulk operations instead of iteration

Signed-off-by: Dariusz Zbyrad <dariusz.zbyrad@gmail.com>

* Removed manuall array copy

Signed-off-by: Dariusz Zbyrad <dariusz.zbyrad@gmail.com>
master
dariuszzbyrad 2020-09-01 13:16:08 +02:00 committed by GitHub
parent 1de8837c39
commit 73b08c7254
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 10 additions and 24 deletions

View File

@ -205,9 +205,7 @@ public class KerasTokenizer {
ArrayList<String> sortedVocabulary = new ArrayList<>();
if (outOfVocabularyToken != null)
sortedVocabulary.add(outOfVocabularyToken);
for (String word: sortedWordCounts.keySet()) {
sortedVocabulary.add(word);
}
sortedVocabulary.addAll(sortedWordCounts.keySet());
for (int i = 0; i < sortedVocabulary.size(); i++)
wordIndex.put(sortedVocabulary.get(i), i+1);

View File

@ -96,9 +96,7 @@ public class ReshapePreprocessor extends BaseInputPreProcessor {
int shapeLength = shape.length;
val miniBatchShape = new long[shapeLength + 1];
miniBatchShape[0] = miniBatchSize;
for (int i = 1; i < miniBatchShape.length; i++) {
miniBatchShape[i] = shape[i - 1];
}
System.arraycopy(shape, 0, miniBatchShape, 1, miniBatchShape.length - 1);
return miniBatchShape;
}

View File

@ -67,9 +67,7 @@ public class BookRecognition implements Recognition {
}
if (mergeList != null) {
for (Term term : list) {
list.add(term);
}
list.addAll(list);
}
result.setTerms(list);

View File

@ -48,9 +48,7 @@ public class StopRecognition implements Recognition {
* @return
*/
public StopRecognition insertStopWords(String... stopWords) {
for (String words : stopWords) {
stop.add(words);
}
stop.addAll(Arrays.asList(stopWords));
return this;
}
@ -60,9 +58,7 @@ public class StopRecognition implements Recognition {
* @param stopWords
*/
public void insertStopNatures(String... stopNatures) {
for (String natureStr : stopNatures) {
natureStop.add(natureStr);
}
natureStop.addAll(Arrays.asList(stopNatures));
}
/**

View File

@ -345,9 +345,8 @@ public class VocabularyHolder implements Serializable {
if (word.getRetentionStep() < retentionDelay - 1) {
word.incrementRetentionStep();
} else {
for (int x = 1; x < retentionDelay; x++) {
word.getFrequencyShift()[x - 1] = word.getFrequencyShift()[x];
}
if (retentionDelay - 1 >= 0)
System.arraycopy(word.getFrequencyShift(), 1, word.getFrequencyShift(), 0, retentionDelay - 1);
}
}
logger.info("Scavenger was activated. Vocab size before: [" + initialSize + "], after: [" + vocabulary.size()

View File

@ -77,9 +77,7 @@ public class StackVertex extends BaseGraphVertex {
// create the new shape
outShape[0] = nStack * inShape[0];
for (int i = 1; i < inShape.length; i++) {
outShape[i] = inShape[i];
}
System.arraycopy(inShape, 1, outShape, 1, inShape.length - 1);
boolean variableLengthTS = false;
if (inShape.length == 3) {

View File

@ -838,8 +838,7 @@ public class VariationalAutoencoder implements Layer {
return;
}
for (TrainingListener listener : listeners)
trainingListeners.add(listener);
trainingListeners.addAll(Arrays.asList(listeners));
}
@Override

View File

@ -915,7 +915,7 @@ public class SharedTrainingMaster extends BaseTrainingMaster<SharedTrainingResul
protected int numWorkersPerNode = -1;
protected int workerPrefetchNumBatches = 2;
protected Repartitioner repartitioner = new DefaultRepartitioner();
protected Boolean workerTogglePeriodicGC = new Boolean(true);
protected Boolean workerTogglePeriodicGC = Boolean.TRUE;
protected Integer workerPeriodicGCFrequency = new Integer(5000);
protected boolean encodingDebugMode = false;