Skip to content

Commit caf80a5

Browse files
committed
Added profiles to math.dist()
1 parent 5f5cafe commit caf80a5

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2695,14 +2695,16 @@ public Object doGeneric(VirtualFrame frame, Object iterable, Object start) {
26952695
@GenerateNodeFactory
26962696
public abstract static class DistNode extends PythonBuiltinNode {
26972697

2698-
@Child private TupleNodes.ConstructTupleNode tupleCtor = TupleNodes.ConstructTupleNode.create();
2699-
@Child private SequenceNodes.GetObjectArrayNode getObjectArray = SequenceNodes.GetObjectArrayNode.create();
2700-
private final LoopConditionProfile loopProfile1 = LoopConditionProfile.createCountingProfile();
2701-
private final LoopConditionProfile loopProfile2 = LoopConditionProfile.createCountingProfile();
2702-
27032698
@Specialization
27042699
public double doGeneric(VirtualFrame frame, Object p, Object q,
2705-
@CachedLibrary(limit = "4") PythonObjectLibrary lib) {
2700+
@CachedLibrary(limit = "4") PythonObjectLibrary lib,
2701+
@Cached TupleNodes.ConstructTupleNode tupleCtor,
2702+
@Cached SequenceNodes.GetObjectArrayNode getObjectArray,
2703+
@Cached("createCountingProfile()") LoopConditionProfile loopProfile1,
2704+
@Cached("createCountingProfile()") LoopConditionProfile loopProfile2,
2705+
@Cached("createBinaryProfile()") ConditionProfile infProfile,
2706+
@Cached("createBinaryProfile()") ConditionProfile nanProfile,
2707+
@Cached("createBinaryProfile()") ConditionProfile trivialProfile) {
27062708
// adapted from CPython math_dist_impl and vector_norm
27072709
Object[] ps = getObjectArray.execute(tupleCtor.execute(frame, p));
27082710
Object[] qs = getObjectArray.execute(tupleCtor.execute(frame, q));
@@ -2724,13 +2726,13 @@ public double doGeneric(VirtualFrame frame, Object p, Object q,
27242726
max = x;
27252727
}
27262728
}
2727-
if (Double.isInfinite(max)) {
2729+
if (infProfile.profile(Double.isInfinite(max))) {
27282730
return max;
27292731
}
2730-
if (foundNan) {
2732+
if (nanProfile.profile(foundNan)) {
27312733
return Double.NaN;
27322734
}
2733-
if (max == 0.0 || len <= 1) {
2735+
if (trivialProfile.profile(max == 0.0 || len <= 1)) {
27342736
return max;
27352737
}
27362738

0 commit comments

Comments
 (0)