{"library":"pylibraft-cu12","title":"RAFT Python Library (CUDA 12)","description":"pylibraft-cu12 is the Python binding for RAFT (Reusable Algorithms Functions and other Tools), a core component of the NVIDIA RAPIDS ecosystem providing a collection of GPU-accelerated primitives and algorithms for data science. It is designed for optimal performance on NVIDIA GPUs with CUDA 12.x. The current version is 26.4.0, following a monthly release cadence aligned with the broader RAPIDS project.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install pylibraft-cu12 cupy-cuda12x","pip install pylibraft-cu12"],"cli":null},"imports":["from raft.neighbors import NearestNeighbors","from raft.cluster import KMeans","from raft.common.cuda_utils import get_device_info","from raft.linear_model import LinearRegression"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import cupy as cp\nfrom raft.neighbors import NearestNeighbors\nimport sys\n\n# Ensure CuPy is installed for GPU array handling and a CUDA device is available\ntry:\n    if cp.cuda.runtime.getDeviceCount() == 0:\n        print(\"Error: No CUDA device found. RAFT requires a CUDA-enabled GPU.\")\n        sys.exit(1)\nexcept cp.cuda.runtime.CUDARuntimeError as e:\n    print(f\"Error initializing CuPy or CUDA runtime: {e}\")\n    print(\"Please ensure CuPy is installed correctly (e.g., `cupy-cuda12x`) and your CUDA environment is set up.\")\n    sys.exit(1)\n\n# Generate some random GPU data using CuPy\nn_samples = 100\nn_features = 10\nX = cp.random.rand(n_samples, n_features, dtype=cp.float32)\n\n# Create a NearestNeighbors model\nnn = NearestNeighbors(n_neighbors=5, metric='euclidean', output_type='cupy')\n\n# Fit the model to the data\nnn.fit(X)\n\n# Query for nearest neighbors to the same data\ndistances, indices = nn.kneighbors(X)\n\nprint(\"Distances shape:\", distances.shape)\nprint(\"Indices shape:\", indices.shape)\nprint(\"\\nFirst 5 distances (sample 0):\\n\", distances[0, :5])\nprint(\"\\nFirst 5 indices (sample 0):\\n\", indices[0, :5])","lang":"python","description":"This quickstart demonstrates how to use `raft.neighbors.NearestNeighbors` to find the k-nearest neighbors on GPU data using CuPy. It initializes random GPU data, fits a NearestNeighbors model, and queries for neighbors. Ensure you have `cupy-cuda12x` installed for this example to run and a CUDA-enabled GPU.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}