← Back to Pull requests

fix(dbscan): split the metrics example per metric and batch the Minkowski powers #3995

Closed
unknown closed this pull request without merging on Nov 10, 2026 10:59 UTC
View on GitHub
unknown unknown commented on Nov 05, 2026 15:19 UTC
Author

Description

dbscan_brute_force_metrics_batch ran DBSCAN with five metrics in one process and exceeded the 5-minute per-example limit in the internal Windows example run (TIMEOUT (0:05:00) dbscan_brute_force_metrics_batch). This PR splits the example per metric, which showed that Minkowski is the slow one, and fixes the Minkowski distance computation.

Examples. One example per metric, in examples/oneapi/cpp and examples/oneapi/dpc:

  • dbscan_brute_force_manhattan_batch.cpp

  • dbscan_brute_force_minkowski_batch.cpp (degree 3)

  • dbscan_brute_force_chebyshev_batch.cpp

  • dbscan_brute_force_cosine_batch.cpp
  • Data, epsilon and min_observations are the same as in the removed example. The euclidean case is dropped, since dbscan_brute_force_batch already shows the default metric. docs/source/includes/clustering/dbscan-examples.rst lists the new files; Bazel, CMake and the docs pick the files up by glob. After the split, the internal Windows run times out only in dbscan_brute_force_minkowski_batch.

    Minkowski distances. MinkowskiDistances::computeBatch (service_kernel_math.h) is used for Minkowski degrees other than 1 and 2 by the CPU DBSCAN default path, by brute-force kNN (classification, regression and search, which scikit-learn-intelex uses for KNeighborsClassifier, KNeighborsRegressor, NearestNeighbors and LocalOutlierFactor with metric="minkowski") and by the HDBSCAN medoid computation. It called sPowx on every coordinate of every pair, and on the MKL backend each sPowx is a separate vPowx call with n = 1; the example (10500 x 2, degree 3) makes about 2.2e8 of them.

    computeBatch now writes the absolute differences of up to 32 values into a stack buffer, raises them to p in one vPowx call with the same VML mode, and sums each pair in coordinate order; a row with more than 32 features is processed in pieces. Degree 1 keeps the existing path. Brute-force kNN maps degree 2 to the euclidean distance; DBSCAN passes any degree to this class, so degree 2 takes the chunked path there. The chunk stays small on purpose: with the TBB threading layer VML starts its own parallel_for for longer vectors (seen from 128 elements), mkl_set_num_threads_local does not stop it, and from inside the DBSCAN neighborhood loop that made a 1024-value chunk up to 2.5x slower than main on all cores. computeBatch also returns the status of computeBatchImpl instead of dropping it.

    Performance. Speedup of this PR over main (median time on main / median time with this PR) on a two-socket Intel CPU. Each cell is the range over degrees 1.5, 3 and 4.7. scikit-learn-intelex main was built once and run against both oneDAL builds by switching LD_LIBRARY_PATH; brute force, n_neighbors=10 (20 for LOF), 2000 queries against 20000 rows up to d=17, 1000 against 10000 for d=32 and 100, 500 against 4000 for d=512, 200 against 2000 for d=1000; median of 5 calls, three alternating rounds.

    | sklearnex, all cores | d=2 | d=8 | d=16 | d=17 | d=32 | d=100 | d=512 | d=1000 |
    |---|---|---|---|---|---|---|---|---|
    | KNeighborsClassifier, float32 | 3.9-4.9x | 7.5-10.0x | 1.3-1.4x | 1.3-1.5x | 1.4-1.7x | 2.0-2.1x | 1.0-1.2x | 1.3-1.4x |
    | KNeighborsClassifier, float64 | 3.9-4.6x | 1.7-2.1x | 1.7-1.9x | 1.7-1.8x | 1.5-2.3x | 2.2-2.9x | 1.1-2.2x | 1.4-2.2x |
    | KNeighborsRegressor, float32 | 3.9-4.8x | 7.8-10.4x | 1.2-1.4x | 1.4-1.5x | 1.3-1.6x | 1.9-2.1x | 1.0-1.2x | 1.3-1.7x |
    | NearestNeighbors, float32 | 3.8-5.0x | 7.8-10.1x | 1.2-1.5x | 1.3-1.5x | 1.4-1.4x | 1.9-2.0x | 1.0-1.3x | 1.3-1.9x |
    | LocalOutlierFactor, float32 | 2.2-3.0x | 4.7-6.2x | 1.2-1.4x | 1.3-1.3x | 1.2-1.3x | 1.7-2.3x | 0.9-1.2x | 1.1-1.5x |

    | sklearnex, limited cores | d=2 | d=16 | d=100 |
    |---|---|---|---|
    | 1 core | 11.5-15.0x | 1.4-1.6x | 1.7-2.0x |
    | 8 cores | 11.6-14.6x | 1.6-1.9x | 1.8-2.3x |
    | 56 cores | 5.4-8.0x | 1.4-1.5x | 1.7-2.1x |

    DBSCAN through the oneAPI C++ interface (rows chosen so that rows^2 x d is about 2e9, 2000-20000 rows; median of 3 runs, three alternating rounds; float and double):

    | DBSCAN, all cores | d=1 | d=2 | d=3 | d=8 | d=15 | d=16 | d=17 | d=32 | d=64 | d=100 | d=256 | d=512 | d=1000 |
    |---|---|---|---|---|---|---|---|---|---|---|---|---|---|
    | float | 1.6-2.5x | 2.9-4.3x | 2.7-4.3x | 6.5-12.6x | 7.7-11.3x | 1.4-1.7x | 1.3-1.7x | 1.3-1.9x | 1.3-1.8x | 1.6-2.1x | 1.2-1.7x | 1.3-1.7x | 1.4-2.1x |
    | double | 2.1-2.6x | 2.6-4.2x | 2.4-4.0x | 1.6-2.0x | 4.8-6.2x | 1.6-2.3x | 1.5-2.4x | 1.5-2.5x | 1.3-2.5x | 1.5-2.3x | 1.4-2.7x | 1.4-2.7x | 1.3-2.2x |

    | DBSCAN float, limited cores | d=2 | d=16 | d=100 |
    |---|---|---|---|
    | 1 core | 8.4-14.3x | 1.1-1.6x | 1.9-2.1x |
    | 8 cores | 8.1-14.4x | 1.6-1.8x | 1.9-2.1x |
    | 56 cores | 5.9-8.9x | 1.2-1.5x | 2.1-2.3x |

  • The smallest gain is for float32 with 512 features (0.9-1.2x, within run-to-run noise on calls of about 50 ms): there main already raised the differences in 16-value vPowx calls through the AVX-512 specialization of computeDistance. Every other kNN and DBSCAN scenario is at least 1.06x faster, most of them 1.3x or more.

  • Paths this PR does not change behave the same: p=1 and p=2 in the matrices above are within 0.8-1.2x on runs of a few milliseconds, and a targeted rerun with larger inputs and 15 calls per round gives 0.96-1.10x for kNN and 0.98-1.01x for DBSCAN.

  • HDBSCAN (brute force, 10000 rows, minkowski, with and without medoids): total time 0.93-1.26x, since the minimum spanning tree dominates and uses its own distance functor; the medoid part alone is 1.5-5.6x faster with 100 features.
  • Correctness.

  • kNN Minkowski distances, checked against main and against a long double reference for 1-1100 features (including 15, 16, 17, 1024 and 1025), degrees 0.5, 1, 1.5, 3 and 4.7, float and double. The neighbor indices are identical to main. The distances differ from main only in the last bits, from the summation order, and the largest relative error against the reference is lower than on main (8.4e-7 vs 1.0e-6 in float, 1.5e-15 vs 2.2e-15 in double).

  • DBSCAN responses are identical to main in all 104 type/feature/degree cases of the matrix and in the limited-core runs. HDBSCAN responses and medoid coordinates are identical too.

  • In the scikit-learn-intelex matrix (161 cases), three outputs differ, all in float32: 2 of 20000 neighbor indices in one NearestNeighbors case, 1 of 5000 in another, and 1 of 500 KNeighborsRegressor predictions. In every case the neighbors involved are at distances 1 ulp apart or equal: the k-th neighbor swaps at a tie, as with any change of rounding. All other outputs are identical.
  • Tests.

  • bazel test --config=host: //cpp/oneapi/dal/algo/{dbscan,knn,hdbscan}:tests, //examples/daal/cpp:{dbscan,k_nearest_neighbors} and //examples/oneapi/cpp:{dbscan,hdbscan,knn} pass (26 targets). The dbscan, knn and hdbscan batch suites also pass with --order rand for three seeds.

  • bazel test --config=dpc --device=gpu: //cpp/oneapi/dal/algo/{dbscan,knn}:tests and //examples/oneapi/dpc:{dbscan,knn} pass (16 targets).

  • bazel build //:release with GCC 13 succeeds.

  • scikit-learn-intelex sklearnex/neighbors and onedal/neighbors (88 passed) and scikit-learn's sklearn.neighbors suite under the patch (1516 passed) give the same results with main and with this PR.

  • The DBSCAN batch suite checks Minkowski degrees 3 and 0.5 against a reference distance definition. Its 37-column case covers rows longer than one 32-value chunk with a partial last chunk, and the 2-column case a partial chunk of pairs.
  • No public API or ABI changes.

    ---

    Checklist:

    Completeness and readability

  • I have commented my code, particularly in hard-to-understand areas.

  • I have updated the documentation to reflect the changes or created a separate PR with updates and provided its number in the description, if necessary.

  • Git commit message contains an appropriate signed-off-by string _(see CONTRIBUTING.md for details)_.

  • I have resolved any merge conflicts that might occur with the base branch.
  • Testing

  • I have run it locally and tested the changes extensively.

  • All CI jobs are green or I have provided justification why they aren't.
  • Performance

  • I have measured performance for affected algorithms using scikit-learn_bench and provided at least a summary table with measured data, if performance change is expected.

  • Not with scikit-learn_bench: measured with scikit-learn-intelex estimators and the oneDAL DBSCAN/HDBSCAN interface directly (tables above).

    🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: Vika-F Review duration: 6939m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3995"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%