Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply optimize stream refactoring #539

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/org/numenta/nupic/model/Connections.java
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,7 @@ public void removeSynapseFromPresynapticMap(Synapse synapse) {
* @return Synapse object on the segment with the minimal permanence
*/
private Synapse minPermanenceSynapse(DistalDendrite dd) {
List<Synapse> synapses = getSynapses(dd).stream().sorted().collect(Collectors.toList());
List<Synapse> synapses = getSynapses(dd).parallelStream().sorted().collect(Collectors.toList());
Synapse min = null;
double minPermanence = Double.MAX_VALUE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public static Stream<String> getJarEntryStream(String path) {
innerPath = innerPath.startsWith("!") ? innerPath.substring(1) : innerPath;
InputStream inStream = jar.getInputStream(jar.getEntry(innerPath));
BufferedReader br = new BufferedReader(new InputStreamReader(inStream));
retVal = br.lines().onClose(() -> {
retVal = br.lines().parallel().onClose(() -> {
try {
br.close();
jar.close();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/numenta/nupic/util/GroupBy2.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private void advanceSequences() {
* @return the next smallest generated key.
*/
private boolean nextMinKey() {
return Arrays.stream(nextList)
return Arrays.stream(nextList).parallel()
.filter(opt -> opt.isPresent())
.map(opt -> opt.get().getSecond())
.min((k, k2) -> k.compareTo(k2))
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/numenta/nupic/util/UniversalRandom.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public static void main(String[] args) {
int[] selectedIndices = new int[sampleSize];
List<Integer> collectedRandoms = new ArrayList<>();
int[] expectedSample = {1,2,3,7,8,9};
List<Integer> expectedRandoms = Arrays.stream(new int[] {0,0,0,5,3,3}).boxed().collect(Collectors.toList());
List<Integer> expectedRandoms = Arrays.stream(new int[] {0,0,0,5,3,3}).parallel().boxed().collect(Collectors.toList());
random.sampleWithPrintout(choices, selectedIndices, collectedRandoms);
System.out.println("samples are equal ? " + Arrays.equals(expectedSample, selectedIndices));
System.out.println("used randoms are equal ? " + collectedRandoms.equals(expectedRandoms));
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/numenta/nupic/QuickDayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public void input(Double value, int recordNum, int sequenceNum) {
ComputeCycle cc = temporalMemory.compute(memory, input, true);
lastPredicted = predictedColumns;
predictedColumns = getSDR(cc.predictiveCells()); //Get the predicted column indexes
int[] activeCellIndexes = Connections.asCellIndexes(cc.activeCells()).stream().mapToInt(i -> i).sorted().toArray(); //Get the active cells for classifier input
int[] activeCellIndexes = Connections.asCellIndexes(cc.activeCells()).parallelStream().mapToInt(i -> i).sorted().toArray(); //Get the active cells for classifier input
System.out.println("TemporalMemory Input = " + Arrays.toString(input));
System.out.println("TemporalMemory Prediction = " + Arrays.toString(predictedColumns));

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/numenta/nupic/RunLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public void networkStep(int[] sparseSPOutput, boolean learn) {
public Tuple tmStep(int[] sparseSPOutput, boolean learn, boolean isVerbose) {
// Input into the Temporal Memory
ComputeCycle cc = tm.compute(connections, sparseSPOutput, learn);
int[] activeCellIndices = cc.activeCells().stream().mapToInt(c -> c.getIndex()).sorted().toArray();
int[] activeCellIndices = cc.activeCells().parallelStream().mapToInt(c -> c.getIndex()).sorted().toArray();
int[] predColumnIndices = SDR.cellsAsColumnIndices(cc.predictiveCells(), connections.getCellsPerColumn());
int[] activeColumns = Arrays.stream(activeCellIndices)
.map(cell -> cell / connections.getCellsPerColumn())
Expand Down Expand Up @@ -478,7 +478,7 @@ public static Tuple testTemporalMemory(TemporalMemory tm, Connections conn, int[
}

public static void loadSPOutputFile() {
try (Stream<String> stream = Files.lines(Paths.get(MakeshiftLayer.readFile))) {
try (Stream<String> stream = Files.lines(Paths.get(MakeshiftLayer.readFile)).parallel()) {
MakeshiftLayer.input = stream.map(l -> {
String line = l.replace("[", "").replace("]", "").trim();
int[] result = Arrays.stream(line.split("[\\s]*\\,[\\s]*")).mapToInt(i -> Integer.parseInt(i)).toArray();
Expand All @@ -490,7 +490,7 @@ public static void loadSPOutputFile() {
}

public static void loadRawInputFile() {
try (Stream<String> stream = Files.lines(Paths.get(MakeshiftLayer.INPUT_PATH))) {
try (Stream<String> stream = Files.lines(Paths.get(MakeshiftLayer.INPUT_PATH)).parallel()) {
MakeshiftLayer.raw = stream.map(l -> l.trim()).collect(Collectors.toList());
}catch(Exception e) {e.printStackTrace();}
}
Expand Down