Skip to content

Commit f5c671b

Browse files
committed
Address PR comments, restructure C API implementation more cleanly
1 parent b09d545 commit f5c671b

25 files changed

Lines changed: 2204 additions & 2655 deletions

cpp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ add_library(cugraph_c
679679
src/c_api/lookup_src_dst.cpp
680680
src/c_api/louvain.cpp
681681
src/c_api/triangle_count.cpp
682+
src/c_api/neighbor_sample.cpp
682683
src/c_api/neighbor_sampling.cpp
683684
src/c_api/sampling_result.cpp
684685
src/c_api/temporal_neighbor_sampling.cpp

cpp/include/cugraph/sampling_functions.hpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,26 @@ enum class temporal_sampling_comparison_t {
4444
MONOTONICALLY_DECREASING, /** Time monotonically decreasing (could have multiple edges with same
4545
time) */
4646
FIXED_WINDOW, /** Apply the original per-seed time window at every hop */
47-
LAST = FIXED_WINDOW /** Deprecated alias for FIXED_WINDOW */
47+
LAST /** Deprecated Value, we moved last-n to a different parameter */
4848
};
4949

5050
/**
5151
* @brief Selects neighbors from the set that satisfies the sampling filters.
5252
*/
5353
enum class neighbor_selection_t {
5454
RANDOM = 0, /** Random selection. Uniform if no bias view is supplied, biased otherwise. */
55-
FIRST, /** Deterministically select the earliest edges. Not yet implemented. */
56-
LAST /** Deterministically select the latest edges. Not yet implemented. */
55+
LAST /** Deterministically select the latest edges based on the ordering criteria defined in
56+
temporal_sampling_comparison. Not yet implemented. */
5757
};
5858

59-
struct sampling_flags_t {
59+
/**
60+
* @brief Options controlling neighborhood sampling behavior.
61+
*
62+
* Temporal sampling is enabled when @p temporal_sampling_comparison has a value; leave it
63+
* unset for non-temporal sampling. Future sampling knobs should be added here so
64+
* `neighbor_sample` can keep a stable parameter list.
65+
*/
66+
struct sampling_options_t {
6067
/**
6168
* Specifies how to handle prior sources. Default is DEFAULT.
6269
*/
@@ -81,10 +88,10 @@ struct sampling_flags_t {
8188
bool with_replacement{true};
8289

8390
/**
84-
* Specifies how to handle temporal sampling. Default is STRICTLY_INCREASING.
91+
* When set, enables temporal sampling with the given comparison mode. Default is unset
92+
* (non-temporal).
8593
*/
86-
temporal_sampling_comparison_t temporal_sampling_comparison{
87-
temporal_sampling_comparison_t::STRICTLY_INCREASING};
94+
std::optional<temporal_sampling_comparison_t> temporal_sampling_comparison{std::nullopt};
8895

8996
/**
9097
* Specifies if disjoint sampling should be enforced. Default is false.
@@ -97,6 +104,9 @@ struct sampling_flags_t {
97104
neighbor_selection_t neighbor_selection{neighbor_selection_t::RANDOM};
98105
};
99106

107+
/** @deprecated Use sampling_options_t. */
108+
using sampling_flags_t = sampling_options_t;
109+
100110
/**
101111
* @ingroup sampling_functions_cpp
102112
* @deprecated Use neighbor_sample instead.
@@ -925,11 +935,10 @@ heterogeneous_biased_temporal_neighbor_sample(
925935
* contains one value per hop.
926936
*
927937
* RANDOM selection samples uniformly when @p edge_bias_view is absent and samples according to
928-
* the supplied biases when it is present. FIRST and LAST are reserved for deterministically
929-
* selecting the earliest or latest eligible edges (temporal only; no bias; no with-replacement),
930-
* but are not yet implemented.
938+
* the supplied biases when it is present. LAST is reserved for deterministically selecting the
939+
* latest eligible edges (temporal only; no bias; no with-replacement), but is not yet implemented.
931940
*
932-
* Sampling is temporal when @p temporal_sampling_comparison is specified; in that case
941+
* Sampling is temporal when @p sampling_options.temporal_sampling_comparison is set; in that case
933942
* @p edge_start_time_view is required. FIXED_WINDOW applies each seed's original closed time window
934943
* at every hop, while the increasing and decreasing modes propagate sampled edge times as the next
935944
* frontier bound.
@@ -967,9 +976,7 @@ neighbor_sample(
967976
std::optional<raft::device_span<int32_t const>> label_to_output_comm_rank,
968977
raft::host_span<int32_t const> fan_out,
969978
std::optional<edge_type_t> num_edge_types,
970-
neighbor_selection_t neighbor_selection,
971-
std::optional<temporal_sampling_comparison_t> temporal_sampling_comparison,
972-
sampling_flags_t sampling_flags,
979+
sampling_options_t sampling_options,
973980
bool do_expensive_check = false);
974981

975982
/**

cpp/include/cugraph_c/sampling_algorithms.h

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,17 @@ typedef enum {
198198
MONOTONICALLY_DECREASING, /** Time monotonically decreasing (could have multiple edges with same
199199
time) */
200200
FIXED_WINDOW, /** Apply the original per-seed time window at every hop */
201-
LAST = FIXED_WINDOW /** Deprecated alias for FIXED_WINDOW */
201+
LAST /** Deprecated Value, we moved last-n to a different parameter */
202202
} cugraph_temporal_sampling_comparison_t;
203203

204204
/**
205205
* @brief Selects neighbors from the set that satisfies the sampling filters.
206206
*/
207207
typedef enum {
208208
CUGRAPH_NEIGHBOR_SELECTION_RANDOM = 0, /** Uniform without biases, biased with biases */
209-
CUGRAPH_NEIGHBOR_SELECTION_FIRST, /** Deterministically select the earliest edges (not yet
210-
implemented) */
211-
CUGRAPH_NEIGHBOR_SELECTION_LAST /** Deterministically select the latest edges (not yet
212-
implemented) */
209+
CUGRAPH_NEIGHBOR_SELECTION_LAST /** Deterministically select the last-n edges based on the
210+
ordering criteria defined in temporal_sampling_comparison (not
211+
yet implemented) */
213212
} cugraph_neighbor_selection_t;
214213

215214
/**
@@ -330,6 +329,25 @@ CUGRAPH_EXPORT void cugraph_sampling_set_dedupe_sources(cugraph_sampling_options
330329
CUGRAPH_EXPORT void cugraph_sampling_set_temporal_sampling_comparison(
331330
cugraph_sampling_options_t* options, cugraph_temporal_sampling_comparison_t comparison);
332331

332+
/**
333+
* @ingroup samplingC
334+
* @brief Clear temporal sampling comparison, disabling temporal sampling.
335+
*
336+
* @param options - opaque pointer to the sampling options
337+
*/
338+
CUGRAPH_EXPORT void cugraph_sampling_clear_temporal_sampling_comparison(
339+
cugraph_sampling_options_t* options);
340+
341+
/**
342+
* @ingroup samplingC
343+
* @brief Set neighbor selection mode.
344+
*
345+
* @param options - opaque pointer to the sampling options
346+
* @param selection - RANDOM or LAST
347+
*/
348+
CUGRAPH_EXPORT void cugraph_sampling_set_neighbor_selection(cugraph_sampling_options_t* options,
349+
cugraph_neighbor_selection_t selection);
350+
333351
/**
334352
* @ingroup samplingC
335353
* @brief Set flag to perform disjoint sampling
@@ -354,14 +372,14 @@ CUGRAPH_EXPORT void cugraph_sampling_options_free(cugraph_sampling_options_t* op
354372
* @brief Unified homogeneous/heterogeneous and temporal/non-temporal neighborhood sampling.
355373
*
356374
* RANDOM selection samples uniformly if @p edge_biases is NULL and samples according to
357-
* @p edge_biases otherwise. FIRST and LAST are reserved for deterministically selecting the
358-
* earliest or latest temporally eligible edges (requiring @p temporal_sampling_comparison), but
359-
* are not yet implemented.
375+
* @p edge_biases otherwise. LAST is reserved for deterministically selecting the latest
376+
* temporally eligible edges (requiring temporal sampling), but is not yet implemented.
360377
*
361-
* Sampling is non-temporal when @p temporal_sampling_comparison is NULL; all temporal arguments
362-
* must then be NULL. Sampling is homogeneous when @p num_edge_types is 1; otherwise
363-
* @p fan_out contains one value per (hop, edge type). When @p vertex_type_offsets is NULL,
364-
* all vertices are treated as a single vertex type.
378+
* Sampling is non-temporal unless cugraph_sampling_set_temporal_sampling_comparison has been
379+
* called on @p sampling_options; all temporal arguments must then be NULL. Sampling is
380+
* homogeneous when @p num_edge_types is 1; otherwise @p fan_out contains one value per
381+
* (hop, edge type). When @p vertex_type_offsets is NULL, all vertices are treated as a single
382+
* vertex type.
365383
*
366384
* @param [in] handle Handle for accessing resources.
367385
* @param [in,out] rng_state State of the random number generator, updated for RANDOM selection.
@@ -375,10 +393,9 @@ CUGRAPH_EXPORT void cugraph_sampling_options_free(cugraph_sampling_options_t* op
375393
* processing.
376394
* @param [in] fan_out Host array defining fanout per hop (and per edge type when heterogeneous).
377395
* @param [in] num_edge_types Number of edge types. Use 1 for homogeneous sampling.
378-
* @param [in] neighbor_selection RANDOM, FIRST, or LAST.
379-
* @param [in] temporal_sampling_comparison Optional temporal comparison. NULL disables temporal
380-
* sampling.
381-
* @param [in] sampling_options Sampling options.
396+
* @param [in] sampling_options Sampling options. Temporal sampling is enabled by
397+
* cugraph_sampling_set_temporal_sampling_comparison; neighbor selection defaults to RANDOM and may
398+
* be set with cugraph_sampling_set_neighbor_selection.
382399
* @param [in] do_expensive_check Whether to perform expensive input validation.
383400
* @param [out] result Sampling result.
384401
* @param [out] error Error details on failure.
@@ -396,8 +413,6 @@ CUGRAPH_EXPORT cugraph_error_code_t cugraph_neighbor_sample(
396413
const cugraph_type_erased_device_array_view_t* vertex_type_offsets,
397414
const cugraph_type_erased_host_array_view_t* fan_out,
398415
int num_edge_types,
399-
cugraph_neighbor_selection_t neighbor_selection,
400-
const cugraph_temporal_sampling_comparison_t* temporal_sampling_comparison,
401416
const cugraph_sampling_options_t* sampling_options,
402417
bool_t do_expensive_check,
403418
cugraph_sample_result_t** result,

0 commit comments

Comments
 (0)