|
46 | 46 | public class MIDIFeatureProcessor { |
47 | 47 | /* FIELDS ****************************************************************/ |
48 | 48 |
|
49 | | - private static Map<String, MIDIFeatureExtractor> name2feature = new HashMap<>(); |
| 49 | + private static Map<String, MIDIFeatureExtractor> name2feature = new ConcurrentHashMap<>(); |
50 | 50 |
|
51 | 51 | /** |
52 | 52 | * The window size in seconds used for dividing up the recordings to |
@@ -345,7 +345,7 @@ public void onCompletion(CountedCompleter<?> caller) { |
345 | 345 | double[][][] dependencies = new double[sequences.size()][ArrayUtils.nullToEmpty(featureExtractor.getDepenedencies()).length][]; |
346 | 346 | for (int j = 0; j < ArrayUtils.nullToEmpty(featureExtractor.getDepenedencies()).length; j++) { |
347 | 347 | String dependency = featureExtractor.getDepenedencies()[j]; |
348 | | - dependencies[i][j] = map.get(name2feature.get(dependency))[i]; |
| 348 | + dependencies[i][j] = map.get(dependency)[i]; |
349 | 349 | } |
350 | 350 | try { |
351 | 351 | results[i] = featureExtractor.extractFeature(sequences.get(i), |
@@ -399,17 +399,20 @@ public double[][][] getFeatures(Sequence[] windows, MeiSpecificStorage meiSpecif |
399 | 399 | } |
400 | 400 | ForkJoinPool pool = ForkJoinPool.commonPool(); |
401 | 401 | ConcurrentHashMap<String, double[][]> resultsMap = new ConcurrentHashMap<>(); |
402 | | - IntStream.range(0, featureExtractorsDefinitions.length) |
| 402 | + List<ForkJoinTask<Void>> forkJoinTasks = IntStream.range(0, |
| 403 | + featureExtractorsDefinitions.length) |
403 | 404 | .filter(i -> featuresToSaveMask[i]) |
404 | 405 | .mapToObj(i -> name2feature.get(featureExtractorsDefinitions[i].name)) |
405 | 406 | .map(featureDefinition -> pool.submit(new Worker(null, |
406 | 407 | Arrays.stream(windows).toList(), |
407 | 408 | representations, |
408 | 409 | resultsMap, |
409 | | - featureDefinition))).toList().forEach(voidForkJoinTask -> { |
| 410 | + featureDefinition))).toList(); |
| 411 | + forkJoinTasks.forEach(voidForkJoinTask -> { |
410 | 412 | try { |
411 | 413 | voidForkJoinTask.get(); |
412 | 414 | } catch (InterruptedException | ExecutionException e) { |
| 415 | + e.printStackTrace(); |
413 | 416 | throw new RuntimeException(e); |
414 | 417 | } |
415 | 418 | }); |
|
0 commit comments