-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9381 from IoannisPanagiotas/do-not-throw-histogra…
…m-hiccups Refactoring to allow histogram failure testing and a first solution
- Loading branch information
Showing
31 changed files
with
752 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
algo-common/src/main/java/org/neo4j/gds/result/CentralityRecordTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.gds.result; | ||
|
||
import org.HdrHistogram.DoubleHistogram; | ||
import org.neo4j.gds.core.utils.partition.Partition; | ||
|
||
import java.util.function.LongToDoubleFunction; | ||
import java.util.function.Supplier; | ||
|
||
class CentralityRecordTask implements Runnable { | ||
|
||
private final DoubleHistogram histogram; | ||
private final Partition partition; | ||
private final LongToDoubleFunction centralityFunction; | ||
|
||
CentralityRecordTask( | ||
Partition partition, | ||
LongToDoubleFunction centralityFunction, | ||
Supplier<DoubleHistogram> histogramSupplier | ||
) { | ||
this.partition = partition; | ||
this.centralityFunction = centralityFunction; | ||
this.histogram = histogramSupplier.get(); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
partition.consume(id -> { | ||
histogram.recordValue(centralityFunction.applyAsDouble(id)); | ||
}); | ||
} | ||
|
||
DoubleHistogram histogram() {return histogram;} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
algo-common/src/main/java/org/neo4j/gds/result/CommunityAddTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.gds.result; | ||
|
||
import com.carrotsearch.hppc.LongLongHashMap; | ||
import com.carrotsearch.hppc.LongLongMap; | ||
import com.carrotsearch.hppc.procedures.LongLongProcedure; | ||
import org.neo4j.gds.collections.hsa.HugeSparseLongArray; | ||
|
||
import java.util.function.LongUnaryOperator; | ||
|
||
class CommunityAddTask implements Runnable { | ||
|
||
private final HugeSparseLongArray.Builder builder; | ||
|
||
private final LongUnaryOperator communityFunction; | ||
|
||
private final long startId; | ||
private final long length; | ||
|
||
// Use local buffer to avoid contention on GrowingBuilder.add(). | ||
// This is especially useful, if the input has a skewed | ||
// distribution, i.e. most nodes end up in the same community. | ||
private final LongLongMap buffer; | ||
|
||
CommunityAddTask( | ||
HugeSparseLongArray.Builder builder, | ||
LongUnaryOperator communityFunction, | ||
long startId, | ||
long length | ||
) { | ||
this.builder = builder; | ||
this.communityFunction = communityFunction; | ||
this.startId = startId; | ||
this.length = length; | ||
// safe cast, since max batch size less than Integer.MAX_VALUE | ||
this.buffer = new LongLongHashMap((int) length); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
var endId = startId + length; | ||
for (long id = startId; id < endId; id++) { | ||
buffer.addTo(communityFunction.applyAsLong(id), 1L); | ||
} | ||
buffer.forEach((LongLongProcedure) builder::addTo); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
algo-common/src/main/java/org/neo4j/gds/result/CommunityCountAndRecordTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.gds.result; | ||
|
||
import org.HdrHistogram.Histogram; | ||
import org.neo4j.gds.collections.hsa.HugeSparseLongArray; | ||
import org.neo4j.gds.core.utils.partition.Partition; | ||
|
||
class CommunityCountAndRecordTask implements Runnable { | ||
|
||
private final HugeSparseLongArray communitySizes; | ||
|
||
private final Partition partition; | ||
|
||
private final Histogram histogram; | ||
|
||
private long count; | ||
|
||
CommunityCountAndRecordTask( | ||
HugeSparseLongArray communitySizes, | ||
Partition partition, | ||
HistogramProvider histogramProvider | ||
) { | ||
this.communitySizes = communitySizes; | ||
this.partition = partition; | ||
this.histogram = histogramProvider.get(); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
partition.consume(id -> { | ||
long communitySize = communitySizes.get(id); | ||
if (communitySize != CommunityStatistics.EMPTY_COMMUNITY) { | ||
count++; | ||
histogram.recordValue(communitySize); | ||
} | ||
}); | ||
} | ||
|
||
public long count(){ | ||
return count; | ||
} | ||
|
||
public Histogram histogram(){ | ||
return histogram; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
algo-common/src/main/java/org/neo4j/gds/result/CommunityCountTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.gds.result; | ||
|
||
import org.neo4j.gds.collections.hsa.HugeSparseLongArray; | ||
import org.neo4j.gds.core.utils.partition.Partition; | ||
|
||
class CommunityCountTask implements Runnable { | ||
|
||
private final HugeSparseLongArray communitySizes; | ||
|
||
private final Partition partition; | ||
|
||
private long count; | ||
|
||
CommunityCountTask(HugeSparseLongArray communitySizes, Partition partition) { | ||
this.communitySizes = communitySizes; | ||
this.partition = partition; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
partition.consume(id -> { | ||
if (communitySizes.get(id) != CommunityStatistics.EMPTY_COMMUNITY) { | ||
count++; | ||
} | ||
}); | ||
} | ||
|
||
long count() { | ||
return count; | ||
} | ||
} |
Oops, something went wrong.