pylibraft.random

pylibraft.random#

2 min read time

Applies to Linux

Submodules#

Functions#

rmat(*args[, handle])

rmat(out, theta, r_scale, c_scale, seed=12345, handle=None)

Package Contents#

pylibraft.random.rmat(*args, handle=None, **kwargs)#

rmat(out, theta, r_scale, c_scale, seed=12345, handle=None)

Generate RMAT adjacency list based on the input distribution.

out:

CUDA array interface compliant matrix shape (n_edges, 2). This will contain the src/dst node ids stored consecutively like a pair.

theta:

CUDA array interface compliant matrix shape (max(r_scale, c_scale) * 4) This stores the probability distribution at each RMAT level

r_scale: int

log2 of number of source nodes

c_scale: int

log2 of number of destination nodes

seed: int

random seed used for reproducibility

handleOptional RAFT resource handle for reusing CUDA resources.

If a handle isn’t supplied, CUDA resources will be allocated inside this function and synchronized before the function exits. If a handle is supplied, you will need to explicitly synchronize yourself by calling handle.sync() before accessing the output.

>>> import cupy as cp
>>> from pylibraft.common import Handle
>>> from pylibraft.random import rmat
>>> n_edges = 5000
>>> r_scale = 16
>>> c_scale = 14
>>> theta_len = max(r_scale, c_scale) * 4
>>> out = cp.empty((n_edges, 2), dtype=cp.int32)
>>> theta = cp.random.random_sample(theta_len, dtype=cp.float32)
>>> # A single RAFT handle can optionally be reused across
>>> # pylibraft functions.
>>> handle = Handle()
>>> rmat(out, theta, r_scale, c_scale, handle=handle)
>>> # pylibraft functions are often asynchronous so the
>>> # handle needs to be explicitly synchronized
>>> handle.sync()