From 5b04cfd04c5a4b7f64a642f615d2da3bd396e0cf Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Thu, 8 Dec 2022 00:43:46 -0600 Subject: [PATCH 1/8] Update pre-commit configuration. --- .pre-commit-config.yaml | 29 +- ci/checks/copyright.py | 217 +++++++------ ci/checks/style.sh | 72 +---- cpp/scripts/gitutils.py | 286 ------------------ cpp/scripts/run-clang-format.py | 141 --------- python/.flake8 | 7 - .../cugraph/tests/test_property_graph.py | 5 +- setup.cfg | 25 ++ 8 files changed, 181 insertions(+), 601 deletions(-) delete mode 100644 cpp/scripts/gitutils.py delete mode 100644 cpp/scripts/run-clang-format.py delete mode 100644 python/.flake8 create mode 100644 setup.cfg diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 61d21fcba7b..5c158d15551 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,13 +4,13 @@ # To run: `pre-commit run --all-files` repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 + rev: v4.4.0 hooks: - id: check-added-large-files - id: debug-statements - id: mixed-line-ending - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 22.10.0 hooks: - id: black language_version: python3 @@ -18,14 +18,31 @@ repos: args: [--target-version=py38] files: ^python/ - repo: https://github.com/PyCQA/flake8 - rev: 3.8.4 + rev: 6.0.0 hooks: - id: flake8 - args: [--config=python/.flake8] - files: ^python/ + args: ["--config=setup.cfg"] + files: python/.*$ + types: [file] + types_or: [python] # TODO: Enable [python, cython] + additional_dependencies: ["flake8-force"] - repo: https://github.com/asottile/yesqa rev: v1.3.0 hooks: - id: yesqa additional_dependencies: - - flake8==3.8.4 + - flake8==6.0.0 +# - repo: https://github.com/pre-commit/mirrors-clang-format +# rev: v11.1.0 +# hooks: +# - id: clang-format +# types_or: [c, c++, cuda] +# args: ["-fallback-style=none", "-style=file", "-i"] + - repo: local + hooks: + - id: copyright-check + name: copyright-check + entry: python ./ci/checks/copyright.py --git-modified-only --update-current-year + language: python + pass_filenames: false + additional_dependencies: [gitpython] diff --git a/ci/checks/copyright.py b/ci/checks/copyright.py index f3acfd404f5..83f43183f71 100644 --- a/ci/checks/copyright.py +++ b/ci/checks/copyright.py @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,22 +13,13 @@ # limitations under the License. # -import datetime -import re import argparse -import io +import datetime import os +import re import sys -SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.expanduser(__file__))) - -# Add the scripts dir for gitutils -sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, - "../../cpp/scripts"))) - -# Now import gitutils. Ignore flake8 error here since there is no other way to -# set up imports -import gitutils # noqa: E402 +import git FilesToCheck = [ re.compile(r"[.](cmake|cpp|cu|cuh|h|hpp|sh|pxd|py|pyx)$"), @@ -36,23 +27,29 @@ re.compile(r"CMakeLists_standalone[.]txt$"), re.compile(r"setup[.]cfg$"), re.compile(r"[.]flake8[.]cython$"), - re.compile(r"meta[.]yaml$") + re.compile(r"meta[.]yaml$"), +] +ExemptFiles = [ + re.compile(r"cpp/include/cudf_test/cxxopts.hpp"), + re.compile(r"versioneer[.]py"), ] -ExemptFiles = ['versioneer.py'] # this will break starting at year 10000, which is probably OK :) CheckSimple = re.compile( - r"Copyright *(?:\(c\))? *(\d{4}),? *NVIDIA C(?:ORPORATION|orporation)") + r"Copyright *(?:\(c\))? *(\d{4}),? *NVIDIA C(?:ORPORATION|orporation)" +) CheckDouble = re.compile( r"Copyright *(?:\(c\))? *(\d{4})-(\d{4}),? *NVIDIA C(?:ORPORATION|orporation)" # noqa: E501 ) def checkThisFile(f): - # This check covers things like symlinks which point to files that DNE - if not (os.path.exists(f)): - return False - if gitutils and gitutils.isFileEmpty(f): + if isinstance(f, git.Diff): + if f.deleted_file or f.b_blob.size == 0: + return False + f = f.b_path + elif not os.path.exists(f) or os.stat(f).st_size == 0: + # This check covers things like symlinks which point to files that DNE return False for exempt in ExemptFiles: if exempt.search(f): @@ -63,36 +60,90 @@ def checkThisFile(f): return False +def modifiedFiles(): + """Get a set of all modified files, as Diff objects. + + The files returned have been modified in git since the merge base of HEAD + and the upstream of the target branch. We return the Diff objects so that + we can read only the staged changes. + """ + repo = git.Repo() + # Use the environment variable TARGET_BRANCH (defined in CI) if possible + target_branch = os.environ.get("TARGET_BRANCH") + if target_branch is None: + # Fall back to the closest branch if not on CI + target_branch = repo.git.describe( + all=True, tags=True, match="branch-*", abbrev=0 + ).lstrip("heads/") + + upstream_target_branch = None + if target_branch in repo.heads: + # Use the tracking branch of the local reference if it exists. This + # returns None if no tracking branch is set. + upstream_target_branch = repo.heads[target_branch].tracking_branch() + if upstream_target_branch is None: + # Fall back to the remote with the newest target_branch. This code + # path is used on CI because the only local branch reference is + # current-pr-branch, and thus target_branch is not in repo.heads. + # This also happens if no tracking branch is defined for the local + # target_branch. We use the remote with the latest commit if + # multiple remotes are defined. + candidate_branches = [ + remote.refs[target_branch] for remote in repo.remotes + if target_branch in remote.refs + ] + if len(candidate_branches) > 0: + upstream_target_branch = sorted( + candidate_branches, + key=lambda branch: branch.commit.committed_datetime, + )[-1] + else: + # If no remotes are defined, try to use the local version of the + # target_branch. If this fails, the repo configuration must be very + # strange and we can fix this script on a case-by-case basis. + upstream_target_branch = repo.heads[target_branch] + merge_base = repo.merge_base("HEAD", upstream_target_branch.commit)[0] + diff = merge_base.diff() + changed_files = {f for f in diff if f.b_path is not None} + return changed_files + + def getCopyrightYears(line): res = CheckSimple.search(line) if res: - return (int(res.group(1)), int(res.group(1))) + return int(res.group(1)), int(res.group(1)) res = CheckDouble.search(line) if res: - return (int(res.group(1)), int(res.group(2))) - return (None, None) + return int(res.group(1)), int(res.group(2)) + return None, None def replaceCurrentYear(line, start, end): # first turn a simple regex into double (if applicable). then update years res = CheckSimple.sub(r"Copyright (c) \1-\1, NVIDIA CORPORATION", line) res = CheckDouble.sub( - r"Copyright (c) {:04d}-{:04d}, NVIDIA CORPORATION".format(start, end), - res) + rf"Copyright (c) {start:04d}-{end:04d}, NVIDIA CORPORATION", + res, + ) return res def checkCopyright(f, update_current_year): - """ - Checks for copyright headers and their years - """ + """Checks for copyright headers and their years.""" errs = [] thisYear = datetime.datetime.now().year lineNum = 0 crFound = False yearMatched = False - with io.open(f, "r", encoding="utf-8") as fp: - lines = fp.readlines() + + if isinstance(f, git.Diff): + path = f.b_path + lines = f.b_blob.data_stream.read().decode().splitlines(keepends=True) + else: + path = f + with open(f, encoding="utf-8") as fp: + lines = fp.readlines() + for line in lines: lineNum += 1 start, end = getCopyrightYears(line) @@ -101,20 +152,19 @@ def checkCopyright(f, update_current_year): crFound = True if start > end: e = [ - f, + path, lineNum, "First year after second year in the copyright " "header (manual fix required)", - None + None, ] errs.append(e) - if thisYear < start or thisYear > end: + elif thisYear < start or thisYear > end: e = [ - f, + path, lineNum, - "Current year not included in the " - "copyright header", - None + "Current year not included in the copyright header", + None, ] if thisYear < start: e[-1] = replaceCurrentYear(line, thisYear, end) @@ -123,15 +173,14 @@ def checkCopyright(f, update_current_year): errs.append(e) else: yearMatched = True - fp.close() # copyright header itself not found if not crFound: e = [ - f, + path, 0, "Copyright header missing or formatted incorrectly " "(manual fix required)", - None + None, ] errs.append(e) # even if the year matches a copyright header, make the check pass @@ -141,21 +190,19 @@ def checkCopyright(f, update_current_year): if update_current_year: errs_update = [x for x in errs if x[-1] is not None] if len(errs_update) > 0: - print("File: {}. Changing line(s) {}".format( - f, ', '.join(str(x[1]) for x in errs if x[-1] is not None))) + lines_changed = ", ".join(str(x[1]) for x in errs_update) + print(f"File: {path}. Changing line(s) {lines_changed}") for _, lineNum, __, replacement in errs_update: lines[lineNum - 1] = replacement - with io.open(f, "w", encoding="utf-8") as out_file: - for new_line in lines: - out_file.write(new_line) - errs = [x for x in errs if x[-1] is None] + with open(path, "w", encoding="utf-8") as out_file: + out_file.writelines(lines) return errs def getAllFilesUnderDir(root, pathFilter=None): retList = [] - for (dirpath, dirnames, filenames) in os.walk(root): + for dirpath, dirnames, filenames in os.walk(root): for fn in filenames: filePath = os.path.join(dirpath, fn) if pathFilter(filePath): @@ -170,47 +217,37 @@ def checkCopyright_main(): it compares between branches "$PR_TARGET_BRANCH" and "current-pr-branch" """ retVal = 0 - global ExemptFiles argparser = argparse.ArgumentParser( - "Checks for a consistent copyright header in git's modified files") - argparser.add_argument("--update-current-year", - dest='update_current_year', - action="store_true", - required=False, - help="If set, " - "update the current year if a header " - "is already present and well formatted.") - argparser.add_argument("--git-modified-only", - dest='git_modified_only', - action="store_true", - required=False, - help="If set, " - "only files seen as modified by git will be " - "processed.") - argparser.add_argument("--exclude", - dest='exclude', - action="append", - required=False, - default=["python/cuml/_thirdparty/"], - help=("Exclude the paths specified (regexp). " - "Can be specified multiple times.")) - - (args, dirs) = argparser.parse_known_args() - try: - ExemptFiles = ExemptFiles + [pathName for pathName in args.exclude] - ExemptFiles = [re.compile(file) for file in ExemptFiles] - except re.error as reException: - print("Regular expression error:") - print(reException) - return 1 + "Checks for a consistent copyright header in git's modified files" + ) + argparser.add_argument( + "--update-current-year", + dest="update_current_year", + action="store_true", + required=False, + help="If set, " + "update the current year if a header is already " + "present and well formatted.", + ) + argparser.add_argument( + "--git-modified-only", + dest="git_modified_only", + action="store_true", + required=False, + help="If set, " + "only files seen as modified by git will be " + "processed.", + ) + + args, dirs = argparser.parse_known_args() if args.git_modified_only: - files = gitutils.modifiedFiles(pathFilter=checkThisFile) + files = [f for f in modifiedFiles() if checkThisFile(f)] else: files = [] for d in [os.path.abspath(d) for d in dirs]: - if not (os.path.isdir(d)): + if not os.path.isdir(d): raise ValueError(f"{d} is not a directory.") files += getAllFilesUnderDir(d, pathFilter=checkThisFile) @@ -219,24 +256,24 @@ def checkCopyright_main(): errors += checkCopyright(f, args.update_current_year) if len(errors) > 0: - print("Copyright headers incomplete in some of the files!") + if any(e[-1] is None for e in errors): + print("Copyright headers incomplete in some of the files!") for e in errors: print(" %s:%d Issue: %s" % (e[0], e[1], e[2])) print("") n_fixable = sum(1 for e in errors if e[-1] is not None) path_parts = os.path.abspath(__file__).split(os.sep) - file_from_repo = os.sep.join(path_parts[path_parts.index("ci"):]) - if n_fixable > 0: - print(("You can run `python {} --git-modified-only " - "--update-current-year` to fix {} of these " - "errors.\n").format(file_from_repo, n_fixable)) + file_from_repo = os.sep.join(path_parts[path_parts.index("ci") :]) + if n_fixable > 0 and not args.update_current_year: + print( + f"You can run `python {file_from_repo} --git-modified-only " + "--update-current-year` and stage the results in git to " + f"fix {n_fixable} of these errors.\n" + ) retVal = 1 - else: - print("Copyright check passed") return retVal if __name__ == "__main__": - import sys sys.exit(checkCopyright_main()) diff --git a/ci/checks/style.sh b/ci/checks/style.sh index 51b59071fd4..e2a74fa7ed4 100755 --- a/ci/checks/style.sh +++ b/ci/checks/style.sh @@ -4,76 +4,10 @@ # cuGraph Style Tester # ######################## -# Assume this script is run from the root of the cugraph repo - -# Make failing commands visible when used in a pipeline and allow the script to -# continue on errors, but use ERRORCODE to still allow any failing command to be -# captured for returning a final status code. This allows all style check to -# take place to provide a more comprehensive list of style violations. -set -o pipefail -# CI does `set -e` then sources this file, so we override that so we can output -# the results from the various style checkers -set +e -ERRORCODE=0 -PATH=/conda/bin:$PATH - # Activate common conda env +PATH=/conda/bin:$PATH . /opt/conda/etc/profile.d/conda.sh conda activate rapids -# Run flake8 and get results/return code -FLAKE=`flake8 --config=python/.flake8 python` -ERRORCODE=$((ERRORCODE | $?)) - -# Run black and get results/return code -BLACK_FORMAT=`black --target-version=py38 --check --exclude versioneer.py python 2>&1` -BLACK_FORMAT_RETVAL=$? -ERRORCODE=$((ERRORCODE | ${BLACK_FORMAT_RETVAL})) - -# Run clang-format and check for a consistent code format -CLANG_FORMAT=`python cpp/scripts/run-clang-format.py 2>&1` -CLANG_FORMAT_RETVAL=$? -ERRORCODE=$((ERRORCODE | ${CLANG_FORMAT_RETVAL})) - -# Output results if failure otherwise show pass -if [ "$FLAKE" != "" ]; then - echo -e "\n\n>>>> FAILED: flake8 style check; begin output\n\n" - echo -e "$FLAKE" - echo -e "\n\n>>>> FAILED: flake8 style check; end output\n\n" -else - echo -e "\n\n>>>> PASSED: flake8 style check\n\n" -fi - -if [ "$BLACK_FORMAT_RETVAL" != "0" ]; then - echo -e "\n\n>>>> FAILED: black format check; begin output\n\n" - echo -e "$BLACK_FORMAT" - echo -e "\n\n>>>> FAILED: black format check; end output\n\n" -else - echo -e "\n\n>>>> PASSED: black format check\n\n" -fi - -if [ "$CLANG_FORMAT_RETVAL" != "0" ]; then - echo -e "\n\n>>>> FAILED: clang format check; begin output\n\n" - echo -e "$CLANG_FORMAT" - echo -e "\n\n>>>> FAILED: clang format check; end output\n\n" -else - echo -e "\n\n>>>> PASSED: clang format check\n\n" -fi - -# Check for copyright headers in the files modified currently -#COPYRIGHT=`env PYTHONPATH=ci/utils python ci/checks/copyright.py cpp python benchmarks ci 2>&1` -COPYRIGHT=`env PYTHONPATH=ci/utils python ci/checks/copyright.py --git-modified-only --exclude=".*/versioneer.py" 2>&1` -CR_RETVAL=$? -ERRORCODE=$((ERRORCODE | ${CR_RETVAL})) - -if [ "$CR_RETVAL" != "0" ]; then - echo -e "\n\n>>>> FAILED: copyright check; begin output\n\n" - echo -e "$COPYRIGHT" - echo -e "\n\n>>>> FAILED: copyright check; end output\n\n" -else - echo -e "\n\n>>>> PASSED: copyright check; begin debug output\n\n" - echo -e "$COPYRIGHT" - echo -e "\n\n>>>> PASSED: copyright check; end debug output\n\n" -fi - -exit ${ERRORCODE} +# Run pre-commit checks +pre-commit run --hook-stage manual --all-files --show-diff-on-failure \ No newline at end of file diff --git a/cpp/scripts/gitutils.py b/cpp/scripts/gitutils.py deleted file mode 100644 index 4e30f8fcb03..00000000000 --- a/cpp/scripts/gitutils.py +++ /dev/null @@ -1,286 +0,0 @@ -# Copyright (c) 2022, NVIDIA CORPORATION. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -import subprocess -import os -import re - - -def isFileEmpty(f): - return os.stat(f).st_size == 0 - - -def __git(*opts): - """Runs a git command and returns its output""" - cmd = "git " + " ".join(list(opts)) - ret = subprocess.check_output(cmd, shell=True) - return ret.decode("UTF-8").rstrip("\n") - - -def __gitdiff(*opts): - """Runs a git diff command with no pager set""" - return __git("--no-pager", "diff", *opts) - - -def branch(): - """Returns the name of the current branch""" - name = __git("rev-parse", "--abbrev-ref", "HEAD") - name = name.rstrip() - return name - - -def repo_version(): - """ - Determines the version of the repo by using `git describe` - - Returns - ------- - str - The full version of the repo in the format 'v#.#.#{a|b|rc}' - """ - return __git("describe", "--tags", "--abbrev=0") - - -def repo_version_major_minor(): - """ - Determines the version of the repo using `git describe` and returns only - the major and minor portion - - Returns - ------- - str - The partial version of the repo in the format '{major}.{minor}' - """ - - full_repo_version = repo_version() - - match = re.match(r"^v?(?P[0-9]+)(?:\.(?P[0-9]+))?", - full_repo_version) - - if (match is None): - print(" [DEBUG] Could not determine repo major minor version. " - f"Full repo version: {full_repo_version}.") - return None - - out_version = match.group("major") - - if (match.group("minor")): - out_version += "." + match.group("minor") - - return out_version - - -def determine_merge_commit(current_branch="HEAD"): - """ - When running outside of CI, this will estimate the target merge commit hash - of `current_branch` by finding a common ancester with the remote branch - 'branch-{major}.{minor}' where {major} and {minor} are determined from the - repo version. - - Parameters - ---------- - current_branch : str, optional - Which branch to consider as the current branch, by default "HEAD" - - Returns - ------- - str - The common commit hash ID - """ - - try: - # Try to determine the target branch from the most recent tag - head_branch = __git("describe", - "--all", - "--tags", - "--match='branch-*'", - "--abbrev=0") - except subprocess.CalledProcessError: - print(" [DEBUG] Could not determine target branch from most recent " - "tag. Falling back to 'branch-{major}.{minor}.") - head_branch = None - - if (head_branch is not None): - # Convert from head to branch name - head_branch = __git("name-rev", "--name-only", head_branch) - else: - # Try and guess the target branch as "branch-." - version = repo_version_major_minor() - - if (version is None): - return None - - head_branch = "branch-{}".format(version) - - try: - # Now get the remote tracking branch - remote_branch = __git("rev-parse", - "--abbrev-ref", - "--symbolic-full-name", - head_branch + "@{upstream}") - except subprocess.CalledProcessError: - print(" [DEBUG] Could not remote tracking reference for " - f"branch {head_branch}.") - remote_branch = None - - if (remote_branch is None): - return None - - print(f" [DEBUG] Determined TARGET_BRANCH as: '{remote_branch}'. " - "Finding common ancestor.") - - common_commit = __git("merge-base", remote_branch, current_branch) - - return common_commit - - -def uncommittedFiles(): - """ - Returns a list of all changed files that are not yet committed. This - means both untracked/unstaged as well as uncommitted files too. - """ - files = __git("status", "-u", "-s") - ret = [] - for f in files.splitlines(): - f = f.strip(" ") - f = re.sub("\s+", " ", f) # noqa: W605 - tmp = f.split(" ", 1) - # only consider staged files or uncommitted files - # in other words, ignore untracked files - if tmp[0] == "M" or tmp[0] == "A": - ret.append(tmp[1]) - return ret - - -def changedFilesBetween(baseName, branchName, commitHash): - """ - Returns a list of files changed between branches baseName and latest commit - of branchName. - """ - current = branch() - # checkout "base" branch - __git("checkout", "--force", baseName) - # checkout branch for comparing - __git("checkout", "--force", branchName) - # checkout latest commit from branch - __git("checkout", "-fq", commitHash) - - files = __gitdiff("--name-only", - "--ignore-submodules", - f"{baseName}..{branchName}") - - # restore the original branch - __git("checkout", "--force", current) - return files.splitlines() - - -def changesInFileBetween(file, b1, b2, filter=None): - """Filters the changed lines to a file between the branches b1 and b2""" - current = branch() - __git("checkout", "--quiet", b1) - __git("checkout", "--quiet", b2) - diffs = __gitdiff("--ignore-submodules", - "-w", - "--minimal", - "-U0", - "%s...%s" % (b1, b2), - "--", - file) - __git("checkout", "--quiet", current) - lines = [] - for line in diffs.splitlines(): - if filter is None or filter(line): - lines.append(line) - return lines - - -def modifiedFiles(pathFilter=None): - """ - If inside a CI-env (ie. TARGET_BRANCH and COMMIT_HASH are defined, and - current branch is "current-pr-branch"), then lists out all files modified - between these 2 branches. Locally, TARGET_BRANCH will try to be determined - from the current repo version and finding a coresponding branch named - 'branch-{major}.{minor}'. If this fails, this functino will list out all - the uncommitted files in the current branch. - - Such utility function is helpful while putting checker scripts as part of - cmake, as well as CI process. This way, during development, only the files - touched (but not yet committed) by devs can be checked. But, during the CI - process ALL files modified by the dev, as submiited in the PR, will be - checked. This happens, all the while using the same script. - """ - targetBranch = os.environ.get("TARGET_BRANCH") - commitHash = os.environ.get("COMMIT_HASH") - currentBranch = branch() - print( - f" [DEBUG] TARGET_BRANCH={targetBranch}, COMMIT_HASH={commitHash}, " - f"currentBranch={currentBranch}") - - if targetBranch and commitHash and (currentBranch == "current-pr-branch"): - print(" [DEBUG] Assuming a CI environment.") - allFiles = changedFilesBetween(targetBranch, currentBranch, commitHash) - else: - print(" [DEBUG] Did not detect CI environment. " - "Determining TARGET_BRANCH locally.") - - common_commit = determine_merge_commit(currentBranch) - - if (common_commit is not None): - - # Now get the diff. Use --staged to get both diff between - # common_commit..HEAD and any locally staged files - allFiles = __gitdiff("--name-only", - "--ignore-submodules", - "--staged", - f"{common_commit}").splitlines() - else: - # Fallback to just uncommitted files - allFiles = uncommittedFiles() - - files = [] - for f in allFiles: - if pathFilter is None or pathFilter(f): - files.append(f) - - filesToCheckString = "\n\t".join(files) if files else "" - print(f" [DEBUG] Found files to check:\n\t{filesToCheckString}\n") - return files - - -def listAllFilesInDir(folder): - """Utility function to list all files/subdirs in the input folder""" - allFiles = [] - for root, dirs, files in os.walk(folder): - for name in files: - allFiles.append(os.path.join(root, name)) - return allFiles - - -def listFilesToCheck(filesDirs, filter=None): - """ - Utility function to filter the input list of files/dirs based on the input - filter method and returns all the files that need to be checked - """ - allFiles = [] - for f in filesDirs: - if os.path.isfile(f): - if filter is None or filter(f): - allFiles.append(f) - elif os.path.isdir(f): - files = listAllFilesInDir(f) - for f_ in files: - if filter is None or filter(f_): - allFiles.append(f_) - return allFiles diff --git a/cpp/scripts/run-clang-format.py b/cpp/scripts/run-clang-format.py deleted file mode 100644 index 46b027f3c06..00000000000 --- a/cpp/scripts/run-clang-format.py +++ /dev/null @@ -1,141 +0,0 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -from __future__ import print_function -import sys -import re -import os -import subprocess -import argparse -import tempfile - - -EXPECTED_VERSION = "11.1.0" -VERSION_REGEX = re.compile(r"clang-format version ([0-9.]+)") -# NOTE: populate this list with more top-level dirs as we add more of them to the cugraph repo -DEFAULT_DIRS = ["cpp/include", - "cpp/src", - "cpp/tests"] - - -def parse_args(): - argparser = argparse.ArgumentParser("Runs clang-format on a project") - argparser.add_argument("-dstdir", type=str, default=None, - help="Directory to store the temporary outputs of" - " clang-format. If nothing is passed for this, then" - " a temporary dir will be created using `mkdtemp`") - argparser.add_argument("-exe", type=str, default="clang-format", - help="Path to clang-format exe") - argparser.add_argument("-inplace", default=False, action="store_true", - help="Replace the source files itself.") - argparser.add_argument("-regex", type=str, - default=r"[.](cu|cuh|h|hpp|cpp)$", - help="Regex string to filter in sources") - argparser.add_argument("-ignore", type=str, default=r"cannylab/bh[.]cu$", - help="Regex used to ignore files from matched list") - argparser.add_argument("-v", dest="verbose", action="store_true", - help="Print verbose messages") - argparser.add_argument("dirs", type=str, nargs="*", - help="List of dirs where to find sources") - args = argparser.parse_args() - args.regex_compiled = re.compile(args.regex) - args.ignore_compiled = re.compile(args.ignore) - if args.dstdir is None: - args.dstdir = tempfile.mkdtemp() - ret = subprocess.check_output("%s --version" % args.exe, shell=True) - ret = ret.decode("utf-8") - version = VERSION_REGEX.match(ret) - if version is None: - raise Exception("Failed to figure out clang-format version!") - version = version.group(1) - if version != EXPECTED_VERSION: - raise Exception("clang-format exe must be v%s found '%s'" % \ - (EXPECTED_VERSION, version)) - if len(args.dirs) == 0: - args.dirs = DEFAULT_DIRS - return args - - -def list_all_src_files(file_regex, ignore_regex, srcdirs, dstdir, inplace): - allFiles = [] - for srcdir in srcdirs: - for root, dirs, files in os.walk(srcdir): - for f in files: - if re.search(file_regex, f): - src = os.path.join(root, f) - if re.search(ignore_regex, src): - continue - if inplace: - _dir = root - else: - _dir = os.path.join(dstdir, root) - dst = os.path.join(_dir, f) - allFiles.append((src, dst)) - return allFiles - - -def run_clang_format(src, dst, exe, verbose): - dstdir = os.path.dirname(dst) - if not os.path.exists(dstdir): - os.makedirs(dstdir) - # run the clang format command itself - if src == dst: - cmd = "%s -i %s" % (exe, src) - else: - cmd = "%s %s > %s" % (exe, src, dst) - try: - subprocess.check_call(cmd, shell=True) - except subprocess.CalledProcessError: - print("Failed to run clang-format! Maybe your env is not proper?") - raise - # run the diff to check if there are any formatting issues - cmd = "diff -q %s %s >/dev/null" % (src, dst) - try: - subprocess.check_call(cmd, shell=True) - if verbose: - print("%s passed" % os.path.basename(src)) - except subprocess.CalledProcessError: - print("%s failed! 'diff %s %s' will show formatting violations!" % \ - (os.path.basename(src), src, dst)) - return False - return True - - -def main(): - args = parse_args() - # Attempt to making sure that we run this script from root of repo always - if not os.path.exists(".git"): - print("Error!! This needs to always be run from the root of repo") - sys.exit(-1) - all_files = list_all_src_files(args.regex_compiled, args.ignore_compiled, - args.dirs, args.dstdir, args.inplace) - # actual format checker - status = True - for src, dst in all_files: - if not run_clang_format(src, dst, args.exe, args.verbose): - status = False - if not status: - print("clang-format failed! You have 2 options:") - print(" 1. Look at formatting differences above and fix them manually") - print(" 2. Or run the below command to bulk-fix all these at once") - print("Bulk-fix command: ") - print(" python cpp/scripts/run-clang-format.py %s -inplace" % \ - " ".join(sys.argv[1:])) - sys.exit(-1) - return - - -if __name__ == "__main__": - main() diff --git a/python/.flake8 b/python/.flake8 deleted file mode 100644 index 5a49c87c04b..00000000000 --- a/python/.flake8 +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright (c) 2020, NVIDIA CORPORATION. - -[flake8] -exclude = img,notebooks,thirdparty,__init__.py,libgdf -# https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#flake8 -max-line-length = 88 -extend-ignore = E203 diff --git a/python/cugraph/cugraph/tests/test_property_graph.py b/python/cugraph/cugraph/tests/test_property_graph.py index b116dbe9743..86e84d75367 100644 --- a/python/cugraph/cugraph/tests/test_property_graph.py +++ b/python/cugraph/cugraph/tests/test_property_graph.py @@ -1866,9 +1866,10 @@ def test_add_data_noncontiguous(df_type): @pytest.mark.parametrize("df_type", df_types, ids=df_type_id) def test_vertex_ids_different_type(df_type): - """Getting the number of vertices requires combining vertex ids from multiples columns. + """Getting the number of vertices requires combining vertex ids from + multiple columns. - This tests ensures combining these columns works even if they are different types. + This test ensures combining these columns works even if they are different types. """ from cugraph.experimental import PropertyGraph diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000000..1d917da6bd2 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,25 @@ +# Copyright (c) 2022, NVIDIA CORPORATION. + +[flake8] +filename = *.py, *.pyx, *.pxd, *.pxi +exclude = __init__.py, *.egg, build, docs, .git +force-check = True +max-line-length = 88 +ignore = + # line break before binary operator + W503, + # whitespace before : + E203 +per-file-ignores = + # Rules ignored only in Cython: + # E211: whitespace before '(' (used in multi-line imports) + # E225: Missing whitespace around operators (breaks cython casting syntax like ) + # E226: Missing whitespace around arithmetic operators (breaks cython pointer syntax like int*) + # E227: Missing whitespace around bitwise or shift operator (Can also break casting syntax) + # E275: Missing whitespace after keyword (Doesn't work with Cython except?) + # E402: invalid syntax (works for Python, not Cython) + # E999: invalid syntax (works for Python, not Cython) + # W504: line break after binary operator (breaks lines that end with a pointer) + *.pyx: E211, E225, E226, E227, E275, E402, E999, W504 + *.pxd: E211, E225, E226, E227, E275, E402, E999, W504 + *.pxi: E211, E225, E226, E227, E275, E402, E999, W504 From 9825b90c70d1c4ddf525b41c5d402e4bcaf9a5b1 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Thu, 8 Dec 2022 00:45:06 -0600 Subject: [PATCH 2/8] Apply clang-format to tests and libcugraph_etl. --- .pre-commit-config.yaml | 12 ++--- .../include/hash/concurrent_unordered_map.cuh | 4 +- cpp/libcugraph_etl/src/renumbering.cu | 4 +- cpp/tests/c_api/betweenness_centrality_test.c | 4 +- cpp/tests/c_api/bfs_test.c | 6 +-- cpp/tests/c_api/core_number_test.c | 3 +- .../c_api/create_sg_graph_envelope_test.c | 4 +- cpp/tests/c_api/edge_betweenness_centrality.c | 14 ++--- cpp/tests/c_api/egonet_test.c | 12 +++-- cpp/tests/c_api/hits_test.c | 12 ++++- .../c_api/mg_betweenness_centrality_test.c | 4 +- cpp/tests/c_api/mg_core_number_test.c | 3 +- cpp/tests/c_api/mg_create_graph_test.c | 2 +- .../c_api/mg_edge_betweenness_centrality.c | 16 +++--- cpp/tests/c_api/mg_egonet_test.c | 18 +++---- .../c_api/mg_eigenvector_centrality_test.c | 14 ++--- cpp/tests/c_api/mg_induced_subgraph_test.c | 23 ++++---- cpp/tests/c_api/mg_katz_test.c | 6 +-- cpp/tests/c_api/mg_pagerank_test.c | 21 +++++--- cpp/tests/c_api/mg_random_walks_test.c | 9 ++-- cpp/tests/c_api/mg_similarity_test.c | 12 ++--- cpp/tests/c_api/mg_sssp_test.c | 52 +++++++++---------- .../mg_strongly_connected_components_test.c | 3 +- cpp/tests/c_api/mg_triangle_count_test.c | 2 +- cpp/tests/c_api/node2vec_test.c | 41 ++++++++++----- cpp/tests/c_api/random_walks_test.c | 12 ++--- cpp/tests/c_api/sg_random_walks_test.c | 9 ++-- cpp/tests/c_api/sssp_test.c | 30 +++++------ .../strongly_connected_components_test.c | 3 +- cpp/tests/c_api/triangle_count_test.c | 3 +- 30 files changed, 191 insertions(+), 167 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5c158d15551..24136489a7f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,12 +32,12 @@ repos: - id: yesqa additional_dependencies: - flake8==6.0.0 -# - repo: https://github.com/pre-commit/mirrors-clang-format -# rev: v11.1.0 -# hooks: -# - id: clang-format -# types_or: [c, c++, cuda] -# args: ["-fallback-style=none", "-style=file", "-i"] + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v11.1.0 + hooks: + - id: clang-format + types_or: [c, c++, cuda] + args: ["-fallback-style=none", "-style=file", "-i"] - repo: local hooks: - id: copyright-check diff --git a/cpp/libcugraph_etl/include/hash/concurrent_unordered_map.cuh b/cpp/libcugraph_etl/include/hash/concurrent_unordered_map.cuh index c48ee2fb792..c50e4a0da9c 100644 --- a/cpp/libcugraph_etl/include/hash/concurrent_unordered_map.cuh +++ b/cpp/libcugraph_etl/include/hash/concurrent_unordered_map.cuh @@ -14,9 +14,9 @@ * limitations under the License. */ - /* +/* * FIXME: This file is copied from cudf because CuCollections doesnt support concurrent - * insert/find for 8 byte key-value pair size. The plan is to migrate to + * insert/find for 8 byte key-value pair size. The plan is to migrate to * using the cuco when the feature is supported. At that point this file can be deleted. */ #pragma once diff --git a/cpp/libcugraph_etl/src/renumbering.cu b/cpp/libcugraph_etl/src/renumbering.cu index 89c8bd3d792..683c7823f7c 100644 --- a/cpp/libcugraph_etl/src/renumbering.cu +++ b/cpp/libcugraph_etl/src/renumbering.cu @@ -793,8 +793,8 @@ struct renumber_functor { cudaStream_t exec_strm = handle.get_stream(); - auto mr = rmm::mr::new_delete_resource(); - size_t hist_size = sizeof(accum_type) * 32; + auto mr = rmm::mr::new_delete_resource(); + size_t hist_size = sizeof(accum_type) * 32; accum_type* hist_insert_counter = static_cast(mr.allocate(hist_size)); *hist_insert_counter = 0; diff --git a/cpp/tests/c_api/betweenness_centrality_test.c b/cpp/tests/c_api/betweenness_centrality_test.c index 5056fc09bc5..f201d631544 100644 --- a/cpp/tests/c_api/betweenness_centrality_test.c +++ b/cpp/tests/c_api/betweenness_centrality_test.c @@ -55,7 +55,9 @@ int generic_betweenness_centrality_test(vertex_t* h_src, ret_code = cugraph_betweenness_centrality( p_handle, p_graph, num_vertices_to_sample, NULL, FALSE, FALSE, FALSE, &p_result, &ret_error); #if 1 - TEST_ASSERT(test_ret_value, ret_code != CUGRAPH_SUCCESS, "cugraph_betweenness_centrality should have failed"); + TEST_ASSERT(test_ret_value, + ret_code != CUGRAPH_SUCCESS, + "cugraph_betweenness_centrality should have failed"); #else TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, cugraph_error_message(ret_error)); TEST_ASSERT( diff --git a/cpp/tests/c_api/bfs_test.c b/cpp/tests/c_api/bfs_test.c index e4eb4513f23..8feb426a853 100644 --- a/cpp/tests/c_api/bfs_test.c +++ b/cpp/tests/c_api/bfs_test.c @@ -123,9 +123,9 @@ int test_bfs_exceptions() size_t depth_limit = 1; size_t num_seeds = 1; - vertex_t src[] = {0, 1, 1, 2, 2, 2, 3, 4}; - vertex_t dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; - weight_t wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; + vertex_t src[] = {0, 1, 1, 2, 2, 2, 3, 4}; + vertex_t dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; + weight_t wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; int64_t seeds[] = {0}; int test_ret_value = 0; diff --git a/cpp/tests/c_api/core_number_test.c b/cpp/tests/c_api/core_number_test.c index c5837fd692b..0228bde5b1c 100644 --- a/cpp/tests/c_api/core_number_test.c +++ b/cpp/tests/c_api/core_number_test.c @@ -52,7 +52,8 @@ int generic_core_number_test(vertex_t* h_src, TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "create_test_graph failed."); TEST_ALWAYS_ASSERT(ret_code == CUGRAPH_SUCCESS, cugraph_error_message(ret_error)); - ret_code = cugraph_core_number(p_handle, p_graph, K_CORE_DEGREE_TYPE_IN, FALSE, &p_result, &ret_error); + ret_code = + cugraph_core_number(p_handle, p_graph, K_CORE_DEGREE_TYPE_IN, FALSE, &p_result, &ret_error); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "cugraph_core_number failed."); TEST_ALWAYS_ASSERT(ret_code == CUGRAPH_SUCCESS, cugraph_error_message(ret_error)); diff --git a/cpp/tests/c_api/create_sg_graph_envelope_test.c b/cpp/tests/c_api/create_sg_graph_envelope_test.c index 14a5ac3cf1c..c33839310a5 100644 --- a/cpp/tests/c_api/create_sg_graph_envelope_test.c +++ b/cpp/tests/c_api/create_sg_graph_envelope_test.c @@ -29,8 +29,8 @@ int test_create_sg_graph_simple() typedef float weight_t; cugraph_error_code_t ret_code = CUGRAPH_SUCCESS; - size_t num_edges = 8; - size_t num_vertices = 6; + size_t num_edges = 8; + size_t num_vertices = 6; vertex_t h_src[] = {0, 1, 1, 2, 2, 2, 3, 4}; vertex_t h_dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; diff --git a/cpp/tests/c_api/edge_betweenness_centrality.c b/cpp/tests/c_api/edge_betweenness_centrality.c index 75dbe464654..658ce5f2288 100644 --- a/cpp/tests/c_api/edge_betweenness_centrality.c +++ b/cpp/tests/c_api/edge_betweenness_centrality.c @@ -26,13 +26,13 @@ typedef int32_t edge_t; typedef float weight_t; int generic_edge_betweenness_centrality_test(vertex_t* h_src, - vertex_t* h_dst, - weight_t* h_wgt, - weight_t* h_result, - size_t num_vertices, - size_t num_edges, - bool_t store_transposed, - size_t num_vertices_to_sample) + vertex_t* h_dst, + weight_t* h_wgt, + weight_t* h_result, + size_t num_vertices, + size_t num_edges, + bool_t store_transposed, + size_t num_vertices_to_sample) { int test_ret_value = 0; diff --git a/cpp/tests/c_api/egonet_test.c b/cpp/tests/c_api/egonet_test.c index fac9815c150..3315373fdcb 100644 --- a/cpp/tests/c_api/egonet_test.c +++ b/cpp/tests/c_api/egonet_test.c @@ -128,15 +128,17 @@ int generic_egonet_test(vertex_t* h_src, weight_t M[num_vertices][num_vertices]; for (int i = 0; (i < num_seeds) && (test_ret_value == 0); ++i) { - for (int r = 0 ; r < num_vertices ; ++r) - for (int c = 0 ; c < num_vertices ; ++c) + for (int r = 0; r < num_vertices; ++r) + for (int c = 0; c < num_vertices; ++c) M[r][c] = 0; - for (size_t e = h_expected_offsets[i] ; e < h_expected_offsets[i+1] ; ++e) + for (size_t e = h_expected_offsets[i]; e < h_expected_offsets[i + 1]; ++e) M[h_expected_src[e]][h_expected_dst[e]] = 1; - for (size_t e = h_result_offsets[i] ; (e < h_result_offsets[i+1]) && (test_ret_value == 0) ; ++e) { - TEST_ASSERT(test_ret_value, (M[h_result_src[e]][h_result_dst[e]] > 0), "found different edges"); + for (size_t e = h_result_offsets[i]; (e < h_result_offsets[i + 1]) && (test_ret_value == 0); + ++e) { + TEST_ASSERT( + test_ret_value, (M[h_result_src[e]][h_result_dst[e]] > 0), "found different edges"); } } diff --git a/cpp/tests/c_api/hits_test.c b/cpp/tests/c_api/hits_test.c index c275d883d11..e8d4b98b7ab 100644 --- a/cpp/tests/c_api/hits_test.c +++ b/cpp/tests/c_api/hits_test.c @@ -53,8 +53,16 @@ int generic_hits_test(vertex_t* h_src, p_handle = cugraph_create_resource_handle(NULL); TEST_ASSERT(test_ret_value, p_handle != NULL, "resource handle creation failed."); - ret_code = create_test_graph( - p_handle, h_src, h_dst, h_wgt, num_edges, store_transposed, renumber, FALSE, &p_graph, &ret_error); + ret_code = create_test_graph(p_handle, + h_src, + h_dst, + h_wgt, + num_edges, + store_transposed, + renumber, + FALSE, + &p_graph, + &ret_error); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "create_test_graph failed."); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, cugraph_error_message(ret_error)); diff --git a/cpp/tests/c_api/mg_betweenness_centrality_test.c b/cpp/tests/c_api/mg_betweenness_centrality_test.c index c9a714c4bf4..d48139177ad 100644 --- a/cpp/tests/c_api/mg_betweenness_centrality_test.c +++ b/cpp/tests/c_api/mg_betweenness_centrality_test.c @@ -51,7 +51,9 @@ int generic_betweenness_centrality_test(const cugraph_resource_handle_t* handle, ret_code = cugraph_betweenness_centrality( handle, p_graph, num_vertices_to_sample, NULL, FALSE, FALSE, FALSE, &p_result, &ret_error); #if 1 - TEST_ASSERT(test_ret_value, ret_code != CUGRAPH_SUCCESS, "cugraph_betweenness_centrality should have failed"); + TEST_ASSERT(test_ret_value, + ret_code != CUGRAPH_SUCCESS, + "cugraph_betweenness_centrality should have failed"); #else TEST_ASSERT( test_ret_value, ret_code == CUGRAPH_SUCCESS, "cugraph_betweenness_centrality failed."); diff --git a/cpp/tests/c_api/mg_core_number_test.c b/cpp/tests/c_api/mg_core_number_test.c index 6b34effe183..8e53cb855d6 100644 --- a/cpp/tests/c_api/mg_core_number_test.c +++ b/cpp/tests/c_api/mg_core_number_test.c @@ -48,7 +48,8 @@ int generic_core_number_test(const cugraph_resource_handle_t* p_handle, TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "create_test_graph failed."); TEST_ALWAYS_ASSERT(ret_code == CUGRAPH_SUCCESS, cugraph_error_message(ret_error)); - ret_code = cugraph_core_number(p_handle, p_graph, K_CORE_DEGREE_TYPE_IN, FALSE, &p_result, &ret_error); + ret_code = + cugraph_core_number(p_handle, p_graph, K_CORE_DEGREE_TYPE_IN, FALSE, &p_result, &ret_error); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "cugraph_core_number failed."); TEST_ALWAYS_ASSERT(ret_code == CUGRAPH_SUCCESS, cugraph_error_message(ret_error)); diff --git a/cpp/tests/c_api/mg_create_graph_test.c b/cpp/tests/c_api/mg_create_graph_test.c index cc98dd982e0..67534f16fa3 100644 --- a/cpp/tests/c_api/mg_create_graph_test.c +++ b/cpp/tests/c_api/mg_create_graph_test.c @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "c_test_utils.h" /* RUN_TEST */ +#include "c_test_utils.h" /* RUN_TEST */ #include "mg_test_utils.h" /* RUN_TEST */ #include diff --git a/cpp/tests/c_api/mg_edge_betweenness_centrality.c b/cpp/tests/c_api/mg_edge_betweenness_centrality.c index 24e109f2f49..9431b3f5908 100644 --- a/cpp/tests/c_api/mg_edge_betweenness_centrality.c +++ b/cpp/tests/c_api/mg_edge_betweenness_centrality.c @@ -26,14 +26,14 @@ typedef int32_t edge_t; typedef float weight_t; int generic_edge_betweenness_centrality_test(const cugraph_resource_handle_t* handle, - vertex_t* h_src, - vertex_t* h_dst, - weight_t* h_wgt, - weight_t* h_result, - size_t num_vertices, - size_t num_edges, - bool_t store_transposed, - size_t num_vertices_to_sample) + vertex_t* h_src, + vertex_t* h_dst, + weight_t* h_wgt, + weight_t* h_result, + size_t num_vertices, + size_t num_edges, + bool_t store_transposed, + size_t num_vertices_to_sample) { int test_ret_value = 0; diff --git a/cpp/tests/c_api/mg_egonet_test.c b/cpp/tests/c_api/mg_egonet_test.c index 8f0dda42a57..4b8a4ae3533 100644 --- a/cpp/tests/c_api/mg_egonet_test.c +++ b/cpp/tests/c_api/mg_egonet_test.c @@ -68,9 +68,7 @@ int generic_egonet_test(const cugraph_resource_handle_t* resource_handle, TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "create_test_graph failed."); TEST_ALWAYS_ASSERT(ret_code == CUGRAPH_SUCCESS, cugraph_error_message(ret_error)); - if (rank != 0) { - num_seeds = 0; - } + if (rank != 0) { num_seeds = 0; } ret_code = cugraph_type_erased_device_array_create(resource_handle, num_seeds, INT32, &seeds, &ret_error); @@ -134,15 +132,17 @@ int generic_egonet_test(const cugraph_resource_handle_t* resource_handle, weight_t M[num_vertices][num_vertices]; for (int i = 0; (i < num_seeds) && (test_ret_value == 0); ++i) { - for (int r = 0 ; r < num_vertices ; ++r) - for (int c = 0 ; c < num_vertices ; ++c) + for (int r = 0; r < num_vertices; ++r) + for (int c = 0; c < num_vertices; ++c) M[r][c] = 0; - for (size_t e = h_expected_offsets[i] ; e < h_expected_offsets[i+1] ; ++e) + for (size_t e = h_expected_offsets[i]; e < h_expected_offsets[i + 1]; ++e) M[h_expected_src[e]][h_expected_dst[e]] = 1; - for (size_t e = h_result_offsets[i] ; (e < h_result_offsets[i+1]) && (test_ret_value == 0) ; ++e) { - TEST_ASSERT(test_ret_value, (M[h_result_src[e]][h_result_dst[e]] > 0), "found different edges"); + for (size_t e = h_result_offsets[i]; (e < h_result_offsets[i + 1]) && (test_ret_value == 0); + ++e) { + TEST_ASSERT( + test_ret_value, (M[h_result_src[e]][h_result_dst[e]] > 0), "found different edges"); } } @@ -159,7 +159,7 @@ int generic_egonet_test(const cugraph_resource_handle_t* resource_handle, return test_ret_value; } -int test_egonet(const cugraph_resource_handle_t *resource_handle) +int test_egonet(const cugraph_resource_handle_t* resource_handle) { size_t num_edges = 9; size_t num_vertices = 6; diff --git a/cpp/tests/c_api/mg_eigenvector_centrality_test.c b/cpp/tests/c_api/mg_eigenvector_centrality_test.c index 56a5c3911a2..3cb5fec46ef 100644 --- a/cpp/tests/c_api/mg_eigenvector_centrality_test.c +++ b/cpp/tests/c_api/mg_eigenvector_centrality_test.c @@ -101,20 +101,12 @@ int test_eigenvector_centrality(const cugraph_resource_handle_t* handle) 0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f, 0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; weight_t h_result[] = {0.236374, 0.292046, 0.458369, 0.605472, 0.190544, 0.495814}; - double epsilon = 1e-6; + double epsilon = 1e-6; size_t max_iterations = 200; // Eigenvector centrality wants store_transposed = TRUE - return generic_eigenvector_centrality_test(handle, - h_src, - h_dst, - h_wgt, - h_result, - num_vertices, - num_edges, - TRUE, - epsilon, - max_iterations); + return generic_eigenvector_centrality_test( + handle, h_src, h_dst, h_wgt, h_result, num_vertices, num_edges, TRUE, epsilon, max_iterations); } /******************************************************************************/ diff --git a/cpp/tests/c_api/mg_induced_subgraph_test.c b/cpp/tests/c_api/mg_induced_subgraph_test.c index 6d902cc7bae..448c7c5126b 100644 --- a/cpp/tests/c_api/mg_induced_subgraph_test.c +++ b/cpp/tests/c_api/mg_induced_subgraph_test.c @@ -57,9 +57,9 @@ int generic_induced_subgraph_test(const cugraph_resource_handle_t* handle, cugraph_induced_subgraph_result_t* result = NULL; - data_type_id_t vertex_tid = INT32; - data_type_id_t size_t_tid = SIZE_T; - size_t num_subgraph_vertices = h_subgraph_offsets[num_subgraph_offsets-1]; + data_type_id_t vertex_tid = INT32; + data_type_id_t size_t_tid = SIZE_T; + size_t num_subgraph_vertices = h_subgraph_offsets[num_subgraph_offsets - 1]; ret_code = create_mg_test_graph( handle, h_src, h_dst, h_wgt, num_edges, store_transposed, FALSE, &graph, &ret_error); @@ -69,7 +69,7 @@ int generic_induced_subgraph_test(const cugraph_resource_handle_t* handle, if (cugraph_resource_handle_get_rank(handle) != 0) { num_subgraph_vertices = 0; - for (int i = 0 ; i < num_subgraph_offsets ; ++i) { + for (int i = 0; i < num_subgraph_offsets; ++i) { h_subgraph_offsets[i] = 0; } } @@ -78,11 +78,8 @@ int generic_induced_subgraph_test(const cugraph_resource_handle_t* handle, handle, num_subgraph_offsets, size_t_tid, &subgraph_offsets, &ret_error); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "subgraph_offsets create failed."); - ret_code = cugraph_type_erased_device_array_create(handle, - num_subgraph_vertices, - vertex_tid, - &subgraph_vertices, - &ret_error); + ret_code = cugraph_type_erased_device_array_create( + handle, num_subgraph_vertices, vertex_tid, &subgraph_vertices, &ret_error); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "subgraph_offsets create failed."); subgraph_offsets_view = cugraph_type_erased_device_array_view(subgraph_offsets); @@ -102,7 +99,7 @@ int generic_induced_subgraph_test(const cugraph_resource_handle_t* handle, graph, subgraph_offsets_view, subgraph_vertices_view, - //FALSE, + // FALSE, TRUE, &result, &ret_error); @@ -115,9 +112,9 @@ int generic_induced_subgraph_test(const cugraph_resource_handle_t* handle, cugraph_type_erased_device_array_view_t* extracted_wgt; cugraph_type_erased_device_array_view_t* extracted_graph_offsets; - extracted_src = cugraph_induced_subgraph_get_sources(result); - extracted_dst = cugraph_induced_subgraph_get_destinations(result); - extracted_wgt = cugraph_induced_subgraph_get_edge_weights(result); + extracted_src = cugraph_induced_subgraph_get_sources(result); + extracted_dst = cugraph_induced_subgraph_get_destinations(result); + extracted_wgt = cugraph_induced_subgraph_get_edge_weights(result); extracted_graph_offsets = cugraph_induced_subgraph_get_subgraph_offsets(result); size_t extracted_size = cugraph_type_erased_device_array_view_size(extracted_src); diff --git a/cpp/tests/c_api/mg_katz_test.c b/cpp/tests/c_api/mg_katz_test.c index ca2de1bb194..0f7e95bd69d 100644 --- a/cpp/tests/c_api/mg_katz_test.c +++ b/cpp/tests/c_api/mg_katz_test.c @@ -43,8 +43,8 @@ int generic_katz_test(const cugraph_resource_handle_t* handle, cugraph_error_code_t ret_code = CUGRAPH_SUCCESS; cugraph_error_t* ret_error; - cugraph_graph_t* p_graph = NULL; - cugraph_centrality_result_t* p_result = NULL; + cugraph_graph_t* p_graph = NULL; + cugraph_centrality_result_t* p_result = NULL; cugraph_type_erased_device_array_view_t* betas_view = NULL; ret_code = create_mg_test_graph( @@ -71,7 +71,7 @@ int generic_katz_test(const cugraph_resource_handle_t* handle, cugraph_type_erased_device_array_view_t* vertices; cugraph_type_erased_device_array_view_t* centralities; - vertices = cugraph_centrality_result_get_vertices(p_result); + vertices = cugraph_centrality_result_get_vertices(p_result); centralities = cugraph_centrality_result_get_values(p_result); vertex_t h_vertices[num_vertices]; diff --git a/cpp/tests/c_api/mg_pagerank_test.c b/cpp/tests/c_api/mg_pagerank_test.c index 8ac0c3070f5..e005b53d709 100644 --- a/cpp/tests/c_api/mg_pagerank_test.c +++ b/cpp/tests/c_api/mg_pagerank_test.c @@ -50,8 +50,18 @@ int generic_pagerank_test(const cugraph_resource_handle_t* handle, TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "create_mg_test_graph failed."); - ret_code = cugraph_pagerank( - handle, p_graph, NULL, NULL, NULL, NULL, alpha, epsilon, max_iterations, FALSE, &p_result, &ret_error); + ret_code = cugraph_pagerank(handle, + p_graph, + NULL, + NULL, + NULL, + NULL, + alpha, + epsilon, + max_iterations, + FALSE, + &p_result, + &ret_error); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "cugraph_pagerank failed."); // NOTE: Because we get back vertex ids and pageranks, we can simply compare @@ -90,7 +100,7 @@ int generic_pagerank_test(const cugraph_resource_handle_t* handle, return test_ret_value; } -int generic_personalized_pagerank_test(const cugraph_resource_handle_t *handle, +int generic_personalized_pagerank_test(const cugraph_resource_handle_t* handle, vertex_t* h_src, vertex_t* h_dst, weight_t* h_wgt, @@ -126,9 +136,7 @@ int generic_personalized_pagerank_test(const cugraph_resource_handle_t *handle, TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "create_test_graph failed."); TEST_ALWAYS_ASSERT(ret_code == CUGRAPH_SUCCESS, cugraph_error_message(ret_error)); - if (cugraph_resource_handle_get_rank(handle) != 0) { - num_personalization_vertices = 0; - } + if (cugraph_resource_handle_get_rank(handle) != 0) { num_personalization_vertices = 0; } ret_code = cugraph_type_erased_device_array_create( handle, num_personalization_vertices, vertex_tid, &personalization_vertices, &ret_error); @@ -201,7 +209,6 @@ int generic_personalized_pagerank_test(const cugraph_resource_handle_t *handle, return test_ret_value; } - int test_pagerank(const cugraph_resource_handle_t* handle) { size_t num_edges = 8; diff --git a/cpp/tests/c_api/mg_random_walks_test.c b/cpp/tests/c_api/mg_random_walks_test.c index 753f7c8a89b..63ca7cfc167 100644 --- a/cpp/tests/c_api/mg_random_walks_test.c +++ b/cpp/tests/c_api/mg_random_walks_test.c @@ -121,11 +121,10 @@ int generic_uniform_random_walks_test(const cugraph_resource_handle_t* handle, "uniform_random_walks found no edge when an edge exists"); } } else { - TEST_ASSERT( - test_ret_value, - M[h_result_verts[src_index]][h_result_verts[dst_index]] == - h_result_wgts[i * max_depth + j], - "uniform_random_walks got edge that doesn't exist"); + TEST_ASSERT(test_ret_value, + M[h_result_verts[src_index]][h_result_verts[dst_index]] == + h_result_wgts[i * max_depth + j], + "uniform_random_walks got edge that doesn't exist"); } } } diff --git a/cpp/tests/c_api/mg_similarity_test.c b/cpp/tests/c_api/mg_similarity_test.c index 5f6c8881127..e94b62b3ffd 100644 --- a/cpp/tests/c_api/mg_similarity_test.c +++ b/cpp/tests/c_api/mg_similarity_test.c @@ -42,7 +42,7 @@ int generic_similarity_test(const cugraph_resource_handle_t* handle, bool_t use_weight, similarity_t test_type) { - int test_ret_value = 0; + int test_ret_value = 0; data_type_id_t vertex_tid = INT32; cugraph_error_code_t ret_code = CUGRAPH_SUCCESS; @@ -62,9 +62,7 @@ int generic_similarity_test(const cugraph_resource_handle_t* handle, TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "create_test_graph failed."); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, cugraph_error_message(ret_error)); - if (cugraph_resource_handle_get_rank(handle) != 0) { - num_pairs = 0; - } + if (cugraph_resource_handle_get_rank(handle) != 0) { num_pairs = 0; } ret_code = cugraph_type_erased_device_array_create(handle, num_pairs, vertex_tid, &v1, &ret_error); @@ -328,9 +326,9 @@ int main(int argc, char** argv) result |= RUN_MG_TEST(test_jaccard, handle); result |= RUN_MG_TEST(test_sorensen, handle); result |= RUN_MG_TEST(test_overlap, handle); - //result |= RUN_MG_TEST(test_weighted_jaccard, handle); - //result |= RUN_MG_TEST(test_weighted_sorensen, handle); - //result |= RUN_MG_TEST(test_weighted_overlap, handle); + // result |= RUN_MG_TEST(test_weighted_jaccard, handle); + // result |= RUN_MG_TEST(test_weighted_sorensen, handle); + // result |= RUN_MG_TEST(test_weighted_overlap, handle); cugraph_free_resource_handle(handle); } diff --git a/cpp/tests/c_api/mg_sssp_test.c b/cpp/tests/c_api/mg_sssp_test.c index 6392addc397..3cfab05550c 100644 --- a/cpp/tests/c_api/mg_sssp_test.c +++ b/cpp/tests/c_api/mg_sssp_test.c @@ -101,16 +101,16 @@ int generic_sssp_test(const cugraph_resource_handle_t* p_handle, } int generic_sssp_test_double(const cugraph_resource_handle_t* p_handle, - vertex_t* h_src, - vertex_t* h_dst, - double* h_wgt, - vertex_t source, - double const* expected_distances, - vertex_t const* expected_predecessors, - size_t num_vertices, - size_t num_edges, - double cutoff, - bool_t store_transposed) + vertex_t* h_src, + vertex_t* h_dst, + double* h_wgt, + vertex_t source, + double const* expected_distances, + vertex_t const* expected_predecessors, + size_t num_vertices, + size_t num_edges, + double cutoff, + bool_t store_transposed) { int test_ret_value = 0; @@ -180,8 +180,8 @@ int test_sssp(const cugraph_resource_handle_t* p_handle) vertex_t src[] = {0, 1, 1, 2, 2, 2, 3, 4}; vertex_t dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; - float wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; - float expected_distances[] = {0.0f, 0.1f, FLT_MAX, 2.2f, 1.2f, 4.4f}; + float wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; + float expected_distances[] = {0.0f, 0.1f, FLT_MAX, 2.2f, 1.2f, 4.4f}; vertex_t expected_predecessors[] = {-1, 0, -1, 1, 1, 4}; // Bfs wants store_transposed = FALSE @@ -205,8 +205,8 @@ int test_sssp_with_transpose(const cugraph_resource_handle_t* p_handle) vertex_t src[] = {0, 1, 1, 2, 2, 2, 3, 4}; vertex_t dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; - float wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; - float expected_distances[] = {0.0f, 0.1f, FLT_MAX, 2.2f, 1.2f, 4.4f}; + float wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; + float expected_distances[] = {0.0f, 0.1f, FLT_MAX, 2.2f, 1.2f, 4.4f}; vertex_t expected_predecessors[] = {-1, 0, -1, 1, 1, 4}; // Bfs wants store_transposed = FALSE @@ -231,23 +231,23 @@ int test_sssp_with_transpose_double(const cugraph_resource_handle_t* p_handle) vertex_t src[] = {0, 1, 1, 2, 2, 2, 3, 4}; vertex_t dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; - double wgt[] = {0.1d, 2.1d, 1.1d, 5.1d, 3.1d, 4.1d, 7.2d, 3.2d}; - double expected_distances[] = {0.0d, 0.1d, DBL_MAX, 2.2d, 1.2d, 4.4d}; + double wgt[] = {0.1d, 2.1d, 1.1d, 5.1d, 3.1d, 4.1d, 7.2d, 3.2d}; + double expected_distances[] = {0.0d, 0.1d, DBL_MAX, 2.2d, 1.2d, 4.4d}; vertex_t expected_predecessors[] = {-1, 0, -1, 1, 1, 4}; // Bfs wants store_transposed = FALSE // This call will force cugraph_sssp to transpose the graph return generic_sssp_test_double(p_handle, - src, - dst, - wgt, - 0, - expected_distances, - expected_predecessors, - num_vertices, - num_edges, - 10, - TRUE); + src, + dst, + wgt, + 0, + expected_distances, + expected_predecessors, + num_vertices, + num_edges, + 10, + TRUE); } /******************************************************************************/ diff --git a/cpp/tests/c_api/mg_strongly_connected_components_test.c b/cpp/tests/c_api/mg_strongly_connected_components_test.c index f7659b8023a..894b6996303 100644 --- a/cpp/tests/c_api/mg_strongly_connected_components_test.c +++ b/cpp/tests/c_api/mg_strongly_connected_components_test.c @@ -48,7 +48,8 @@ int generic_scc_test(const cugraph_resource_handle_t* handle, TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "create_mg_test_graph failed."); ret_code = cugraph_strongly_connected_components(handle, p_graph, FALSE, &p_result, &ret_error); - TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_NOT_IMPLEMENTED, "SCC should not be implemented, but is"); + TEST_ASSERT( + test_ret_value, ret_code == CUGRAPH_NOT_IMPLEMENTED, "SCC should not be implemented, but is"); #if 0 // FIXME: Actual implementation will be something like this diff --git a/cpp/tests/c_api/mg_triangle_count_test.c b/cpp/tests/c_api/mg_triangle_count_test.c index 9b367f81b51..a5f7c61b3c4 100644 --- a/cpp/tests/c_api/mg_triangle_count_test.c +++ b/cpp/tests/c_api/mg_triangle_count_test.c @@ -95,7 +95,7 @@ int generic_triangle_count_test(const cugraph_resource_handle_t* handle, TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "copy_to_host failed."); for (int i = 0; (i < num_local_results) && (test_ret_value == 0); ++i) { - for (int j = 0 ; j < num_results ; ++j) { + for (int j = 0; j < num_results; ++j) { if (h_vertices[i] == h_verts[j]) { TEST_ASSERT(test_ret_value, h_counts[i] == h_result[j], "counts results don't match"); } diff --git a/cpp/tests/c_api/node2vec_test.c b/cpp/tests/c_api/node2vec_test.c index 701d4923fe1..574ed02e5a4 100644 --- a/cpp/tests/c_api/node2vec_test.c +++ b/cpp/tests/c_api/node2vec_test.c @@ -205,21 +205,36 @@ int test_node2vec_short_sparse() int test_node2vec_karate() { - size_t num_edges = 156; + size_t num_edges = 156; size_t num_vertices = 34; - vertex_t src[] = {1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 17, 19, 21, 31, 2, - 3, 7, 13, 17, 19, 21, 30, 3, 7, 8, 9, 13, 27, 28, 32, 7, 12, - 13, 6, 10, 6, 10, 16, 16, 30, 32, 33, 33, 33, 32, 33, 32, - 33, 32, 33, 33, 32, 33, 32, 33, 25, 27, 29, 32, 33, 25, 27, - 31, 31, 29, 33, 33, 31, 33, 32, 33, 32, 33, 32, 33, 33, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, - 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, - 8, 8, 8, 9, 13, 14, 14, 15, 15, 18, 18, 19, 20, 20, 22, 22, - 23, 23, 23, 23, 23, 24, 24, 24, 25, 26, 26, 27, 28, 28, 29, - 29, 30, 30, 31, 31, 32}; - vertex_t dst[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,4,4,5,5,5,6,8,8,8,9,13,14,14,15,15,18,18,19,20,20,22,22,23,23,23,23,23,24,24,24,25,26,26,27,28,28,29,29,30,30,31,31,32,1,2,3,4,5,6,7,8,10,11,12,13,17,19,21,31,2,3,7,13,17,19,21,30,3,7,8,9,13,27,28,32,7,12,13,6,10,6,10,16,16,30,32,33,33,33,32,33,32,33,32,33,33,32,33,32,33,25,27,29,32,33,25,27,31,31,29,33,33,31,33,32,33,32,33,32,33,33}; - weight_t wgt[] = {1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f}; + vertex_t src[] = {1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 17, 19, 21, 31, 2, 3, 7, 13, + 17, 19, 21, 30, 3, 7, 8, 9, 13, 27, 28, 32, 7, 12, 13, 6, 10, 6, 10, 16, + 16, 30, 32, 33, 33, 33, 32, 33, 32, 33, 32, 33, 33, 32, 33, 32, 33, 25, 27, 29, + 32, 33, 25, 27, 31, 31, 29, 33, 33, 31, 33, 32, 33, 32, 33, 32, 33, 33, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, + 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 8, + 8, 8, 9, 13, 14, 14, 15, 15, 18, 18, 19, 20, 20, 22, 22, 23, 23, 23, 23, 23, + 24, 24, 24, 25, 26, 26, 27, 28, 28, 29, 29, 30, 30, 31, 31, 32}; + vertex_t dst[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, + 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, + 6, 8, 8, 8, 9, 13, 14, 14, 15, 15, 18, 18, 19, 20, 20, 22, 22, 23, 23, 23, + 23, 23, 24, 24, 24, 25, 26, 26, 27, 28, 28, 29, 29, 30, 30, 31, 31, 32, 1, 2, + 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 17, 19, 21, 31, 2, 3, 7, 13, 17, 19, + 21, 30, 3, 7, 8, 9, 13, 27, 28, 32, 7, 12, 13, 6, 10, 6, 10, 16, 16, 30, + 32, 33, 33, 33, 32, 33, 32, 33, 32, 33, 33, 32, 33, 32, 33, 25, 27, 29, 32, 33, + 25, 27, 31, 31, 29, 33, 33, 31, 33, 32, 33, 32, 33, 32, 33, 33}; + weight_t wgt[] = { + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}; vertex_t seeds[] = {12, 28, 20, 23, 15, 26}; size_t max_depth = 5; diff --git a/cpp/tests/c_api/random_walks_test.c b/cpp/tests/c_api/random_walks_test.c index be500b2cd91..d40d74c77e6 100644 --- a/cpp/tests/c_api/random_walks_test.c +++ b/cpp/tests/c_api/random_walks_test.c @@ -39,8 +39,8 @@ int test_random_walks_1() typedef float weight_t; cugraph_error_code_t ret_code = CUGRAPH_SUCCESS; - size_t num_edges = 8; - size_t num_vertices = 6; + size_t num_edges = 8; + size_t num_vertices = 6; vertex_t h_src[] = {0, 1, 1, 2, 2, 2, 3, 4}; vertex_t h_dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; @@ -192,8 +192,8 @@ int test_random_walks_2() typedef float weight_t; cugraph_error_code_t ret_code = CUGRAPH_SUCCESS; - size_t num_edges = 8; - size_t num_vertices = 6; + size_t num_edges = 8; + size_t num_vertices = 6; vertex_t h_src[] = {0, 1, 1, 2, 2, 2, 3, 4}; vertex_t h_dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; @@ -319,8 +319,8 @@ int test_random_walks_3() typedef float weight_t; cugraph_error_code_t ret_code = CUGRAPH_SUCCESS; - size_t num_edges = 8; - size_t num_vertices = 6; + size_t num_edges = 8; + size_t num_vertices = 6; vertex_t h_src[] = {0, 1, 1, 2, 2, 2, 3, 4}; vertex_t h_dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; diff --git a/cpp/tests/c_api/sg_random_walks_test.c b/cpp/tests/c_api/sg_random_walks_test.c index 7b07967e3c9..225c71247e7 100644 --- a/cpp/tests/c_api/sg_random_walks_test.c +++ b/cpp/tests/c_api/sg_random_walks_test.c @@ -125,11 +125,10 @@ int generic_uniform_random_walks_test(vertex_t* h_src, "uniform_random_walks found no edge when an edge exists"); } } else { - TEST_ASSERT( - test_ret_value, - M[h_result_verts[src_index]][h_result_verts[dst_index]] == - h_result_wgts[i * max_depth + j], - "uniform_random_walks got edge that doesn't exist"); + TEST_ASSERT(test_ret_value, + M[h_result_verts[src_index]][h_result_verts[dst_index]] == + h_result_wgts[i * max_depth + j], + "uniform_random_walks got edge that doesn't exist"); } } } diff --git a/cpp/tests/c_api/sssp_test.c b/cpp/tests/c_api/sssp_test.c index 1113ed88e14..48039fcb43c 100644 --- a/cpp/tests/c_api/sssp_test.c +++ b/cpp/tests/c_api/sssp_test.c @@ -102,15 +102,15 @@ int generic_sssp_test(vertex_t* h_src, } int generic_sssp_test_double(vertex_t* h_src, - vertex_t* h_dst, - double* h_wgt, - vertex_t source, - double const* expected_distances, - vertex_t const* expected_predecessors, - size_t num_vertices, - size_t num_edges, - double cutoff, - bool_t store_transposed) + vertex_t* h_dst, + double* h_wgt, + vertex_t source, + double const* expected_distances, + vertex_t const* expected_predecessors, + size_t num_vertices, + size_t num_edges, + double cutoff, + bool_t store_transposed) { int test_ret_value = 0; @@ -182,8 +182,8 @@ int test_sssp() vertex_t src[] = {0, 1, 1, 2, 2, 2, 3, 4}; vertex_t dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; - float wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; - float expected_distances[] = {0.0f, 0.1f, FLT_MAX, 2.2f, 1.2f, 4.4f}; + float wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; + float expected_distances[] = {0.0f, 0.1f, FLT_MAX, 2.2f, 1.2f, 4.4f}; vertex_t expected_predecessors[] = {-1, 0, -1, 1, 1, 4}; // Bfs wants store_transposed = FALSE @@ -206,8 +206,8 @@ int test_sssp_with_transpose() vertex_t src[] = {0, 1, 1, 2, 2, 2, 3, 4}; vertex_t dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; - float wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; - float expected_distances[] = {0.0f, 0.1f, FLT_MAX, 2.2f, 1.2f, 4.4f}; + float wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; + float expected_distances[] = {0.0f, 0.1f, FLT_MAX, 2.2f, 1.2f, 4.4f}; vertex_t expected_predecessors[] = {-1, 0, -1, 1, 1, 4}; // Bfs wants store_transposed = FALSE @@ -223,8 +223,8 @@ int test_sssp_with_transpose_double() vertex_t src[] = {0, 1, 1, 2, 2, 2, 3, 4}; vertex_t dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; - double wgt[] = {0.1d, 2.1d, 1.1d, 5.1d, 3.1d, 4.1d, 7.2d, 3.2d}; - double expected_distances[] = {0.0d, 0.1d, DBL_MAX, 2.2d, 1.2d, 4.4d}; + double wgt[] = {0.1d, 2.1d, 1.1d, 5.1d, 3.1d, 4.1d, 7.2d, 3.2d}; + double expected_distances[] = {0.0d, 0.1d, DBL_MAX, 2.2d, 1.2d, 4.4d}; vertex_t expected_predecessors[] = {-1, 0, -1, 1, 1, 4}; // Bfs wants store_transposed = FALSE diff --git a/cpp/tests/c_api/strongly_connected_components_test.c b/cpp/tests/c_api/strongly_connected_components_test.c index 51e27e4f469..5a9110cf2a5 100644 --- a/cpp/tests/c_api/strongly_connected_components_test.c +++ b/cpp/tests/c_api/strongly_connected_components_test.c @@ -52,7 +52,8 @@ int generic_scc_test(vertex_t* h_src, TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, cugraph_error_message(ret_error)); ret_code = cugraph_strongly_connected_components(p_handle, p_graph, FALSE, &p_result, &ret_error); - TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_NOT_IMPLEMENTED, "SCC should not be implemented, but is"); + TEST_ASSERT( + test_ret_value, ret_code == CUGRAPH_NOT_IMPLEMENTED, "SCC should not be implemented, but is"); #if 0 // FIXME: Actual implementation will be something like this diff --git a/cpp/tests/c_api/triangle_count_test.c b/cpp/tests/c_api/triangle_count_test.c index a9fc0cbb292..5929e3d6560 100644 --- a/cpp/tests/c_api/triangle_count_test.c +++ b/cpp/tests/c_api/triangle_count_test.c @@ -96,8 +96,7 @@ int generic_triangle_count_test(vertex_t* h_src, TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "copy_to_host failed."); for (int i = 0; (i < num_local_results) && (test_ret_value == 0); ++i) { - TEST_ASSERT( - test_ret_value, h_result[i] == h_counts[i], "counts results don't match"); + TEST_ASSERT(test_ret_value, h_result[i] == h_counts[i], "counts results don't match"); } cugraph_triangle_count_result_free(p_result); From 2e4f34fa354aff160b87f4e011a5b5c3349cb55c Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Thu, 8 Dec 2022 01:29:52 -0600 Subject: [PATCH 3/8] Apply flake8 to Cython code. --- .pre-commit-config.yaml | 2 +- .../betweenness_centrality_wrapper.pyx | 76 +-- .../edge_betweenness_centrality_wrapper.pyx | 77 +-- python/cugraph/cugraph/community/ecg.pxd | 6 +- .../cugraph/cugraph/community/ecg_wrapper.pyx | 50 +- .../cugraph/community/ktruss_subgraph.pxd | 6 +- .../community/ktruss_subgraph_wrapper.pyx | 21 +- python/cugraph/cugraph/community/leiden.pxd | 6 +- .../cugraph/community/leiden_wrapper.pyx | 30 +- .../cugraph/community/spectral_clustering.pxd | 22 +- .../community/spectral_clustering_wrapper.pyx | 177 ++++-- .../cugraph/community/subgraph_extraction.pxd | 6 +- .../community/subgraph_extraction_wrapper.pyx | 43 +- .../cugraph/components/connectivity.pxd | 4 +- .../components/connectivity_wrapper.pyx | 16 +- python/cugraph/cugraph/dask/comms/comms.pxd | 4 +- .../cugraph/dask/structure/replication.pyx | 39 +- python/cugraph/cugraph/generators/rmat.pxd | 3 +- .../cugraph/generators/rmat_wrapper.pyx | 93 ++-- .../cugraph/layout/force_atlas2_wrapper.pyx | 109 ++-- .../cugraph/cugraph/linear_assignment/lap.pxd | 14 +- .../cugraph/linear_assignment/lap_wrapper.pyx | 88 ++- .../cugraph/link_prediction/jaccard.pxd | 10 +- .../link_prediction/jaccard_wrapper.pyx | 96 ++-- .../cugraph/link_prediction/overlap.pxd | 10 +- .../link_prediction/overlap_wrapper.pyx | 84 +-- .../cugraph/structure/graph_primtypes.pxd | 112 ++-- .../cugraph/structure/graph_primtypes.pyx | 53 +- .../structure/graph_primtypes_wrapper.pyx | 80 ++- .../cugraph/structure/graph_utilities.pxd | 11 +- .../cugraph/structure/renumber_wrapper.pyx | 512 +++++++++++------- python/cugraph/cugraph/structure/utils.pxd | 10 +- .../cugraph/structure/utils_wrapper.pyx | 25 +- .../cugraph/tree/minimum_spanning_tree.pxd | 7 +- .../tree/minimum_spanning_tree_wrapper.pyx | 42 +- .../cugraph/utilities/path_retrieval.pxd | 17 +- .../utilities/path_retrieval_wrapper.pyx | 10 +- .../pylibcugraph/_cugraph_c/algorithms.pxd | 5 +- .../_cugraph_c/centrality_algorithms.pxd | 16 +- .../_cugraph_c/community_algorithms.pxd | 12 +- .../_cugraph_c/core_algorithms.pxd | 16 +- .../pylibcugraph/_cugraph_c/error.pxd | 2 +- .../pylibcugraph/_cugraph_c/graph.pxd | 35 +- .../_cugraph_c/graph_functions.pxd | 40 +- .../_cugraph_c/labeling_algorithms.pxd | 7 +- .../_cugraph_c/resource_handle.pxd | 25 +- .../_cugraph_c/similarity_algorithms.pxd | 8 +- python/pylibcugraph/pylibcugraph/bfs.pyx | 23 +- .../pylibcugraph/components/_connectivity.pxd | 7 +- .../pylibcugraph/components/_connectivity.pyx | 10 +- .../pylibcugraph/pylibcugraph/core_number.pyx | 9 +- python/pylibcugraph/pylibcugraph/egonet.pyx | 10 +- .../pylibcugraph/eigenvector_centrality.pyx | 2 +- .../pylibcugraph/graph_properties.pxd | 4 +- .../pylibcugraph/graph_properties.pyx | 2 +- python/pylibcugraph/pylibcugraph/graphs.pxd | 3 +- python/pylibcugraph/pylibcugraph/graphs.pyx | 32 +- python/pylibcugraph/pylibcugraph/hits.pyx | 46 +- .../pylibcugraph/jaccard_coefficients.pyx | 34 +- python/pylibcugraph/pylibcugraph/k_core.pyx | 30 +- .../pylibcugraph/katz_centrality.pyx | 8 +- python/pylibcugraph/pylibcugraph/node2vec.pyx | 20 +- .../pylibcugraph/overlap_coefficients.pyx | 34 +- python/pylibcugraph/pylibcugraph/pagerank.pyx | 48 +- .../pylibcugraph/personalized_pagerank.pyx | 71 +-- .../pylibcugraph/resource_handle.pyx | 2 +- .../pylibcugraph/sorensen_coefficients.pyx | 46 +- python/pylibcugraph/pylibcugraph/sssp.pyx | 14 +- .../structure/graph_primtypes.pxd | 21 +- .../structure/graph_utilities.pxd | 2 +- .../pylibcugraph/testing/type_utils.pyx | 2 +- .../pylibcugraph/triangle_count.pyx | 8 +- .../pylibcugraph/two_hop_neighbors.pyx | 14 +- .../pylibcugraph/uniform_neighbor_sample.pyx | 1 + python/pylibcugraph/pylibcugraph/utils.pxd | 8 +- python/pylibcugraph/pylibcugraph/utils.pyx | 48 +- .../weakly_connected_components.pyx | 33 +- 77 files changed, 1564 insertions(+), 1165 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 24136489a7f..dfba8744cb8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,7 +24,7 @@ repos: args: ["--config=setup.cfg"] files: python/.*$ types: [file] - types_or: [python] # TODO: Enable [python, cython] + types_or: [python, cython] additional_dependencies: ["flake8-force"] - repo: https://github.com/asottile/yesqa rev: v1.3.0 diff --git a/python/cugraph/cugraph/centrality/betweenness_centrality_wrapper.pyx b/python/cugraph/cugraph/centrality/betweenness_centrality_wrapper.pyx index 3d34304ff13..27e29ee8102 100644 --- a/python/cugraph/cugraph/centrality/betweenness_centrality_wrapper.pyx +++ b/python/cugraph/cugraph/centrality/betweenness_centrality_wrapper.pyx @@ -16,7 +16,9 @@ # cython: embedsignature = True # cython: language_level = 3 -from cugraph.centrality.betweenness_centrality cimport betweenness_centrality as c_betweenness_centrality +from cugraph.centrality.betweenness_centrality cimport ( + betweenness_centrality as c_betweenness_centrality +) from cugraph.structure.graph_primtypes cimport * from libc.stdint cimport uintptr_t from libcpp cimport bool @@ -37,7 +39,7 @@ def get_output_df(number_of_vertices, result_dtype): def get_batch(sources, number_of_workers, current_worker): batch_size = len(sources) // number_of_workers - begin = current_worker * batch_size + begin = current_worker * batch_size end = (current_worker + 1) * batch_size if current_worker == (number_of_workers - 1): end = len(sources) @@ -55,23 +57,25 @@ cdef void run_c_betweenness_centrality(uintptr_t c_handle, uintptr_t c_batch, result_dtype): if result_dtype == np.float64: - c_betweenness_centrality[int, int, double, double](( c_handle)[0], - ( c_graph)[0], - c_betweenness, - normalized, - endpoints, - c_weights, - number_of_sources_in_batch, - c_batch) + c_betweenness_centrality[int, int, double, double]( + ( c_handle)[0], + ( c_graph)[0], + c_betweenness, + normalized, + endpoints, + c_weights, + number_of_sources_in_batch, + c_batch) elif result_dtype == np.float32: - c_betweenness_centrality[int, int, float, float](( c_handle)[0], - ( c_graph)[0], - c_betweenness, - normalized, - endpoints, - c_weights, - number_of_sources_in_batch, - c_batch) + c_betweenness_centrality[int, int, float, float]( + ( c_handle)[0], + ( c_graph)[0], + c_betweenness, + normalized, + endpoints, + c_weights, + number_of_sources_in_batch, + c_batch) else: raise ValueError("result_dtype can only be np.float64 or np.float32") @@ -127,7 +131,8 @@ def run_internal_work(handle, input_data, normalized, endpoints, raise ValueError("result_dtype can only be np.float64 or np.float32") c_identifier = result_df['vertex'].__cuda_array_interface__['data'][0] - c_betweenness = result_df['betweenness_centrality'].__cuda_array_interface__['data'][0] + c_betweenness = \ + result_df['betweenness_centrality'].__cuda_array_interface__['data'][0] if weights is not None: c_weights = weights.__cuda_array_interface__['data'][0] @@ -152,6 +157,7 @@ def run_internal_work(handle, input_data, normalized, endpoints, return result_df + def run_mg_work(input_data, normalized, endpoints, weights, sources, result_dtype, session_id): @@ -170,20 +176,20 @@ def run_mg_work(input_data, normalized, endpoints, def batch_betweenness_centrality(input_graph, normalized, endpoints, - weights, vertices, result_dtype): + weights, vertices, result_dtype): df = None client = get_client() comms = Comms.get_comms() replicated_adjlists = input_graph.batch_adjlists - work_futures = [client.submit(run_mg_work, - (data, input_graph.is_directed()), - normalized, - endpoints, - weights, - vertices, - result_dtype, - comms.sessionId, - workers=[worker]) for + work_futures = [client.submit(run_mg_work, + (data, input_graph.is_directed()), + normalized, + endpoints, + weights, + vertices, + result_dtype, + comms.sessionId, + workers=[worker]) for idx, (worker, data) in enumerate(replicated_adjlists.items())] dask.distributed.wait(work_futures) df = work_futures[0].result() @@ -215,13 +221,13 @@ def betweenness_centrality(input_graph, normalized, endpoints, weights, if not input_graph.adjlist: input_graph.view_adj_list() - if Comms.is_initialized() and input_graph.batch_enabled == True: + if Comms.is_initialized() and input_graph.batch_enabled is True: df = batch_betweenness_centrality(input_graph, - normalized, - endpoints, - weights, - vertices, - result_dtype) + normalized, + endpoints, + weights, + vertices, + result_dtype) else: df = sg_betweenness_centrality(input_graph, normalized, diff --git a/python/cugraph/cugraph/centrality/edge_betweenness_centrality_wrapper.pyx b/python/cugraph/cugraph/centrality/edge_betweenness_centrality_wrapper.pyx index bf4a80701ff..ca3333e2a6c 100644 --- a/python/cugraph/cugraph/centrality/edge_betweenness_centrality_wrapper.pyx +++ b/python/cugraph/cugraph/centrality/edge_betweenness_centrality_wrapper.pyx @@ -16,7 +16,9 @@ # cython: embedsignature = True # cython: language_level = 3 -from cugraph.centrality.betweenness_centrality cimport edge_betweenness_centrality as c_edge_betweenness_centrality +from cugraph.centrality.betweenness_centrality cimport ( + edge_betweenness_centrality as c_edge_betweenness_centrality +) from cugraph.structure import graph_primtypes_wrapper from cugraph.structure.graph_primtypes cimport * from libc.stdint cimport uintptr_t @@ -40,7 +42,7 @@ def get_output_df(indices, result_dtype): def get_batch(sources, number_of_workers, current_worker): batch_size = len(sources) // number_of_workers - begin = current_worker * batch_size + begin = current_worker * batch_size end = (current_worker + 1) * batch_size if current_worker == (number_of_workers - 1): end = len(sources) @@ -49,7 +51,7 @@ def get_batch(sources, number_of_workers, current_worker): def run_mg_work(input_data, normalized, weights, sources, - result_dtype, session_id): + result_dtype, session_id): result = None number_of_workers = Comms.get_n_workers(session_id) @@ -80,7 +82,7 @@ def run_internal_work(handle, input_data, normalized, weights, batch, cdef GraphCSRViewDouble graph_double cdef GraphCSRViewFloat graph_float - (offsets, indices, graph_weights), is_directed = input_data + (offsets, indices, graph_weights), is_directed = input_data if graph_weights is not None: c_graph_weights = graph_weights.__cuda_array_interface__['data'][0] @@ -93,7 +95,8 @@ def run_internal_work(handle, input_data, normalized, weights, batch, result_df = get_output_df(indices, result_dtype) c_src_identifier = result_df['src'].__cuda_array_interface__['data'][0] c_dst_identifier = result_df['dst'].__cuda_array_interface__['data'][0] - c_betweenness = result_df['betweenness_centrality'].__cuda_array_interface__['data'][0] + c_betweenness = \ + result_df['betweenness_centrality'].__cuda_array_interface__['data'][0] number_of_sources_in_batch = len(batch) if result_dtype == np.float64: @@ -140,38 +143,41 @@ cdef void run_c_edge_betweenness_centrality(uintptr_t c_handle, uintptr_t c_batch, result_dtype): if result_dtype == np.float64: - c_edge_betweenness_centrality[int, int, double, double](( c_handle)[0], - ( c_graph)[0], - c_betweenness, - normalized, - c_weights, - number_of_sources_in_batch, - c_batch) + c_edge_betweenness_centrality[int, int, double, double]( + ( c_handle)[0], + ( c_graph)[0], + c_betweenness, + normalized, + c_weights, + number_of_sources_in_batch, + c_batch) elif result_dtype == np.float32: - c_edge_betweenness_centrality[int, int, float, float](( c_handle)[0], - ( c_graph)[0], - c_betweenness, - normalized, - c_weights, - number_of_sources_in_batch, - c_batch) + c_edge_betweenness_centrality[int, int, float, float]( + ( c_handle)[0], + ( c_graph)[0], + c_betweenness, + normalized, + c_weights, + number_of_sources_in_batch, + c_batch) else: raise ValueError("result_dtype can only be np.float64 or np.float32") + def batch_edge_betweenness_centrality(input_graph, - normalized, - weights, vertices, result_dtype): + normalized, + weights, vertices, result_dtype): client = get_client() comms = Comms.get_comms() replicated_adjlists = input_graph.batch_adjlists - work_futures = [client.submit(run_mg_work, - (data, input_graph.is_directed()), - normalized, - weights, - vertices, - result_dtype, - comms.sessionId, - workers=[worker]) for + work_futures = [client.submit(run_mg_work, + (data, input_graph.is_directed()), + normalized, + weights, + vertices, + result_dtype, + comms.sessionId, + workers=[worker]) for (worker, data) in replicated_adjlists.items()] dask.distributed.wait(work_futures) df = work_futures[0].result() @@ -200,25 +206,26 @@ def edge_betweenness_centrality(input_graph, normalized, weights, cdef GraphCSRViewDouble graph_double cdef GraphCSRViewFloat graph_float - df = None if not input_graph.adjlist: input_graph.view_adj_list() - if Comms.is_initialized() and input_graph.batch_enabled == True: + if Comms.is_initialized() and input_graph.batch_enabled is True: df = batch_edge_betweenness_centrality(input_graph, normalized, - weights, vertices, - result_dtype) + weights, vertices, + result_dtype) else: df = sg_edge_betweenness_centrality(input_graph, normalized, weights, vertices, result_dtype) if result_dtype == np.float64: graph_double = get_graph_view[GraphCSRViewDouble](input_graph) - graph_double.get_source_indices((df['src'].__cuda_array_interface__['data'][0])) + graph_double.get_source_indices( + (df['src'].__cuda_array_interface__['data'][0])) elif result_dtype == np.float32: graph_float = get_graph_view[GraphCSRViewFloat](input_graph) - graph_float.get_source_indices((df['src'].__cuda_array_interface__['data'][0])) + graph_float.get_source_indices( + (df['src'].__cuda_array_interface__['data'][0])) return df diff --git a/python/cugraph/cugraph/community/ecg.pxd b/python/cugraph/cugraph/community/ecg.pxd index 4f13237eac7..0f3f11492d6 100644 --- a/python/cugraph/cugraph/community/ecg.pxd +++ b/python/cugraph/cugraph/community/ecg.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -21,9 +21,9 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": - cdef void ecg[VT,ET,WT]( + cdef void ecg[VT, ET, WT]( const handle_t &handle, - const GraphCSRView[VT,ET,WT] &graph, + const GraphCSRView[VT, ET, WT] &graph, WT min_weight, VT ensemble_size, VT* ecg_parts) except + diff --git a/python/cugraph/cugraph/community/ecg_wrapper.pyx b/python/cugraph/cugraph/community/ecg_wrapper.pyx index c6d3251b730..c61aac1004c 100644 --- a/python/cugraph/cugraph/community/ecg_wrapper.pyx +++ b/python/cugraph/cugraph/community/ecg_wrapper.pyx @@ -38,9 +38,13 @@ def ecg(input_graph, min_weight=.05, ensemble_size=16): cdef unique_ptr[handle_t] handle_ptr handle_ptr.reset(new handle_t()) - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, - input_graph.adjlist.indices], [np.int32, np.int64]) - [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [ + input_graph.adjlist.offsets, + input_graph.adjlist.indices, + ], [np.int32, np.int64]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.weights], [np.float32, np.float64]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) @@ -55,30 +59,38 @@ def ecg(input_graph, min_weight=.05, ensemble_size=16): cdef uintptr_t c_partition = df['partition'].__cuda_array_interface__['data'][0] cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,float] graph_float - cdef GraphCSRView[int,int,double] graph_double + cdef GraphCSRView[int, int, float] graph_float + cdef GraphCSRView[int, int, double] graph_double if weights.dtype == np.float32: - graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_float = GraphCSRView[int, int, float]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) graph_float.get_vertex_identifiers(c_identifier) - c_ecg[int,int,float](handle_ptr.get()[0], - graph_float, - min_weight, - ensemble_size, - c_partition) + c_ecg[int, int, float](handle_ptr.get()[0], + graph_float, + min_weight, + ensemble_size, + c_partition) else: - graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_double = GraphCSRView[int, int, double]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) graph_double.get_vertex_identifiers(c_identifier) - c_ecg[int,int,double](handle_ptr.get()[0], - graph_double, - min_weight, - ensemble_size, - c_partition) + c_ecg[int, int, double](handle_ptr.get()[0], + graph_double, + min_weight, + ensemble_size, + c_partition) return df diff --git a/python/cugraph/cugraph/community/ktruss_subgraph.pxd b/python/cugraph/cugraph/community/ktruss_subgraph.pxd index d993c31c375..d267dfb2d6e 100644 --- a/python/cugraph/cugraph/community/ktruss_subgraph.pxd +++ b/python/cugraph/cugraph/community/ktruss_subgraph.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -21,6 +21,6 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": - cdef unique_ptr[GraphCOO[VT,ET,WT]] k_truss_subgraph[VT,ET,WT]( - const GraphCOOView[VT,ET,WT] &graph, + cdef unique_ptr[GraphCOO[VT, ET, WT]] k_truss_subgraph[VT, ET, WT]( + const GraphCOOView[VT, ET, WT] &graph, int k) except + diff --git a/python/cugraph/cugraph/community/ktruss_subgraph_wrapper.pyx b/python/cugraph/cugraph/community/ktruss_subgraph_wrapper.pyx index d3b7a38ba41..a10de4fe2b8 100644 --- a/python/cugraph/cugraph/community/ktruss_subgraph_wrapper.pyx +++ b/python/cugraph/cugraph/community/ktruss_subgraph_wrapper.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -23,20 +23,25 @@ import numpy as np def ktruss_subgraph_float(input_graph, k, use_weights): - cdef GraphCOOViewFloat in_graph = get_graph_view[GraphCOOViewFloat](input_graph, use_weights) - return coo_to_df(move(k_truss_subgraph[int,int,float](in_graph, k))) + cdef GraphCOOViewFloat in_graph = get_graph_view[GraphCOOViewFloat]( + input_graph, use_weights) + return coo_to_df(move(k_truss_subgraph[int, int, float](in_graph, k))) def ktruss_subgraph_double(input_graph, k, use_weights): - cdef GraphCOOViewDouble in_graph = get_graph_view[GraphCOOViewDouble](input_graph, use_weights) - return coo_to_df(move(k_truss_subgraph[int,int,double](in_graph, k))) + cdef GraphCOOViewDouble in_graph = get_graph_view[GraphCOOViewDouble]( + input_graph, use_weights) + return coo_to_df(move(k_truss_subgraph[int, int, double](in_graph, k))) def ktruss_subgraph(input_graph, k, use_weights): [input_graph.edgelist.edgelist_df['src'], - input_graph.edgelist.edgelist_df['dst']] = graph_primtypes_wrapper.datatype_cast([input_graph.edgelist.edgelist_df['src'], - input_graph.edgelist.edgelist_df['dst']], - [np.int32]) + input_graph.edgelist.edgelist_df['dst']] = graph_primtypes_wrapper.datatype_cast( + [ + input_graph.edgelist.edgelist_df['src'], + input_graph.edgelist.edgelist_df['dst'], + ], + [np.int32]) if graph_primtypes_wrapper.weight_type(input_graph) == np.float64 and use_weights: return ktruss_subgraph_double(input_graph, k, use_weights) else: diff --git a/python/cugraph/cugraph/community/leiden.pxd b/python/cugraph/cugraph/community/leiden.pxd index 871dc826c06..baf3caa6671 100644 --- a/python/cugraph/cugraph/community/leiden.pxd +++ b/python/cugraph/cugraph/community/leiden.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -23,9 +23,9 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": - cdef pair[size_t, weight_t] leiden[vertex_t,edge_t,weight_t]( + cdef pair[size_t, weight_t] leiden[vertex_t, edge_t, weight_t]( const handle_t &handle, - const GraphCSRView[vertex_t,edge_t,weight_t] &graph, + const GraphCSRView[vertex_t, edge_t, weight_t] &graph, vertex_t *leiden_parts, size_t max_level, weight_t resolution) except + diff --git a/python/cugraph/cugraph/community/leiden_wrapper.pyx b/python/cugraph/cugraph/community/leiden_wrapper.pyx index 1b41134c625..43184c45dfc 100644 --- a/python/cugraph/cugraph/community/leiden_wrapper.pyx +++ b/python/cugraph/cugraph/community/leiden_wrapper.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -38,20 +38,22 @@ def leiden(input_graph, max_iter, resolution): weights = None final_modularity = None - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) if input_graph.adjlist.weights is not None: - [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.weights], [np.float32, np.float64]) else: weights = cudf.Series(np.full(num_edges, 1.0, dtype=np.float32)) # Create the output dataframe df = cudf.DataFrame() df['vertex'] = cudf.Series(np.zeros(num_verts, dtype=np.int32)) - df['partition'] = cudf.Series(np.zeros(num_verts,dtype=np.int32)) + df['partition'] = cudf.Series(np.zeros(num_verts, dtype=np.int32)) cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] @@ -59,16 +61,20 @@ def leiden(input_graph, max_iter, resolution): cdef uintptr_t c_partition = df['partition'].__cuda_array_interface__['data'][0] cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,float] graph_float - cdef GraphCSRView[int,int,double] graph_double + cdef GraphCSRView[int, int, float] graph_float + cdef GraphCSRView[int, int, double] graph_double cdef float final_modularity_float = 1.0 cdef double final_modularity_double = 1.0 cdef int num_level = 0 if weights.dtype == np.float32: - graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_float = GraphCSRView[int, int, float]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) graph_float.get_vertex_identifiers(c_identifier) num_level, final_modularity_float = c_leiden(handle_ptr.get()[0], @@ -79,8 +85,12 @@ def leiden(input_graph, max_iter, resolution): final_modularity = final_modularity_float else: - graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_double = GraphCSRView[int, int, double]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) graph_double.get_vertex_identifiers(c_identifier) num_level, final_modularity_double = c_leiden(handle_ptr.get()[0], diff --git a/python/cugraph/cugraph/community/spectral_clustering.pxd b/python/cugraph/cugraph/community/spectral_clustering.pxd index 346eb50a157..64cf6f71e3f 100644 --- a/python/cugraph/cugraph/community/spectral_clustering.pxd +++ b/python/cugraph/cugraph/community/spectral_clustering.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -21,8 +21,8 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/algorithms.hpp" namespace "cugraph::ext_raft": - cdef void balancedCutClustering[VT,ET,WT]( - const GraphCSRView[VT,ET,WT] &graph, + cdef void balancedCutClustering[VT, ET, WT]( + const GraphCSRView[VT, ET, WT] &graph, const int num_clusters, const int num_eigen_vects, const float evs_tolerance, @@ -31,8 +31,8 @@ cdef extern from "cugraph/algorithms.hpp" namespace "cugraph::ext_raft": const int kmean_max_iter, VT* clustering) except + - cdef void spectralModularityMaximization[VT,ET,WT]( - const GraphCSRView[VT,ET,WT] &graph, + cdef void spectralModularityMaximization[VT, ET, WT]( + const GraphCSRView[VT, ET, WT] &graph, const int n_clusters, const int n_eig_vects, const float evs_tolerance, @@ -41,20 +41,20 @@ cdef extern from "cugraph/algorithms.hpp" namespace "cugraph::ext_raft": const int kmean_max_iter, VT* clustering) except + - cdef void analyzeClustering_modularity[VT,ET,WT]( - const GraphCSRView[VT,ET,WT] &graph, + cdef void analyzeClustering_modularity[VT, ET, WT]( + const GraphCSRView[VT, ET, WT] &graph, const int n_clusters, const VT* clustering, WT* score) except + - cdef void analyzeClustering_edge_cut[VT,ET,WT]( - const GraphCSRView[VT,ET,WT] &graph, + cdef void analyzeClustering_edge_cut[VT, ET, WT]( + const GraphCSRView[VT, ET, WT] &graph, const int n_clusters, const VT* clustering, WT* score) except + - cdef void analyzeClustering_ratio_cut[VT,ET,WT]( - const GraphCSRView[VT,ET,WT] &graph, + cdef void analyzeClustering_ratio_cut[VT, ET, WT]( + const GraphCSRView[VT, ET, WT] &graph, const int n_clusters, const VT* clustering, WT* score) except + diff --git a/python/cugraph/cugraph/community/spectral_clustering_wrapper.pyx b/python/cugraph/cugraph/community/spectral_clustering_wrapper.pyx index 8a04e2c1017..d00e0874a16 100644 --- a/python/cugraph/cugraph/community/spectral_clustering_wrapper.pyx +++ b/python/cugraph/cugraph/community/spectral_clustering_wrapper.pyx @@ -16,11 +16,13 @@ # cython: embedsignature = True # cython: language_level = 3 -from cugraph.community.spectral_clustering cimport balancedCutClustering as c_balanced_cut_clustering -from cugraph.community.spectral_clustering cimport spectralModularityMaximization as c_spectral_modularity_maximization -from cugraph.community.spectral_clustering cimport analyzeClustering_modularity as c_analyze_clustering_modularity -from cugraph.community.spectral_clustering cimport analyzeClustering_edge_cut as c_analyze_clustering_edge_cut -from cugraph.community.spectral_clustering cimport analyzeClustering_ratio_cut as c_analyze_clustering_ratio_cut +from cugraph.community.spectral_clustering cimport ( + balancedCutClustering as c_balanced_cut_clustering, + spectralModularityMaximization as c_spectral_modularity_maximization, + analyzeClustering_modularity as c_analyze_clustering_modularity, + analyzeClustering_edge_cut as c_analyze_clustering_edge_cut, + analyzeClustering_ratio_cut as c_analyze_clustering_ratio_cut, +) from cugraph.structure.graph_primtypes cimport * from cugraph.structure import graph_primtypes_wrapper from libc.stdint cimport uintptr_t @@ -43,19 +45,23 @@ def spectralBalancedCutClustering(input_graph, if input_graph.is_directed(): raise ValueError("directed graphs are not supported") else: - raise TypeError(f"only cugraph.Graph objects are supported, got: {type(input_graph)}") + raise TypeError( + f"only cugraph.Graph objects are supported, got: {type(input_graph)}" + ) if not input_graph.adjlist: input_graph.view_adj_list() weights = None - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) if input_graph.adjlist.weights is not None: - [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.weights], [np.float32, np.float64]) else: weights = cudf.Series(np.full(num_edges, 1.0, dtype=np.float32)) @@ -70,12 +76,16 @@ def spectralBalancedCutClustering(input_graph, cdef uintptr_t c_cluster = df['cluster'].__cuda_array_interface__['data'][0] cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,float] graph_float - cdef GraphCSRView[int,int,double] graph_double + cdef GraphCSRView[int, int, float] graph_float + cdef GraphCSRView[int, int, double] graph_double if weights.dtype == np.float32: - graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_float = GraphCSRView[int, int, float]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) graph_float.get_vertex_identifiers(c_identifier) c_balanced_cut_clustering(graph_float, @@ -87,8 +97,12 @@ def spectralBalancedCutClustering(input_graph, kmean_max_iter, c_cluster) else: - graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_double = GraphCSRView[int, int, double]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) graph_double.get_vertex_identifiers(c_identifier) c_balanced_cut_clustering(graph_double, @@ -102,6 +116,7 @@ def spectralBalancedCutClustering(input_graph, return df + def spectralModularityMaximizationClustering(input_graph, num_clusters, num_eigen_vects=2, @@ -116,15 +131,21 @@ def spectralModularityMaximizationClustering(input_graph, if input_graph.is_directed(): raise ValueError("directed graphs are not supported") else: - raise TypeError(f"only cugraph.Graph objects are supported, got: {type(input_graph)}") + raise TypeError( + f"only cugraph.Graph objects are supported, got: {type(input_graph)}" + ) if not input_graph.adjlist: input_graph.view_adj_list() if input_graph.adjlist.weights is None: - raise Exception("spectral modularity maximization must be called on a graph with weights") + raise Exception( + "spectral modularity maximization must be called on a graph with weights" + ) - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) - [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.weights], [np.float32, np.float64]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) @@ -140,12 +161,16 @@ def spectralModularityMaximizationClustering(input_graph, cdef uintptr_t c_identifier = df['vertex'].__cuda_array_interface__['data'][0] cdef uintptr_t c_cluster = df['cluster'].__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,float] graph_float - cdef GraphCSRView[int,int,double] graph_double + cdef GraphCSRView[int, int, float] graph_float + cdef GraphCSRView[int, int, double] graph_double if weights.dtype == np.float32: - graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_float = GraphCSRView[int, int, float]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) graph_float.get_vertex_identifiers(c_identifier) c_spectral_modularity_maximization(graph_float, @@ -157,8 +182,12 @@ def spectralModularityMaximizationClustering(input_graph, kmean_max_iter, c_cluster) else: - graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_double = GraphCSRView[int, int, double]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) graph_double.get_vertex_identifiers(c_identifier) c_spectral_modularity_maximization(graph_double, @@ -172,6 +201,7 @@ def spectralModularityMaximizationClustering(input_graph, return df + def analyzeClustering_modularity(input_graph, n_clusters, clustering): """ Call analyzeClustering_modularity_nvgraph @@ -180,21 +210,28 @@ def analyzeClustering_modularity(input_graph, n_clusters, clustering): if input_graph.is_directed(): raise ValueError("directed graphs are not supported") else: - raise TypeError(f"only cugraph.Graph objects are supported, got: {type(input_graph)}") + raise TypeError( + f"only cugraph.Graph objects are supported, got: {type(input_graph)}" + ) if not input_graph.adjlist: input_graph.view_adj_list() - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) - [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.weights], [np.float32, np.float64]) score = None num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) if input_graph.adjlist.weights is None: - raise Exception("analyze clustering modularity must be called on a graph with weights") + raise Exception( + "analyze clustering modularity must be called on a graph with weights" + ) if input_graph.adjlist.weights is not None: - [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.weights], [np.float32, np.float64]) else: weights = cudf.Series(np.full(num_edges, 1.0, dtype=np.float32)) @@ -203,14 +240,18 @@ def analyzeClustering_modularity(input_graph, n_clusters, clustering): cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] cdef uintptr_t c_cluster = clustering.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,float] graph_float - cdef GraphCSRView[int,int,double] graph_double + cdef GraphCSRView[int, int, float] graph_float + cdef GraphCSRView[int, int, double] graph_double cdef float score_float cdef double score_double if weights.dtype == np.float32: - graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_float = GraphCSRView[int, int, float]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) c_analyze_clustering_modularity(graph_float, n_clusters, @@ -219,8 +260,12 @@ def analyzeClustering_modularity(input_graph, n_clusters, clustering): score = score_float else: - graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_double = GraphCSRView[int, int, double]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) c_analyze_clustering_modularity(graph_double, n_clusters, @@ -230,6 +275,7 @@ def analyzeClustering_modularity(input_graph, n_clusters, clustering): return score + def analyzeClustering_edge_cut(input_graph, n_clusters, clustering): """ Call analyzeClustering_edge_cut_nvgraph @@ -238,18 +284,22 @@ def analyzeClustering_edge_cut(input_graph, n_clusters, clustering): if input_graph.is_directed(): raise ValueError("directed graphs are not supported") else: - raise TypeError(f"only cugraph.Graph objects are supported, got: {type(input_graph)}") + raise TypeError( + f"only cugraph.Graph objects are supported, got: {type(input_graph)}" + ) if not input_graph.adjlist: input_graph.view_adj_list() - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) score = None num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) if input_graph.adjlist.weights is not None: - [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.weights], [np.float32, np.float64]) else: weights = cudf.Series(np.full(num_edges, 1.0, dtype=np.float32)) @@ -258,14 +308,18 @@ def analyzeClustering_edge_cut(input_graph, n_clusters, clustering): cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] cdef uintptr_t c_cluster = clustering.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,float] graph_float - cdef GraphCSRView[int,int,double] graph_double + cdef GraphCSRView[int, int, float] graph_float + cdef GraphCSRView[int, int, double] graph_double cdef float score_float cdef double score_double if weights.dtype == np.float32: - graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_float = GraphCSRView[int, int, float]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) c_analyze_clustering_edge_cut(graph_float, n_clusters, @@ -274,8 +328,12 @@ def analyzeClustering_edge_cut(input_graph, n_clusters, clustering): score = score_float else: - graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_double = GraphCSRView[int, int, double]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) c_analyze_clustering_edge_cut(graph_double, n_clusters, @@ -285,6 +343,7 @@ def analyzeClustering_edge_cut(input_graph, n_clusters, clustering): return score + def analyzeClustering_ratio_cut(input_graph, n_clusters, clustering): """ Call analyzeClustering_ratio_cut_nvgraph @@ -293,18 +352,22 @@ def analyzeClustering_ratio_cut(input_graph, n_clusters, clustering): if input_graph.is_directed(): raise ValueError("directed graphs are not supported") else: - raise TypeError(f"only cugraph.Graph objects are supported, got: {type(input_graph)}") + raise TypeError( + f"only cugraph.Graph objects are supported, got: {type(input_graph)}" + ) if not input_graph.adjlist: input_graph.view_adj_list() - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) score = None num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) if input_graph.adjlist.weights is not None: - [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.weights], [np.float32, np.float64]) else: weights = cudf.Series(np.full(num_edges, 1.0, dtype=np.float32)) @@ -313,14 +376,18 @@ def analyzeClustering_ratio_cut(input_graph, n_clusters, clustering): cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] cdef uintptr_t c_cluster = clustering.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,float] graph_float - cdef GraphCSRView[int,int,double] graph_double + cdef GraphCSRView[int, int, float] graph_float + cdef GraphCSRView[int, int, double] graph_double cdef float score_float cdef double score_double if weights.dtype == np.float32: - graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_float = GraphCSRView[int, int, float]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) c_analyze_clustering_ratio_cut(graph_float, n_clusters, @@ -329,8 +396,12 @@ def analyzeClustering_ratio_cut(input_graph, n_clusters, clustering): score = score_float else: - graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, - c_weights, num_verts, num_edges) + graph_double = GraphCSRView[int, int, double]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) c_analyze_clustering_ratio_cut(graph_double, n_clusters, diff --git a/python/cugraph/cugraph/community/subgraph_extraction.pxd b/python/cugraph/cugraph/community/subgraph_extraction.pxd index 583e220327d..bc2b789ea71 100644 --- a/python/cugraph/cugraph/community/subgraph_extraction.pxd +++ b/python/cugraph/cugraph/community/subgraph_extraction.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -22,7 +22,7 @@ from libcpp.memory cimport unique_ptr cdef extern from "cugraph/algorithms.hpp" namespace "cugraph::subgraph": - cdef unique_ptr[GraphCOO[VT,ET,WT]] extract_subgraph_vertex[VT,ET,WT]( - const GraphCOOView[VT,ET,WT] &graph, + cdef unique_ptr[GraphCOO[VT, ET, WT]] extract_subgraph_vertex[VT, ET, WT]( + const GraphCOOView[VT, ET, WT] &graph, const VT *vertices, ET num_vertices) except + diff --git a/python/cugraph/cugraph/community/subgraph_extraction_wrapper.pyx b/python/cugraph/cugraph/community/subgraph_extraction_wrapper.pyx index 46dc5c07eaf..5e7b2fba36d 100644 --- a/python/cugraph/cugraph/community/subgraph_extraction_wrapper.pyx +++ b/python/cugraph/cugraph/community/subgraph_extraction_wrapper.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -16,7 +16,9 @@ # cython: embedsignature = True # cython: language_level = 3 -from cugraph.community.subgraph_extraction cimport extract_subgraph_vertex as c_extract_subgraph_vertex +from cugraph.community.subgraph_extraction cimport ( + extract_subgraph_vertex as c_extract_subgraph_vertex +) from cugraph.structure.graph_primtypes cimport * from cugraph.structure import graph_primtypes_wrapper from libc.stdint cimport uintptr_t @@ -36,10 +38,15 @@ def subgraph(input_graph, vertices): if not input_graph.edgelist: input_graph.view_edge_list() - [src, dst] = graph_primtypes_wrapper.datatype_cast([input_graph.edgelist.edgelist_df['src'], input_graph.edgelist.edgelist_df['dst']], [np.int32]) + [src, dst] = graph_primtypes_wrapper.datatype_cast( + [ + input_graph.edgelist.edgelist_df['src'], + input_graph.edgelist.edgelist_df['dst'] + ], [np.int32]) if input_graph.edgelist.weights: - [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.edgelist.edgelist_df['weights']], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [input_graph.edgelist.edgelist_df['weights']], [np.float32, np.float64]) if weights.dtype == np.float64: use_float = False @@ -47,10 +54,10 @@ def subgraph(input_graph, vertices): num_edges = len(src) num_input_vertices = len(vertices) - cdef GraphCOOView[int,int,float] in_graph_float - cdef GraphCOOView[int,int,double] in_graph_double - cdef unique_ptr[GraphCOO[int,int,float]] out_graph_float - cdef unique_ptr[GraphCOO[int,int,double]] out_graph_double + cdef GraphCOOView[int, int, float] in_graph_float + cdef GraphCOOView[int, int, double] in_graph_double + cdef unique_ptr[GraphCOO[int, int, float]] out_graph_float + cdef unique_ptr[GraphCOO[int, int, double]] out_graph_double cdef uintptr_t c_src = src.__cuda_array_interface__['data'][0] cdef uintptr_t c_dst = dst.__cuda_array_interface__['data'][0] @@ -63,18 +70,26 @@ def subgraph(input_graph, vertices): cdef uintptr_t c_vertices = vertices.__cuda_array_interface__['data'][0] if use_float: - in_graph_float = GraphCOOView[int,int,float](c_src, c_dst, c_weights, num_verts, num_edges); - df = coo_to_df(move(c_extract_subgraph_vertex(in_graph_float, c_vertices, num_input_vertices))); + in_graph_float = GraphCOOView[int, int, float]( + c_src, c_dst, c_weights, num_verts, num_edges) + df = coo_to_df(move(c_extract_subgraph_vertex( + in_graph_float, c_vertices, num_input_vertices))) else: - in_graph_double = GraphCOOView[int,int,double](c_src, c_dst, c_weights, num_verts, num_edges); - df = coo_to_df(move(c_extract_subgraph_vertex(in_graph_double, c_vertices, num_input_vertices))); + in_graph_double = GraphCOOView[int, int, double]( + c_src, c_dst, c_weights, num_verts, num_edges) + df = coo_to_df(move(c_extract_subgraph_vertex( + in_graph_double, c_vertices, num_input_vertices))) # renumber vertices to match original input vertices_df = cudf.DataFrame() vertices_df['v'] = vertices vertices_df = vertices_df.reset_index(drop=True).reset_index() - df = df.merge(vertices_df, left_on='src', right_on='index', how='left').drop(columns=['src', 'index']).rename(columns={'v': 'src'}, copy=False) - df = df.merge(vertices_df, left_on='dst', right_on='index', how='left').drop(columns=['dst', 'index']).rename(columns={'v': 'dst'}, copy=False) + df = df.merge(vertices_df, left_on='src', right_on='index', how='left') \ + .drop(columns=['src', 'index']) \ + .rename(columns={'v': 'src'}, copy=False) + df = df.merge(vertices_df, left_on='dst', right_on='index', how='left') \ + .drop(columns=['dst', 'index']) \ + .rename(columns={'v': 'dst'}, copy=False) return df diff --git a/python/cugraph/cugraph/components/connectivity.pxd b/python/cugraph/cugraph/components/connectivity.pxd index 9829ce17325..92c58f2ce2b 100644 --- a/python/cugraph/cugraph/components/connectivity.pxd +++ b/python/cugraph/cugraph/components/connectivity.pxd @@ -25,7 +25,7 @@ cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": ctypedef enum cugraph_cc_t: CUGRAPH_STRONG "cugraph::cugraph_cc_t::CUGRAPH_STRONG" - cdef void connected_components[VT,ET,WT]( - const GraphCSRView[VT,ET,WT] &graph, + cdef void connected_components[VT, ET, WT]( + const GraphCSRView[VT, ET, WT] &graph, cugraph_cc_t connect_type, VT *labels) except + diff --git a/python/cugraph/cugraph/components/connectivity_wrapper.pyx b/python/cugraph/cugraph/components/connectivity_wrapper.pyx index 2a5888f9c9b..7f854ae5291 100644 --- a/python/cugraph/cugraph/components/connectivity_wrapper.pyx +++ b/python/cugraph/cugraph/components/connectivity_wrapper.pyx @@ -35,7 +35,8 @@ def strongly_connected_components(input_graph): if not input_graph.adjlist: input_graph.view_adj_list() - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) @@ -44,14 +45,15 @@ def strongly_connected_components(input_graph): df['vertex'] = cudf.Series(np.zeros(num_verts, dtype=np.int32)) df['labels'] = cudf.Series(np.zeros(num_verts, dtype=np.int32)) - cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] - cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] - cdef uintptr_t c_identifier = df['vertex'].__cuda_array_interface__['data'][0]; - cdef uintptr_t c_labels_val = df['labels'].__cuda_array_interface__['data'][0]; + cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] + cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] + cdef uintptr_t c_identifier = df['vertex'].__cuda_array_interface__['data'][0] + cdef uintptr_t c_labels_val = df['labels'].__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,float] g + cdef GraphCSRView[int, int, float] g - g = GraphCSRView[int,int,float](c_offsets, c_indices, NULL, num_verts, num_edges) + g = GraphCSRView[int, int, float]( + c_offsets, c_indices, NULL, num_verts, num_edges) cdef cugraph_cc_t connect_type=CUGRAPH_STRONG connected_components(g, connect_type, c_labels_val) diff --git a/python/cugraph/cugraph/dask/comms/comms.pxd b/python/cugraph/cugraph/dask/comms/comms.pxd index 3f8f8c2ca59..1fcbd513c98 100644 --- a/python/cugraph/cugraph/dask/comms/comms.pxd +++ b/python/cugraph/cugraph/dask/comms/comms.pxd @@ -21,5 +21,5 @@ from pylibraft.common.handle cimport * cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": - cdef void init_subcomms(handle_t &handle, - size_t row_comm_size) + cdef void init_subcomms(handle_t &handle, + size_t row_comm_size) diff --git a/python/cugraph/cugraph/dask/structure/replication.pyx b/python/cugraph/cugraph/dask/structure/replication.pyx index 64f43663517..d665d320af4 100644 --- a/python/cugraph/cugraph/dask/structure/replication.pyx +++ b/python/cugraph/cugraph/dask/structure/replication.pyx @@ -38,15 +38,20 @@ def replicate_cudf_dataframe(cudf_dataframe, client=None, comms=None): dask_cudf_df = dask_cudf.from_cudf(cudf_dataframe, npartitions=1) df_length = len(dask_cudf_df) - _df_data = get_mg_batch_data(dask_cudf_df, batch_enabled=True) - df_data = mg_utils.prepare_worker_to_parts(_df_data, client) - - workers_to_futures = {worker: client.submit(_replicate_cudf_dataframe, - (data, cudf_dataframe.columns.values, cudf_dataframe.dtypes, df_length), - comms.sessionId, - workers=[worker]) for - (worker, data) in - df_data.worker_to_parts.items()} + _df_data = get_mg_batch_data(dask_cudf_df, batch_enabled=True) + df_data = mg_utils.prepare_worker_to_parts(_df_data, client) + + workers_to_futures = { + worker: client.submit(_replicate_cudf_dataframe, + ( + data, + cudf_dataframe.columns.values, + cudf_dataframe.dtypes, + df_length + ), + comms.sessionId, + workers=[worker]) + for worker, data in df_data.worker_to_parts.items()} dd.wait(workers_to_futures) return workers_to_futures @@ -72,7 +77,7 @@ def _replicate_cudf_dataframe(input_data, session_id): dtype = dtypes[idx] series = cudf.Series(np.zeros(df_length), dtype=dtype) df_data[column] = series - c_series = series.__cuda_array_interface__['data'][0] + c_series = series.__cuda_array_interface__['data'][0] comms_bcast(c_handle, c_series, df_length, series.dtype) if has_data: @@ -87,8 +92,8 @@ def replicate_cudf_series(cudf_series, client=None, comms=None): raise TypeError("Expected a cudf.Series to replicate") client = mg_utils.get_client() if client is None else client comms = Comms.get_comms() if comms is None else comms - dask_cudf_series = dask_cudf.from_cudf(cudf_series, - npartitions=1) + dask_cudf_series = dask_cudf.from_cudf(cudf_series, + npartitions=1) series_length = len(dask_cudf_series) _series_data = get_mg_batch_data(dask_cudf_series, batch_enabled=True) series_data = mg_utils.prepare_worker_to_parts(_series_data) @@ -98,9 +103,9 @@ def replicate_cudf_series(cudf_series, client=None, comms=None): client.submit(_replicate_cudf_series, (data, series_length, dtype), comms.sessionId, - workers=[worker]) for - (worker, data) in - series_data.worker_to_parts.items()} + workers=[worker]) for + (worker, data) in + series_data.worker_to_parts.items()} dd.wait(workers_to_futures) return workers_to_futures @@ -134,11 +139,11 @@ cdef comms_bcast(uintptr_t handle, uintptr_t value_ptr, size_t count, dtype): - if dtype == np.int32: + if dtype == np.int32: c_utils.comms_bcast(( handle)[0], value_ptr, count) elif dtype == np.float32: c_utils.comms_bcast(( handle)[0], value_ptr, count) elif dtype == np.float64: c_utils.comms_bcast(( handle)[0], value_ptr, count) else: - raise TypeError("Unsupported broadcast type") \ No newline at end of file + raise TypeError("Unsupported broadcast type") diff --git a/python/cugraph/cugraph/generators/rmat.pxd b/python/cugraph/cugraph/generators/rmat.pxd index 7c3a4165e3e..b6f9f4530e4 100644 --- a/python/cugraph/cugraph/generators/rmat.pxd +++ b/python/cugraph/cugraph/generators/rmat.pxd @@ -40,7 +40,8 @@ cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": bool clip_and_flip, bool scramble_vertex_ids) except + - cdef vector[pair[unique_ptr[device_buffer], unique_ptr[device_buffer]]] call_generate_rmat_edgelists[vertex_t]( + cdef vector[pair[unique_ptr[device_buffer], unique_ptr[device_buffer]]] \ + call_generate_rmat_edgelists[vertex_t]( const handle_t &handle, size_t n_edgelists, size_t min_scale, diff --git a/python/cugraph/cugraph/generators/rmat_wrapper.pyx b/python/cugraph/cugraph/generators/rmat_wrapper.pyx index 7f1e7f5a219..22796fcb883 100644 --- a/python/cugraph/cugraph/generators/rmat_wrapper.pyx +++ b/python/cugraph/cugraph/generators/rmat_wrapper.pyx @@ -61,26 +61,28 @@ def generate_rmat_edgelist( cdef unique_ptr[graph_generator_t] gg_ret_ptr - if (vertex_t==np.dtype("int32")): - gg_ret_ptr = move(call_generate_rmat_edgelist[int]( deref(handle_), - scale, - num_edges, - a, - b, - c, - seed, - clip_and_flip, - scramble_vertex_ids)) - else: # (vertex_t == np.dtype("int64")) - gg_ret_ptr = move(call_generate_rmat_edgelist[long]( deref(handle_), - scale, - num_edges, - a, - b, - c, - seed, - clip_and_flip, - scramble_vertex_ids)) + if vertex_t == np.dtype("int32"): + gg_ret_ptr = move(call_generate_rmat_edgelist[int]( + deref(handle_), + scale, + num_edges, + a, + b, + c, + seed, + clip_and_flip, + scramble_vertex_ids)) + else: # (vertex_t == np.dtype("int64")) + gg_ret_ptr = move(call_generate_rmat_edgelist[long]( + deref(handle_), + scale, + num_edges, + a, + b, + c, + seed, + clip_and_flip, + scramble_vertex_ids)) gg_ret = move(gg_ret_ptr.get()[0]) @@ -104,7 +106,7 @@ def generate_rmat_edgelists( seed, clip_and_flip, scramble_vertex_ids - ): +): vertex_t = np.dtype("int32") if (2**max_scale) > (2**31 - 1): @@ -128,32 +130,35 @@ def generate_rmat_edgelists( cdef vector[pair[unique_ptr[device_buffer], unique_ptr[device_buffer]]] gg_ret_ptr if (vertex_t==np.dtype("int32")): - gg_ret_ptr = move(call_generate_rmat_edgelists[int]( deref(handle_), - n_edgelists, - min_scale, - max_scale, - edge_factor, - s_distribution, - e_distribution, - seed, - clip_and_flip, - scramble_vertex_ids)) - else: # (vertex_t == np.dtype("int64")) - gg_ret_ptr = move(call_generate_rmat_edgelists[long]( deref(handle_), - n_edgelists, - min_scale, - max_scale, - edge_factor, - s_distribution, - e_distribution, - seed, - clip_and_flip, - scramble_vertex_ids)) + gg_ret_ptr = move(call_generate_rmat_edgelists[int]( + deref(handle_), + n_edgelists, + min_scale, + max_scale, + edge_factor, + s_distribution, + e_distribution, + seed, + clip_and_flip, + scramble_vertex_ids)) + else: # (vertex_t == np.dtype("int64")) + gg_ret_ptr = move(call_generate_rmat_edgelists[long]( + deref(handle_), + n_edgelists, + min_scale, + max_scale, + edge_factor, + s_distribution, + e_distribution, + seed, + clip_and_flip, + scramble_vertex_ids)) list_df = [] for i in range(n_edgelists): set_source = move_device_buffer_to_column(move(gg_ret_ptr[i].first), vertex_t) - set_destination = move_device_buffer_to_column(move(gg_ret_ptr[i].second), vertex_t) + set_destination = move_device_buffer_to_column( + move(gg_ret_ptr[i].second), vertex_t) df = cudf.DataFrame() df['src'] = set_source @@ -161,5 +166,5 @@ def generate_rmat_edgelists( list_df.append(df) - #Return a list of dataframes + # Return a list of dataframes return list_df diff --git a/python/cugraph/cugraph/layout/force_atlas2_wrapper.pyx b/python/cugraph/cugraph/layout/force_atlas2_wrapper.pyx index 73de7415971..da6be88a716 100644 --- a/python/cugraph/cugraph/layout/force_atlas2_wrapper.pyx +++ b/python/cugraph/cugraph/layout/force_atlas2_wrapper.pyx @@ -51,7 +51,7 @@ def force_atlas2(input_graph, cdef unique_ptr[handle_t] handle_ptr handle_ptr.reset(new handle_t()) - handle_ = handle_ptr.get(); + handle_ = handle_ptr.get() if not input_graph.edgelist: input_graph.view_edge_list() @@ -59,8 +59,8 @@ def force_atlas2(input_graph, num_verts = input_graph.number_of_vertices() num_edges = len(input_graph.edgelist.edgelist_df['src']) - cdef GraphCOOView[int,int,float] graph_float - cdef GraphCOOView[int,int,double] graph_double + cdef GraphCOOView[int, int, float] graph_float + cdef GraphCOOView[int, int, double] graph_double df = cudf.DataFrame() df['vertex'] = cudf.Series(np.arange(num_verts, dtype=np.int32)) @@ -76,7 +76,8 @@ def force_atlas2(input_graph, if input_graph.edgelist.weights: weights = input_graph.edgelist.edgelist_df["weights"] - [weights] = graph_primtypes_wrapper.datatype_cast([weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [weights], [np.float32, np.float64]) c_weights = weights.__cuda_array_interface__['data'][0] cdef uintptr_t x_start = NULL @@ -97,60 +98,68 @@ def force_atlas2(input_graph, if callback: callback_ptr = callback.get_native_callback() - # We keep np.float32 as results for both cases pos = cuda.device_array( - (num_verts, 2), - order="F", - dtype=np.float32) + (num_verts, 2), + order="F", + dtype=np.float32) pos_ptr = pos.device_ctypes_pointer.value if input_graph.edgelist.weights \ and input_graph.edgelist.edgelist_df['weights'].dtype == np.float64: - graph_double = GraphCOOView[int,int, double](c_src_indices, - c_dst_indices, c_weights, num_verts, num_edges) - - c_force_atlas2[int, int, double](handle_[0], - graph_double, - pos_ptr, - max_iter, - x_start, - y_start, - outbound_attraction_distribution, - lin_log_mode, - prevent_overlapping, - edge_weight_influence, - jitter_tolerance, - barnes_hut_optimize, - barnes_hut_theta, - scaling_ratio, - strong_gravity_mode, - gravity, - verbose, - callback_ptr) + graph_double = GraphCOOView[int, int, double]( + c_src_indices, + c_dst_indices, + c_weights, + num_verts, + num_edges) + + c_force_atlas2[int, int, double]( + handle_[0], + graph_double, + pos_ptr, + max_iter, + x_start, + y_start, + outbound_attraction_distribution, + lin_log_mode, + prevent_overlapping, + edge_weight_influence, + jitter_tolerance, + barnes_hut_optimize, + barnes_hut_theta, + scaling_ratio, + strong_gravity_mode, + gravity, + verbose, + callback_ptr) else: - graph_float = GraphCOOView[int,int,float](c_src_indices, - c_dst_indices, c_weights, num_verts, - num_edges) - c_force_atlas2[int, int, float](handle_[0], - graph_float, - pos_ptr, - max_iter, - x_start, - y_start, - outbound_attraction_distribution, - lin_log_mode, - prevent_overlapping, - edge_weight_influence, - jitter_tolerance, - barnes_hut_optimize, - barnes_hut_theta, - scaling_ratio, - strong_gravity_mode, - gravity, - verbose, - callback_ptr) + graph_float = GraphCOOView[int, int, float]( + c_src_indices, + c_dst_indices, + c_weights, + num_verts, + num_edges) + c_force_atlas2[int, int, float]( + handle_[0], + graph_float, + pos_ptr, + max_iter, + x_start, + y_start, + outbound_attraction_distribution, + lin_log_mode, + prevent_overlapping, + edge_weight_influence, + jitter_tolerance, + barnes_hut_optimize, + barnes_hut_theta, + scaling_ratio, + strong_gravity_mode, + gravity, + verbose, + callback_ptr) pos_df = cudf.DataFrame(pos, columns=['x', 'y']) df['x'] = pos_df['x'] diff --git a/python/cugraph/cugraph/linear_assignment/lap.pxd b/python/cugraph/cugraph/linear_assignment/lap.pxd index 9f65e215891..8712cfce7cb 100644 --- a/python/cugraph/cugraph/linear_assignment/lap.pxd +++ b/python/cugraph/cugraph/linear_assignment/lap.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021, NVIDIA CORPORATION. +# Copyright (c) 2020-2022, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -20,24 +20,24 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": - cdef weight_t hungarian[vertex_t,edge_t,weight_t]( + cdef weight_t hungarian[vertex_t, edge_t, weight_t]( const handle_t &handle, - const GraphCOOView[vertex_t,edge_t,weight_t] &graph, + const GraphCOOView[vertex_t, edge_t, weight_t] &graph, vertex_t num_workers, const vertex_t *workers, vertex_t *assignments, weight_t epsilon) except + - cdef weight_t hungarian[vertex_t,edge_t,weight_t]( + cdef weight_t hungarian[vertex_t, edge_t, weight_t]( const handle_t &handle, - const GraphCOOView[vertex_t,edge_t,weight_t] &graph, + const GraphCOOView[vertex_t, edge_t, weight_t] &graph, vertex_t num_workers, const vertex_t *workers, vertex_t *assignments) except + cdef extern from "cugraph/algorithms.hpp": - cdef weight_t dense_hungarian "cugraph::dense::hungarian" [vertex_t,weight_t]( + cdef weight_t dense_hungarian "cugraph::dense::hungarian" [vertex_t, weight_t]( const handle_t &handle, const weight_t *costs, vertex_t num_rows, @@ -45,7 +45,7 @@ cdef extern from "cugraph/algorithms.hpp": vertex_t *assignments, weight_t epsilon) except + - cdef weight_t dense_hungarian "cugraph::dense::hungarian" [vertex_t,weight_t]( + cdef weight_t dense_hungarian "cugraph::dense::hungarian" [vertex_t, weight_t]( const handle_t &handle, const weight_t *costs, vertex_t num_rows, diff --git a/python/cugraph/cugraph/linear_assignment/lap_wrapper.pyx b/python/cugraph/cugraph/linear_assignment/lap_wrapper.pyx index c173f45fa3f..2204136a1e7 100644 --- a/python/cugraph/cugraph/linear_assignment/lap_wrapper.pyx +++ b/python/cugraph/cugraph/linear_assignment/lap_wrapper.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021, NVIDIA CORPORATION. +# Copyright (c) 2020-2022, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -36,7 +36,7 @@ def sparse_hungarian(input_graph, workers, epsilon): cdef unique_ptr[handle_t] handle_ptr handle_ptr.reset(new handle_t()) - handle_ = handle_ptr.get(); + handle_ = handle_ptr.get() """ We need a COO of the graph. @@ -52,7 +52,8 @@ def sparse_hungarian(input_graph, workers, epsilon): weights = input_graph.edgelist.edgelist_df["weights"] [src, dst] = graph_primtypes_wrapper.datatype_cast([src, dst], [np.int32]) - [weights] = graph_primtypes_wrapper.datatype_cast([weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [weights], [np.float32, np.float64]) [local_workers] = graph_primtypes_wrapper.datatype_cast([workers], [np.int32]) num_verts = input_graph.number_of_vertices() @@ -62,30 +63,52 @@ def sparse_hungarian(input_graph, workers, epsilon): df['vertex'] = workers df['assignment'] = cudf.Series(np.zeros(len(workers), dtype=np.int32)) - if epsilon == None: + if epsilon is None: epsilon = 1e-6 - cdef uintptr_t c_src = src.__cuda_array_interface__['data'][0] - cdef uintptr_t c_dst = dst.__cuda_array_interface__['data'][0] - cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] - cdef uintptr_t c_workers = local_workers.__cuda_array_interface__['data'][0] + cdef uintptr_t c_src = src.__cuda_array_interface__['data'][0] + cdef uintptr_t c_dst = dst.__cuda_array_interface__['data'][0] + cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] + cdef uintptr_t c_workers = local_workers.__cuda_array_interface__['data'][0] - cdef uintptr_t c_identifier = df['vertex'].__cuda_array_interface__['data'][0]; - cdef uintptr_t c_assignment = df['assignment'].__cuda_array_interface__['data'][0]; + cdef uintptr_t c_identifier = df['vertex'].__cuda_array_interface__['data'][0] + cdef uintptr_t c_assignment = df['assignment'].__cuda_array_interface__['data'][0] cdef float c_epsilon_float = epsilon cdef double c_epsilon_double = epsilon - cdef GraphCOOView[int,int,float] g_float - cdef GraphCOOView[int,int,double] g_double + cdef GraphCOOView[int, int, float] g_float + cdef GraphCOOView[int, int, double] g_double if weights.dtype == np.float32: - g_float = GraphCOOView[int,int,float](c_src, c_dst, c_weights, num_verts, num_edges) - - cost = c_hungarian[int,int,float](handle_[0], g_float, len(workers), c_workers, c_assignment, c_epsilon_float) + g_float = GraphCOOView[int, int, float]( + c_src, + c_dst, + c_weights, + num_verts, + num_edges) + + cost = c_hungarian[int, int, float]( + handle_[0], + g_float, + len(workers), + c_workers, + c_assignment, + c_epsilon_float) else: - g_double = GraphCOOView[int,int,double](c_src, c_dst, c_weights, num_verts, num_edges) - - cost = c_hungarian[int,int,double](handle_[0], g_double, len(workers), c_workers, c_assignment, c_epsilon_double) + g_double = GraphCOOView[int, int, double]( + c_src, + c_dst, + c_weights, + num_verts, + num_edges) + + cost = c_hungarian[int, int, double]( + handle_[0], + g_double, + len(workers), + c_workers, + c_assignment, + c_epsilon_double) return cost, df @@ -99,11 +122,11 @@ def dense_hungarian(costs, num_rows, num_columns, epsilon): cdef unique_ptr[handle_t] handle_ptr handle_ptr.reset(new handle_t()) - handle_ = handle_ptr.get(); + handle_ = handle_ptr.get() assignment = cudf.Series(np.zeros(num_rows, dtype=np.int32)) - if epsilon == None: + if epsilon is None: epsilon = 1e-6 cdef uintptr_t c_costs = costs.__cuda_array_interface__['data'][0] @@ -112,12 +135,29 @@ def dense_hungarian(costs, num_rows, num_columns, epsilon): cdef double c_epsilon_double = epsilon if costs.dtype == np.float32: - cost = c_dense_hungarian[int,float](handle_[0], c_costs, num_rows, num_columns, c_assignment, c_epsilon_float) + cost = c_dense_hungarian[int, float]( + handle_[0], + c_costs, + num_rows, + num_columns, + c_assignment, + c_epsilon_float) elif costs.dtype == np.float64: - cost = c_dense_hungarian[int,double](handle_[0], c_costs, num_rows, num_columns, c_assignment, c_epsilon_double) + cost = c_dense_hungarian[int, double]( + handle_[0], + c_costs, + num_rows, + num_columns, + c_assignment, + c_epsilon_double) elif costs.dtype == np.int32: - cost = c_dense_hungarian[int,double](handle_[0], c_costs, num_rows, num_columns, c_assignment) + cost = c_dense_hungarian[int, double]( + handle_[0], + c_costs, + num_rows, + num_columns, + c_assignment) else: - raise("unsported type: ", costs.dtype) + raise ValueError(f"unsupported type: {costs.dtype}") return cost, assignment diff --git a/python/cugraph/cugraph/link_prediction/jaccard.pxd b/python/cugraph/cugraph/link_prediction/jaccard.pxd index 9e8c82ec3d8..902849168d7 100644 --- a/python/cugraph/cugraph/link_prediction/jaccard.pxd +++ b/python/cugraph/cugraph/link_prediction/jaccard.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -21,13 +21,13 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": - cdef void jaccard[VT,ET,WT]( - const GraphCSRView[VT,ET,WT] &graph, + cdef void jaccard[VT, ET, WT]( + const GraphCSRView[VT, ET, WT] &graph, const WT *weights, WT *result) except + - cdef void jaccard_list[VT,ET,WT]( - const GraphCSRView[VT,ET,WT] &graph, + cdef void jaccard_list[VT, ET, WT]( + const GraphCSRView[VT, ET, WT] &graph, const WT *weights, ET num_pairs, const VT *first, diff --git a/python/cugraph/cugraph/link_prediction/jaccard_wrapper.pyx b/python/cugraph/cugraph/link_prediction/jaccard_wrapper.pyx index e66d8bf0b5c..4b76879bc0e 100644 --- a/python/cugraph/cugraph/link_prediction/jaccard_wrapper.pyx +++ b/python/cugraph/cugraph/link_prediction/jaccard_wrapper.pyx @@ -33,20 +33,21 @@ def jaccard(input_graph, weights_arr=None, vertex_pair=None): indices = None if input_graph.adjlist: - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, - input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) elif input_graph.transposedadjlist: - # - # NOTE: jaccard ONLY operates on an undirected graph, so CSR and CSC should be - # equivalent. The undirected check has already happened, so we'll just use - # the CSC as if it were CSR. - # - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.transposedadjlist.offsets, - input_graph.transposedadjlist.indices], [np.int32]) + # NOTE: jaccard ONLY operates on an undirected graph, so CSR and CSC + # should be equivalent. The undirected check has already happened, so + # we'll just use the CSC as if it were CSR. + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [ + input_graph.transposedadjlist.offsets, + input_graph.transposedadjlist.indices, + ], [np.int32]) else: input_graph.view_adj_list() - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, - input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) @@ -63,13 +64,14 @@ def jaccard(input_graph, weights_arr=None, vertex_pair=None): cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,float] graph_float - cdef GraphCSRView[int,int,double] graph_double + cdef GraphCSRView[int, int, float] graph_float + cdef GraphCSRView[int, int, double] graph_double weight_type = np.float32 if weights_arr is not None: - [weights] = graph_primtypes_wrapper.datatype_cast([weights_arr], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [weights_arr], [np.float32, np.float64]) c_weights = weights.__cuda_array_interface__['data'][0] weight_type = weights.dtype @@ -92,23 +94,25 @@ def jaccard(input_graph, weights_arr=None, vertex_pair=None): c_second_col = second.__cuda_array_interface__['data'][0] if weight_type == np.float32: - graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, - c_weights, num_verts, num_edges) - c_jaccard_list[int,int,float](graph_float, - c_weights, - result_size, - c_first_col, - c_second_col, - c_result_col) + graph_float = GraphCSRView[int, int, float]( + c_offsets, c_indices, c_weights, + num_verts, num_edges) + c_jaccard_list[int, int, float](graph_float, + c_weights, + result_size, + c_first_col, + c_second_col, + c_result_col) else: - graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, - c_weights, num_verts, num_edges) - c_jaccard_list[int,int,double](graph_double, - c_weights, - result_size, - c_first_col, - c_second_col, - c_result_col) + graph_double = GraphCSRView[int, int, double]( + c_offsets, c_indices, c_weights, + num_verts, num_edges) + c_jaccard_list[int, int, double](graph_double, + c_weights, + result_size, + c_first_col, + c_second_col, + c_result_col) return df else: @@ -126,14 +130,14 @@ def jaccard(input_graph, weights_arr=None, vertex_pair=None): nan_as_null=False) c_result_col = df['jaccard_coeff'].__cuda_array_interface__['data'][0] - graph_float = GraphCSRView[int,int,float](c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) - c_jaccard[int,int,float](graph_float, - c_weights, - c_result_col) + graph_float = GraphCSRView[int, int, float](c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) + c_jaccard[int, int, float](graph_float, + c_weights, + c_result_col) graph_float.get_source_indices(c_src_index_col) else: @@ -141,14 +145,14 @@ def jaccard(input_graph, weights_arr=None, vertex_pair=None): nan_as_null=False) c_result_col = df['jaccard_coeff'].__cuda_array_interface__['data'][0] - graph_double = GraphCSRView[int,int,double](c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) - c_jaccard[int,int,double](graph_double, - c_weights, - c_result_col) + graph_double = GraphCSRView[int, int, double](c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) + c_jaccard[int, int, double](graph_double, + c_weights, + c_result_col) graph_double.get_source_indices(c_src_index_col) diff --git a/python/cugraph/cugraph/link_prediction/overlap.pxd b/python/cugraph/cugraph/link_prediction/overlap.pxd index f0654472587..ccb47e630a9 100644 --- a/python/cugraph/cugraph/link_prediction/overlap.pxd +++ b/python/cugraph/cugraph/link_prediction/overlap.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -21,13 +21,13 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": - cdef void overlap[VT,ET,WT]( - const GraphCSRView[VT,ET,WT] &graph, + cdef void overlap[VT, ET, WT]( + const GraphCSRView[VT, ET, WT] &graph, const WT *weights, WT *result) except + - cdef void overlap_list[VT,ET,WT]( - const GraphCSRView[VT,ET,WT] &graph, + cdef void overlap_list[VT, ET, WT]( + const GraphCSRView[VT, ET, WT] &graph, const WT *weights, ET num_pairs, const VT *first, diff --git a/python/cugraph/cugraph/link_prediction/overlap_wrapper.pyx b/python/cugraph/cugraph/link_prediction/overlap_wrapper.pyx index 0f61460a72f..18dc46e854e 100644 --- a/python/cugraph/cugraph/link_prediction/overlap_wrapper.pyx +++ b/python/cugraph/cugraph/link_prediction/overlap_wrapper.pyx @@ -33,7 +33,8 @@ def overlap(input_graph, weights_arr=None, vertex_pair=None): if not input_graph.adjlist: input_graph.view_adj_list() - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) @@ -50,13 +51,14 @@ def overlap(input_graph, weights_arr=None, vertex_pair=None): cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,float] graph_float - cdef GraphCSRView[int,int,double] graph_double + cdef GraphCSRView[int, int, float] graph_float + cdef GraphCSRView[int, int, double] graph_double weight_type = np.float32 if weights_arr is not None: - [weights] = graph_primtypes_wrapper.datatype_cast([weights_arr], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [weights_arr], [np.float32, np.float64]) c_weights = weights.__cuda_array_interface__['data'][0] weight_type = weights.dtype @@ -79,23 +81,31 @@ def overlap(input_graph, weights_arr=None, vertex_pair=None): c_second_col = second.__cuda_array_interface__['data'][0] if weight_type == np.float32: - graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, - c_weights, num_verts, num_edges) - c_overlap_list[int,int,float](graph_float, - c_weights, - result_size, - c_first_col, - c_second_col, - c_result_col) + graph_float = GraphCSRView[int, int, float]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) + c_overlap_list[int, int, float](graph_float, + c_weights, + result_size, + c_first_col, + c_second_col, + c_result_col) else: - graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, - c_weights, num_verts, num_edges) - c_overlap_list[int,int,double](graph_double, - c_weights, - result_size, - c_first_col, - c_second_col, - c_result_col) + graph_double = GraphCSRView[int, int, double]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) + c_overlap_list[int, int, double](graph_double, + c_weights, + result_size, + c_first_col, + c_second_col, + c_result_col) return df else: @@ -113,14 +123,15 @@ def overlap(input_graph, weights_arr=None, vertex_pair=None): nan_as_null=False) c_result_col = df['overlap_coeff'].__cuda_array_interface__['data'][0] - graph_float = GraphCSRView[int,int,float](c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) - c_overlap[int,int,float](graph_float, - c_weights, - c_result_col) + graph_float = GraphCSRView[int, int, float]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) + c_overlap[int, int, float](graph_float, + c_weights, + c_result_col) graph_float.get_source_indices(c_src_index_col) else: @@ -128,14 +139,15 @@ def overlap(input_graph, weights_arr=None, vertex_pair=None): nan_as_null=False) c_result_col = df['overlap_coeff'].__cuda_array_interface__['data'][0] - graph_double = GraphCSRView[int,int,double](c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) - c_overlap[int,int,double](graph_double, - c_weights, - c_result_col) + graph_double = GraphCSRView[int, int, double]( + c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) + c_overlap[int, int, double](graph_double, + c_weights, + c_result_col) graph_double.get_source_indices(c_src_index_col) diff --git a/python/cugraph/cugraph/structure/graph_primtypes.pxd b/python/cugraph/cugraph/structure/graph_primtypes.pxd index f02f33edb67..7a62ef6c79e 100644 --- a/python/cugraph/cugraph/structure/graph_primtypes.pxd +++ b/python/cugraph/cugraph/structure/graph_primtypes.pxd @@ -43,9 +43,9 @@ cdef extern from "cugraph/legacy/graph.hpp" namespace "cugraph::legacy": bool tree PropType has_negative_edges - cdef cppclass GraphViewBase[VT,ET,WT]: + cdef cppclass GraphViewBase[VT, ET, WT]: WT *edge_data - handle_t *handle; + handle_t *handle GraphProperties prop VT number_of_vertices ET number_of_edges @@ -56,109 +56,116 @@ cdef extern from "cugraph/legacy/graph.hpp" namespace "cugraph::legacy": void set_local_data(VT* local_vertices_, ET* local_edges_, VT* local_offsets_) void get_vertex_identifiers(VT *) const - GraphViewBase(WT*,VT,ET) + GraphViewBase(WT*, VT, ET) - cdef cppclass GraphCOOView[VT,ET,WT](GraphViewBase[VT,ET,WT]): + cdef cppclass GraphCOOView[VT, ET, WT](GraphViewBase[VT, ET, WT]): VT *src_indices VT *dst_indices - void degree(ET *,DegreeDirection) const + void degree(ET *, DegreeDirection) const GraphCOOView() GraphCOOView(const VT *, const ET *, const WT *, size_t, size_t) - cdef cppclass GraphCompressedSparseBaseView[VT,ET,WT](GraphViewBase[VT,ET,WT]): + cdef cppclass GraphCompressedSparseBaseView[VT, ET, WT](GraphViewBase[VT, ET, WT]): ET *offsets VT *indices void get_source_indices(VT *) const - void degree(ET *,DegreeDirection) const + void degree(ET *, DegreeDirection) const - GraphCompressedSparseBaseView(const VT *, const ET *, const WT *, size_t, size_t) + GraphCompressedSparseBaseView( + const VT *, const ET *, const WT *, size_t, size_t) - cdef cppclass GraphCSRView[VT,ET,WT](GraphCompressedSparseBaseView[VT,ET,WT]): + cdef cppclass GraphCSRView[VT, ET, WT](GraphCompressedSparseBaseView[VT, ET, WT]): GraphCSRView() GraphCSRView(const VT *, const ET *, const WT *, size_t, size_t) - cdef cppclass GraphCSCView[VT,ET,WT](GraphCompressedSparseBaseView[VT,ET,WT]): + cdef cppclass GraphCSCView[VT, ET, WT](GraphCompressedSparseBaseView[VT, ET, WT]): GraphCSCView() GraphCSCView(const VT *, const ET *, const WT *, size_t, size_t) - cdef cppclass GraphCOOContents[VT,ET,WT]: + cdef cppclass GraphCOOContents[VT, ET, WT]: VT number_of_vertices ET number_of_edges unique_ptr[device_buffer] src_indices unique_ptr[device_buffer] dst_indices unique_ptr[device_buffer] edge_data - cdef cppclass GraphCOO[VT,ET,WT]: + cdef cppclass GraphCOO[VT, ET, WT]: GraphCOO( - VT nv, - ET ne, - bool has_data) except+ - GraphCOOContents[VT,ET,WT] release() - GraphCOOView[VT,ET,WT] view() + VT nv, + ET ne, + bool has_data) except+ + GraphCOOContents[VT, ET, WT] release() + GraphCOOView[VT, ET, WT] view() - cdef cppclass GraphSparseContents[VT,ET,WT]: + cdef cppclass GraphSparseContents[VT, ET, WT]: VT number_of_vertices ET number_of_edges unique_ptr[device_buffer] offsets unique_ptr[device_buffer] indices unique_ptr[device_buffer] edge_data - cdef cppclass GraphCSC[VT,ET,WT]: + cdef cppclass GraphCSC[VT, ET, WT]: GraphCSC( - VT nv, - ET ne, - bool has_data) except+ - GraphSparseContents[VT,ET,WT] release() - GraphCSCView[VT,ET,WT] view() + VT nv, + ET ne, + bool has_data) except+ + GraphSparseContents[VT, ET, WT] release() + GraphCSCView[VT, ET, WT] view() - cdef cppclass GraphCSR[VT,ET,WT]: + cdef cppclass GraphCSR[VT, ET, WT]: GraphCSR( - VT nv, - ET ne, - bool has_data) except+ - GraphSparseContents[VT,ET,WT] release() - GraphCSRView[VT,ET,WT] view() + VT nv, + ET ne, + bool has_data) except+ + GraphSparseContents[VT, ET, WT] release() + GraphCSRView[VT, ET, WT] view() cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": - cdef unique_ptr[GraphCOO[VT, ET, WT]] get_two_hop_neighbors[VT,ET,WT]( + cdef unique_ptr[GraphCOO[VT, ET, WT]] get_two_hop_neighbors[VT, ET, WT]( const GraphCSRView[VT, ET, WT] &graph) except + cdef extern from "" namespace "std" nogil: - cdef unique_ptr[GraphCOO[int,int,float]] move(unique_ptr[GraphCOO[int,int,float]]) - cdef unique_ptr[GraphCOO[int,int,double]] move(unique_ptr[GraphCOO[int,int,double]]) - cdef GraphCOOContents[int,int,float] move(GraphCOOContents[int,int,float]) - cdef GraphCOOContents[int,int,double] move(GraphCOOContents[int,int,double]) + cdef unique_ptr[GraphCOO[int, int, float]] move( + unique_ptr[GraphCOO[int, int, float]]) + cdef unique_ptr[GraphCOO[int, int, double]] move( + unique_ptr[GraphCOO[int, int, double]]) + cdef GraphCOOContents[int, int, float] move(GraphCOOContents[int, int, float]) + cdef GraphCOOContents[int, int, double] move(GraphCOOContents[int, int, double]) cdef device_buffer move(device_buffer) cdef unique_ptr[device_buffer] move(unique_ptr[device_buffer]) - cdef unique_ptr[GraphCSR[int,int,float]] move(unique_ptr[GraphCSR[int,int,float]]) - cdef unique_ptr[GraphCSR[int,int,double]] move(unique_ptr[GraphCSR[int,int,double]]) - cdef GraphSparseContents[int,int,float] move(GraphSparseContents[int,int,float]) - cdef GraphSparseContents[int,int,double] move(GraphSparseContents[int,int,double]) - -ctypedef unique_ptr[GraphCOO[int,int,float]] GraphCOOPtrFloat -ctypedef unique_ptr[GraphCOO[int,int,double]] GraphCOOPtrDouble + cdef unique_ptr[GraphCSR[int, int, float]] move( + unique_ptr[GraphCSR[int, int, float]]) + cdef unique_ptr[GraphCSR[int, int, double]] move( + unique_ptr[GraphCSR[int, int, double]]) + cdef GraphSparseContents[int, int, float] move( + GraphSparseContents[int, int, float]) + cdef GraphSparseContents[int, int, double] move( + GraphSparseContents[int, int, double]) + +ctypedef unique_ptr[GraphCOO[int, int, float]] GraphCOOPtrFloat +ctypedef unique_ptr[GraphCOO[int, int, double]] GraphCOOPtrDouble ctypedef fused GraphCOOPtrType: GraphCOOPtrFloat GraphCOOPtrDouble -ctypedef unique_ptr[GraphCSR[int,int,float]] GraphCSRPtrFloat -ctypedef unique_ptr[GraphCSR[int,int,double]] GraphCSRPtrDouble +ctypedef unique_ptr[GraphCSR[int, int, float]] GraphCSRPtrFloat +ctypedef unique_ptr[GraphCSR[int, int, double]] GraphCSRPtrDouble ctypedef fused GraphCSRPtrType: GraphCSRPtrFloat GraphCSRPtrDouble -ctypedef GraphCOOView[int,int,float] GraphCOOViewFloat -ctypedef GraphCOOView[int,int,double] GraphCOOViewDouble -ctypedef GraphCSRView[int,int,float] GraphCSRViewFloat -ctypedef GraphCSRView[int,int,double] GraphCSRViewDouble +ctypedef GraphCOOView[int, int, float] GraphCOOViewFloat +ctypedef GraphCOOView[int, int, double] GraphCOOViewDouble +ctypedef GraphCSRView[int, int, float] GraphCSRViewFloat +ctypedef GraphCSRView[int, int, double] GraphCSRViewDouble ctypedef fused GraphCOOViewType: GraphCOOViewFloat @@ -174,8 +181,11 @@ ctypedef fused GraphViewType: GraphCSRViewFloat GraphCSRViewDouble -cdef move_device_buffer_to_column(unique_ptr[device_buffer] device_buffer_unique_ptr, dtype) -cdef move_device_buffer_to_series(unique_ptr[device_buffer] device_buffer_unique_ptr, dtype, series_name) +cdef move_device_buffer_to_column( + unique_ptr[device_buffer] device_buffer_unique_ptr, dtype) +cdef move_device_buffer_to_series( + unique_ptr[device_buffer] device_buffer_unique_ptr, dtype, series_name) cdef coo_to_df(GraphCOOPtrType graph) cdef csr_to_series(GraphCSRPtrType graph) -cdef GraphViewType get_graph_view(input_graph, bool weightless=*, GraphViewType* dummy=*) +cdef GraphViewType get_graph_view( + input_graph, bool weightless=*, GraphViewType* dummy=*) diff --git a/python/cugraph/cugraph/structure/graph_primtypes.pyx b/python/cugraph/cugraph/structure/graph_primtypes.pyx index fadd0f73a08..796d18677f6 100644 --- a/python/cugraph/cugraph/structure/graph_primtypes.pyx +++ b/python/cugraph/cugraph/structure/graph_primtypes.pyx @@ -25,8 +25,8 @@ from cudf.core.buffer import as_buffer import cudf -cdef move_device_buffer_to_column( - unique_ptr[device_buffer] device_buffer_unique_ptr, dtype): +cdef move_device_buffer_to_column(unique_ptr[device_buffer] device_buffer_unique_ptr, + dtype): """ Transfers ownership of device_buffer_unique_ptr to a cuDF buffer which is used to construct a cudf column object, which is then returned. If the @@ -41,8 +41,8 @@ cdef move_device_buffer_to_column( return None -cdef move_device_buffer_to_series( - unique_ptr[device_buffer] device_buffer_unique_ptr, dtype, series_name): +cdef move_device_buffer_to_series(unique_ptr[device_buffer] device_buffer_unique_ptr, + dtype, series_name): """ Transfers ownership of device_buffer_unique_ptr to a cuDF buffer which is used to construct a cudf.Series object with name series_name, which is then @@ -101,12 +101,18 @@ cdef csr_to_series(GraphCSRPtrType graph): return (csr_offsets, csr_indices, csr_weights) -cdef GraphCSRViewType get_csr_graph_view(input_graph, bool weighted=True, GraphCSRViewType* dummy=NULL): +cdef GraphCSRViewType get_csr_graph_view( + input_graph, + bool weighted=True, + GraphCSRViewType* dummy=NULL +): if not input_graph.adjlist: input_graph.view_adj_list() - cdef uintptr_t c_off = input_graph.adjlist.offsets.__cuda_array_interface__['data'][0] - cdef uintptr_t c_ind = input_graph.adjlist.indices.__cuda_array_interface__['data'][0] + cdef uintptr_t c_off = \ + input_graph.adjlist.offsets.__cuda_array_interface__['data'][0] + cdef uintptr_t c_ind = \ + input_graph.adjlist.indices.__cuda_array_interface__['data'][0] cdef uintptr_t c_weights = NULL if input_graph.adjlist.weights is not None and weighted: @@ -116,13 +122,19 @@ cdef GraphCSRViewType get_csr_graph_view(input_graph, bool weighted=True, GraphC num_edges = input_graph.number_of_edges(directed_edges=True) cdef GraphCSRViewType in_graph if GraphCSRViewType is GraphCSRViewFloat: - in_graph = GraphCSRViewFloat(c_off, c_ind, c_weights, num_verts, num_edges) + in_graph = GraphCSRViewFloat( + c_off, c_ind, c_weights, num_verts, num_edges) elif GraphCSRViewType is GraphCSRViewDouble: - in_graph = GraphCSRViewDouble(c_off, c_ind, c_weights, num_verts, num_edges) + in_graph = GraphCSRViewDouble( + c_off, c_ind, c_weights, num_verts, num_edges) return in_graph -cdef GraphCOOViewType get_coo_graph_view(input_graph, bool weighted=True, GraphCOOViewType* dummy=NULL): +cdef GraphCOOViewType get_coo_graph_view( + input_graph, + bool weighted=True, + GraphCOOViewType* dummy=NULL +): # FIXME: this function assumes columns named "src" and "dst" and can only # be used for SG graphs due to that assumption. if not input_graph.edgelist: @@ -131,23 +143,32 @@ cdef GraphCOOViewType get_coo_graph_view(input_graph, bool weighted=True, GraphC num_edges = input_graph.number_of_edges(directed_edges=True) num_verts = input_graph.number_of_vertices() - cdef uintptr_t c_src = input_graph.edgelist.edgelist_df['src'].__cuda_array_interface__['data'][0] - cdef uintptr_t c_dst = input_graph.edgelist.edgelist_df['dst'].__cuda_array_interface__['data'][0] + cdef uintptr_t c_src = \ + input_graph.edgelist.edgelist_df['src'].__cuda_array_interface__['data'][0] + cdef uintptr_t c_dst = \ + input_graph.edgelist.edgelist_df['dst'].__cuda_array_interface__['data'][0] cdef uintptr_t c_weights = NULL # FIXME explicit check for None fails, different behavior than get_csr_graph_view if input_graph.edgelist.weights and weighted: - c_weights = input_graph.edgelist.edgelist_df['weights'].__cuda_array_interface__['data'][0] + c_weights = \ + input_graph.edgelist.edgelist_df['weights'].__cuda_array_interface__['data'][0] # noqa: E501 cdef GraphCOOViewType in_graph if GraphCOOViewType is GraphCOOViewFloat: - in_graph = GraphCOOViewFloat(c_src, c_dst, c_weights, num_verts, num_edges) + in_graph = GraphCOOViewFloat( + c_src, c_dst, c_weights, num_verts, num_edges) elif GraphCOOViewType is GraphCOOViewDouble: - in_graph = GraphCOOViewDouble(c_src, c_dst, c_weights, num_verts, num_edges) + in_graph = GraphCOOViewDouble( + c_src, c_dst, c_weights, num_verts, num_edges) return in_graph -cdef GraphViewType get_graph_view(input_graph, bool weighted = True, GraphViewType* dummy=NULL): +cdef GraphViewType get_graph_view( + input_graph, + bool weighted=True, + GraphViewType* dummy=NULL +): if GraphViewType is GraphCOOViewFloat: return get_coo_graph_view[GraphCOOViewFloat](input_graph, weighted, dummy) elif GraphViewType is GraphCOOViewDouble: diff --git a/python/cugraph/cugraph/structure/graph_primtypes_wrapper.pyx b/python/cugraph/cugraph/structure/graph_primtypes_wrapper.pyx index b680be143c9..49df86abd2f 100644 --- a/python/cugraph/cugraph/structure/graph_primtypes_wrapper.pyx +++ b/python/cugraph/cugraph/structure/graph_primtypes_wrapper.pyx @@ -17,7 +17,9 @@ # cython: language_level = 3 from cugraph.structure.graph_primtypes cimport * -from cugraph.structure.graph_primtypes cimport get_two_hop_neighbors as c_get_two_hop_neighbors +from cugraph.structure.graph_primtypes cimport ( + get_two_hop_neighbors as c_get_two_hop_neighbors +) from cugraph.structure.utils_wrapper import * from libcpp cimport bool import enum @@ -55,10 +57,16 @@ def view_adj_list(input_graph): if input_graph.edgelist is None: raise ValueError('Graph is Empty') - [src, dst] = datatype_cast([input_graph.edgelist.edgelist_df['src'], input_graph.edgelist.edgelist_df['dst']], [np.int32]) + [src, dst] = datatype_cast( + [ + input_graph.edgelist.edgelist_df['src'], + input_graph.edgelist.edgelist_df['dst'], + ], [np.int32]) weights = None if input_graph.edgelist.weights: - [weights] = datatype_cast([input_graph.edgelist.edgelist_df['weights']], [np.float32, np.float64]) + [weights] = datatype_cast( + [input_graph.edgelist.edgelist_df['weights']], + [np.float32, np.float64]) return coo2csr(src, dst, weights) @@ -73,10 +81,16 @@ def view_transposed_adj_list(input_graph): else: input_graph.view_edge_list() - [src, dst] = datatype_cast([input_graph.edgelist.edgelist_df['src'], input_graph.edgelist.edgelist_df['dst']], [np.int32]) + [src, dst] = datatype_cast( + [ + input_graph.edgelist.edgelist_df['src'], + input_graph.edgelist.edgelist_df['dst'] + ], [np.int32]) weights = None if input_graph.edgelist.weights: - [weights] = datatype_cast([input_graph.edgelist.edgelist_df['weights']], [np.float32, np.float64]) + [weights] = datatype_cast( + [input_graph.edgelist.edgelist_df['weights']], + [np.float32, np.float64]) return coo2csr(dst, src, weights) @@ -86,24 +100,33 @@ def view_edge_list(input_graph): if input_graph.adjlist is None: raise RuntimeError('Graph is Empty') - [offsets, indices] = datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) [weights] = datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,float] graph - graph = GraphCSRView[int,int,float](c_offsets, c_indices, NULL, num_verts, num_edges) + cdef GraphCSRView[int, int, float] graph + graph = GraphCSRView[int, int, float]( + c_offsets, c_indices, NULL, num_verts, num_edges) - src_indices = cudf.Series(np.zeros(num_edges), dtype= indices.dtype) + src_indices = cudf.Series(np.zeros(num_edges), dtype=indices.dtype) cdef uintptr_t c_src_indices = src_indices.__cuda_array_interface__['data'][0] graph.get_source_indices(c_src_indices) return src_indices, indices, weights -def _degree_coo(edgelist_df, src_name, dst_name, direction=Direction.ALL, num_verts=None, sID=None): +def _degree_coo( + edgelist_df, + src_name, + dst_name, + direction=Direction.ALL, + num_verts=None, + sID=None +): # # Computing the degree of the input graph from COO # @@ -130,14 +153,15 @@ def _degree_coo(edgelist_df, src_name, dst_name, direction=Direction.ALL, num_ve vertex_col = cudf.Series(np.zeros(num_verts, dtype=np.int32)) degree_col = cudf.Series(np.zeros(num_verts, dtype=np.int32)) - cdef GraphCOOView[int,int,float] graph + cdef GraphCOOView[int, int, float] graph cdef uintptr_t c_vertex = vertex_col.__cuda_array_interface__['data'][0] cdef uintptr_t c_degree = degree_col.__cuda_array_interface__['data'][0] cdef uintptr_t c_src = src.__cuda_array_interface__['data'][0] cdef uintptr_t c_dst = dst.__cuda_array_interface__['data'][0] - graph = GraphCOOView[int,int,float](c_src, c_dst, NULL, num_verts, num_edges) + graph = GraphCOOView[int, int, float]( + c_src, c_dst, NULL, num_verts, num_edges) cdef size_t handle_size_t if sID is not None: @@ -171,14 +195,15 @@ def _degree_csr(offsets, indices, direction=Direction.ALL): vertex_col = cudf.Series(np.zeros(num_verts, dtype=np.int32)) degree_col = cudf.Series(np.zeros(num_verts, dtype=np.int32)) - cdef GraphCSRView[int,int,float] graph + cdef GraphCSRView[int, int, float] graph cdef uintptr_t c_vertex = vertex_col.__cuda_array_interface__['data'][0] cdef uintptr_t c_degree = degree_col.__cuda_array_interface__['data'][0] cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] - graph = GraphCSRView[int,int,float](c_offsets, c_indices, NULL, num_verts, num_edges) + graph = GraphCSRView[int, int, float]( + c_offsets, c_indices, NULL, num_verts, num_edges) graph.degree( c_degree, dir) graph.get_vertex_identifiers(c_vertex) @@ -229,9 +254,9 @@ def _mg_degree(input_graph, direction=Direction.ALL): def _degree(input_graph, direction=Direction.ALL): # FIXME: this function assumes columns named "src" and "dst" and can only # be used for SG graphs due to that assumption. - transpose_direction = { Direction.ALL: Direction.ALL, - Direction.IN: Direction.OUT, - Direction.OUT: Direction.IN } + transpose_direction = {Direction.ALL: Direction.ALL, + Direction.IN: Direction.OUT, + Direction.OUT: Direction.IN} if input_graph.adjlist is not None: return _degree_csr(input_graph.adjlist.offsets, @@ -262,20 +287,26 @@ def _degrees(input_graph): def get_two_hop_neighbors(input_graph): # FIXME: this function assumes columns named "src" and "dst" and can only # be used for SG graphs due to that assumption. - cdef GraphCSRView[int,int,float] graph + cdef GraphCSRView[int, int, float] graph offsets = None indices = None transposed = False if input_graph.adjlist: - [offsets, indices] = datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], + [np.int32]) elif input_graph.transposedadjlist: - [offsets, indices] = datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], + [np.int32]) transposed = True else: input_graph.view_adj_list() - [offsets, indices] = datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], + [np.int32]) cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] @@ -283,13 +314,14 @@ def get_two_hop_neighbors(input_graph): num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) - graph = GraphCSRView[int,int,float](c_offsets, c_indices, NULL, num_verts, num_edges) + graph = GraphCSRView[int, int, float]( + c_offsets, c_indices, NULL, num_verts, num_edges) df = coo_to_df(move(c_get_two_hop_neighbors(graph))) if not transposed: - df.rename(columns={'src':'first', 'dst':'second'}, inplace=True) + df.rename(columns={'src': 'first', 'dst': 'second'}, inplace=True) else: - df.rename(columns={'dst':'first', 'src':'second'}, inplace=True) + df.rename(columns={'dst': 'first', 'src': 'second'}, inplace=True) return df diff --git a/python/cugraph/cugraph/structure/graph_utilities.pxd b/python/cugraph/cugraph/structure/graph_utilities.pxd index 74edb61fafa..30e66691e78 100644 --- a/python/cugraph/cugraph/structure/graph_utilities.pxd +++ b/python/cugraph/cugraph/structure/graph_utilities.pxd @@ -36,7 +36,7 @@ cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": doubleType "cugraph::cython::numberTypeEnum::doubleType" cdef cppclass graph_container_t: - pass + pass cdef void populate_graph_container( graph_container_t &graph_container, @@ -145,14 +145,16 @@ cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": pair[vertex_t, vertex_t] get_part_local_vertex_range() vertex_t get_part_local_vertex_first() vertex_t get_part_local_vertex_last() - pair[vertex_t, vertex_t] get_part_vertex_partition_range(size_t vertex_partition_idx) + pair[vertex_t, vertex_t] get_part_vertex_partition_range( + size_t vertex_partition_idx) vertex_t get_part_vertex_partition_first(size_t vertex_partition_idx) vertex_t get_part_vertex_partition_last(size_t vertex_partition_idx) vertex_t get_part_vertex_partition_size(size_t vertex_partition_idx) size_t get_part_number_of_matrix_partitions() vertex_t get_part_matrix_partition_major_first(size_t partition_idx) vertex_t get_part_matrix_partition_major_last(size_t partition_idx) - vertex_t get_part_matrix_partition_major_value_start_offset(size_t partition_idx) + vertex_t get_part_matrix_partition_major_value_start_offset( + size_t partition_idx) pair[vertex_t, vertex_t] get_part_matrix_partition_minor_range() vertex_t get_part_matrix_partition_minor_first() vertex_t get_part_matrix_partition_minor_last() @@ -161,7 +163,8 @@ cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": # cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": - cdef unique_ptr[major_minor_weights_t[vertex_t, edge_t, weight_t]] call_shuffle[vertex_t, edge_t, weight_t]( + cdef unique_ptr[major_minor_weights_t[vertex_t, edge_t, weight_t]] \ + call_shuffle[vertex_t, edge_t, weight_t]( const handle_t &handle, vertex_t *edgelist_major_vertices, vertex_t *edgelist_minor_vertices, diff --git a/python/cugraph/cugraph/structure/renumber_wrapper.pyx b/python/cugraph/cugraph/structure/renumber_wrapper.pyx index 58c64104f65..56a902022e2 100644 --- a/python/cugraph/cugraph/structure/renumber_wrapper.pyx +++ b/python/cugraph/cugraph/structure/renumber_wrapper.pyx @@ -38,9 +38,12 @@ from cugraph.structure.graph_primtypes cimport move_device_buffer_to_series cdef renumber_helper(shuffled_vertices_t* ptr_maj_min_w, vertex_t, weights): # extract shuffled result: # - cdef pair[unique_ptr[device_buffer], size_t] pair_s_major = deref(ptr_maj_min_w).get_major_wrap() - cdef pair[unique_ptr[device_buffer], size_t] pair_s_minor = deref(ptr_maj_min_w).get_minor_wrap() - cdef pair[unique_ptr[device_buffer], size_t] pair_s_weights = deref(ptr_maj_min_w).get_weights_wrap() + cdef pair[unique_ptr[device_buffer], size_t] pair_s_major = \ + deref(ptr_maj_min_w).get_major_wrap() + cdef pair[unique_ptr[device_buffer], size_t] pair_s_minor = \ + deref(ptr_maj_min_w).get_minor_wrap() + cdef pair[unique_ptr[device_buffer], size_t] pair_s_weights = \ + deref(ptr_maj_min_w).get_weights_wrap() shuffled_major_series = move_device_buffer_to_series( move(pair_s_major.first), vertex_t, "shuffled_major") @@ -49,9 +52,10 @@ cdef renumber_helper(shuffled_vertices_t* ptr_maj_min_w, vertex_t, weights): move(pair_s_minor.first), vertex_t, "shuffled_minor") shuffled_df = cudf.DataFrame() - # Some workers might have no data therefore ensure the empty column have the appropriate - # vertex_t or weight_t. Failing to do that will create am empty column of type object - # which is not supported by '__cuda_array_interface__' + # Some workers might have no data therefore ensure the empty column have + # the appropriate vertex_t or weight_t. Failing to do that will create am + # empty column of type object which is not supported by + # '__cuda_array_interface__' if shuffled_major_series is None: shuffled_df['major_vertices'] = cudf.Series(dtype=vertex_t) else: @@ -88,10 +92,12 @@ def renumber(input_df, # maybe use cpdef ? # TODO: get handle_t out of handle... handle_ptr = handle_size_t - # FIXME: call_shuffle currently works on major/minor while call_renumber is updated to work on - # source/destination. We'd better update call_shuffle to work on source/destination as well to - # avoid switching between major/minor & source/destination. Deferring this work at this moment - # expecting this legacy code path will be replaced with the new pylibcugrpah & C API based path. + # FIXME: call_shuffle currently works on major/minor while call_renumber is + # updated to work on source/destination. We'd better update call_shuffle to + # work on source/destination as well to avoid switching between major/minor + # & source/destination. Deferring this work at this moment expecting this + # legacy code path will be replaced with the new pylibcugrpah & C API based + # path. if not transposed: major_vertices = input_df[renumbered_src_col_name] @@ -100,7 +106,7 @@ def renumber(input_df, # maybe use cpdef ? major_vertices = input_df[renumbered_dst_col_name] minor_vertices = input_df[renumbered_src_col_name] - cdef uintptr_t c_edge_weights = NULL # set below... + cdef uintptr_t c_edge_weights = NULL # set below... vertex_t = major_vertices.dtype if num_global_edges > (2**31 - 1): @@ -134,8 +140,8 @@ def renumber(input_df, # maybe use cpdef ? cdef uintptr_t shuffled_dst = NULL # FIXME: Fix fails when do_check = True - cdef bool do_check = False # ? for now... - cdef bool mg_flag = is_multi_gpu # run Single-GPU or MNMG + cdef bool do_check = False # ? for now... + cdef bool mg_flag = is_multi_gpu # run Single-GPU or MNMG cdef pair[unique_ptr[device_buffer], size_t] pair_original @@ -172,25 +178,35 @@ def renumber(input_df, # maybe use cpdef ? cdef size_t rank_indx = rank if (vertex_t == np.dtype("int32")): - if ( edge_t == np.dtype("int32")): - if( weight_t == np.dtype("float32")): - if(is_multi_gpu): - ptr_shuffled_32_32_32.reset(call_shuffle[int, int, float](deref(handle_ptr), - c_major_vertices, - c_minor_vertices, - c_edge_weights, - num_local_edges, - weights is not None).release()) - shuffled_df = renumber_helper(ptr_shuffled_32_32_32.get(), vertex_t, weights) + if edge_t == np.dtype("int32"): + if weight_t == np.dtype("float32"): + if is_multi_gpu: + ptr_shuffled_32_32_32.reset(call_shuffle[int, int, float]( + deref(handle_ptr), + c_major_vertices, + c_minor_vertices, + c_edge_weights, + num_local_edges, + weights is not None).release()) + shuffled_df = renumber_helper( + ptr_shuffled_32_32_32.get(), vertex_t, weights) major_vertices = shuffled_df['major_vertices'] minor_vertices = shuffled_df['minor_vertices'] num_local_edges = len(shuffled_df) if not transposed: - major = renumbered_src_col_name; minor = renumbered_dst_col_name + major = renumbered_src_col_name + minor = renumbered_dst_col_name else: - major = renumbered_dst_col_name; minor = renumbered_src_col_name - shuffled_df = shuffled_df.rename(columns={'major_vertices':major, 'minor_vertices':minor}, copy=False) - edge_counts_32 = move(ptr_shuffled_32_32_32.get().get_edge_counts_wrap()) + major = renumbered_dst_col_name + minor = renumbered_src_col_name + shuffled_df = shuffled_df.rename( + columns={ + 'major_vertices': major, + 'minor_vertices': minor, + }, + copy=False) + edge_counts_32 = move( + ptr_shuffled_32_32_32.get().get_edge_counts_wrap()) else: shuffled_df = input_df edge_counts_32 = make_unique[vector[int]](1, num_local_edges) @@ -202,32 +218,37 @@ def renumber(input_df, # maybe use cpdef ? shuffled_src = minor_vertices.__cuda_array_interface__['data'][0] shuffled_dst = major_vertices.__cuda_array_interface__['data'][0] - ptr_renum_tuple_32_32.reset(call_renumber[int, int](deref(handle_ptr), - shuffled_src, - shuffled_dst, - deref(edge_counts_32.get()), - transposed, - do_check, - mg_flag).release()) + ptr_renum_tuple_32_32.reset(call_renumber[int, int]( + deref(handle_ptr), + shuffled_src, + shuffled_dst, + deref(edge_counts_32.get()), + transposed, + do_check, + mg_flag).release()) - pair_original = ptr_renum_tuple_32_32.get().get_dv_wrap() # original vertices: see helper + # original vertices: see helper + pair_original = ptr_renum_tuple_32_32.get().get_dv_wrap() original_series = move_device_buffer_to_series( move(pair_original.first), vertex_t, "original") # extract unique_ptr[partition_offsets]: # - uniq_partition_vector_32 = move(ptr_renum_tuple_32_32.get().get_partition_offsets_wrap()) + uniq_partition_vector_32 = move( + ptr_renum_tuple_32_32.get().get_partition_offsets_wrap()) # create series out of a partition range from rank to rank+1: # if is_multi_gpu: - new_series = cudf.Series(np.arange(uniq_partition_vector_32.get()[0].at(rank_indx), - uniq_partition_vector_32.get()[0].at(rank_indx+1)), - dtype=vertex_t) + new_series = cudf.Series( + np.arange(uniq_partition_vector_32.get()[0].at(rank_indx), + uniq_partition_vector_32.get()[0].at(rank_indx+1)), + dtype=vertex_t) else: - new_series = cudf.Series(np.arange(0, ptr_renum_tuple_32_32.get().get_num_vertices()), - dtype=vertex_t) + new_series = cudf.Series( + np.arange(0, ptr_renum_tuple_32_32.get().get_num_vertices()), + dtype=vertex_t) # create new cudf df # # and add the previous series to it: @@ -236,32 +257,44 @@ def renumber(input_df, # maybe use cpdef ? renumbered_map['original_ids'] = original_series renumbered_map['new_ids'] = new_series - uniq_segment_vector_32 = move(ptr_renum_tuple_32_32.get().get_segment_offsets_wrap()) - segment_offsets = [None] * (deref(uniq_segment_vector_32).size()) + uniq_segment_vector_32 = move( + ptr_renum_tuple_32_32.get().get_segment_offsets_wrap()) + segment_offsets = [None] * ( + deref(uniq_segment_vector_32).size()) for i in range(len(segment_offsets)): - segment_offsets[i] = deref(uniq_segment_vector_32)[i] + segment_offsets[i] = deref(uniq_segment_vector_32)[i] return renumbered_map, segment_offsets, shuffled_df - elif( weight_t == np.dtype("float64")): - if(is_multi_gpu): - ptr_shuffled_32_32_64.reset(call_shuffle[int, int, double](deref(handle_ptr), - c_major_vertices, - c_minor_vertices, - c_edge_weights, - num_local_edges, - weights is not None).release()) - - shuffled_df = renumber_helper(ptr_shuffled_32_32_64.get(), vertex_t, weights) + elif weight_t == np.dtype("float64"): + if is_multi_gpu: + ptr_shuffled_32_32_64.reset(call_shuffle[int, int, double]( + deref(handle_ptr), + c_major_vertices, + c_minor_vertices, + c_edge_weights, + num_local_edges, + weights is not None).release()) + + shuffled_df = renumber_helper( + ptr_shuffled_32_32_64.get(), vertex_t, weights) major_vertices = shuffled_df['major_vertices'] minor_vertices = shuffled_df['minor_vertices'] num_local_edges = len(shuffled_df) if not transposed: - major = renumbered_src_col_name; minor = renumbered_dst_col_name + major = renumbered_src_col_name + minor = renumbered_dst_col_name else: - major = renumbered_dst_col_name; minor = renumbered_src_col_name - shuffled_df = shuffled_df.rename(columns={'major_vertices':major, 'minor_vertices':minor}, copy=False) - edge_counts_32 = move(ptr_shuffled_32_32_64.get().get_edge_counts_wrap()) + major = renumbered_dst_col_name + minor = renumbered_src_col_name + shuffled_df = shuffled_df.rename( + columns={ + 'major_vertices': major, + 'minor_vertices': minor, + }, + copy=False) + edge_counts_32 = move( + ptr_shuffled_32_32_64.get().get_edge_counts_wrap()) else: shuffled_df = input_df edge_counts_32 = make_unique[vector[int]](1, num_local_edges) @@ -273,32 +306,37 @@ def renumber(input_df, # maybe use cpdef ? shuffled_src = minor_vertices.__cuda_array_interface__['data'][0] shuffled_dst = major_vertices.__cuda_array_interface__['data'][0] - ptr_renum_tuple_32_32.reset(call_renumber[int, int](deref(handle_ptr), - shuffled_src, - shuffled_dst, - deref(edge_counts_32.get()), - transposed, - do_check, - mg_flag).release()) + ptr_renum_tuple_32_32.reset(call_renumber[int, int]( + deref(handle_ptr), + shuffled_src, + shuffled_dst, + deref(edge_counts_32.get()), + transposed, + do_check, + mg_flag).release()) - pair_original = ptr_renum_tuple_32_32.get().get_dv_wrap() # original vertices: see helper + # original vertices: see helper + pair_original = ptr_renum_tuple_32_32.get().get_dv_wrap() original_series = move_device_buffer_to_series( move(pair_original.first), vertex_t, "original") # extract unique_ptr[partition_offsets]: # - uniq_partition_vector_32 = move(ptr_renum_tuple_32_32.get().get_partition_offsets_wrap()) + uniq_partition_vector_32 = move( + ptr_renum_tuple_32_32.get().get_partition_offsets_wrap()) # create series out of a partition range from rank to rank+1: # if is_multi_gpu: - new_series = cudf.Series(np.arange(uniq_partition_vector_32.get()[0].at(rank_indx), - uniq_partition_vector_32.get()[0].at(rank_indx+1)), - dtype=vertex_t) + new_series = cudf.Series( + np.arange(uniq_partition_vector_32.get()[0].at(rank_indx), + uniq_partition_vector_32.get()[0].at(rank_indx+1)), + dtype=vertex_t) else: - new_series = cudf.Series(np.arange(0, ptr_renum_tuple_32_32.get().get_num_vertices()), - dtype=vertex_t) + new_series = cudf.Series( + np.arange(0, ptr_renum_tuple_32_32.get().get_num_vertices()), + dtype=vertex_t) # create new cudf df # @@ -308,33 +346,45 @@ def renumber(input_df, # maybe use cpdef ? renumbered_map['original_ids'] = original_series renumbered_map['new_ids'] = new_series - uniq_segment_vector_32 = move(ptr_renum_tuple_32_32.get().get_segment_offsets_wrap()) - segment_offsets = [None] * (deref(uniq_segment_vector_32).size()) + uniq_segment_vector_32 = move( + ptr_renum_tuple_32_32.get().get_segment_offsets_wrap()) + segment_offsets = [None] * ( + deref(uniq_segment_vector_32).size()) for i in range(len(segment_offsets)): - segment_offsets[i] = deref(uniq_segment_vector_32)[i] + segment_offsets[i] = deref(uniq_segment_vector_32)[i] return renumbered_map, segment_offsets, shuffled_df - elif ( edge_t == np.dtype("int64")): - if( weight_t == np.dtype("float32")): - if(is_multi_gpu): - ptr_shuffled_32_64_32.reset(call_shuffle[int, long, float](deref(handle_ptr), - c_major_vertices, - c_minor_vertices, - c_edge_weights, - num_local_edges, - weights is not None).release()) - - shuffled_df = renumber_helper(ptr_shuffled_32_64_32.get(), vertex_t, weights) + elif edge_t == np.dtype("int64"): + if weight_t == np.dtype("float32"): + if is_multi_gpu: + ptr_shuffled_32_64_32.reset(call_shuffle[int, long, float]( + deref(handle_ptr), + c_major_vertices, + c_minor_vertices, + c_edge_weights, + num_local_edges, + weights is not None).release()) + + shuffled_df = renumber_helper( + ptr_shuffled_32_64_32.get(), vertex_t, weights) major_vertices = shuffled_df['major_vertices'] minor_vertices = shuffled_df['minor_vertices'] num_local_edges = len(shuffled_df) if not transposed: - major = renumbered_src_col_name; minor = renumbered_dst_col_name + major = renumbered_src_col_name + minor = renumbered_dst_col_name else: - major = renumbered_dst_col_name; minor = renumbered_src_col_name - shuffled_df = shuffled_df.rename(columns={'major_vertices':major, 'minor_vertices':minor}, copy=False) - edge_counts_64 = move(ptr_shuffled_32_64_32.get().get_edge_counts_wrap()) + major = renumbered_dst_col_name + minor = renumbered_src_col_name + shuffled_df = shuffled_df.rename( + columns={ + 'major_vertices': major, + 'minor_vertices': minor, + }, + copy=False) + edge_counts_64 = move( + ptr_shuffled_32_64_32.get().get_edge_counts_wrap()) else: shuffled_df = input_df edge_counts_64 = make_unique[vector[long]](1, num_local_edges) @@ -346,32 +396,37 @@ def renumber(input_df, # maybe use cpdef ? shuffled_src = minor_vertices.__cuda_array_interface__['data'][0] shuffled_dst = major_vertices.__cuda_array_interface__['data'][0] - ptr_renum_tuple_32_64.reset(call_renumber[int, long](deref(handle_ptr), - shuffled_src, - shuffled_dst, - deref(edge_counts_64.get()), - transposed, - do_check, - mg_flag).release()) + ptr_renum_tuple_32_64.reset(call_renumber[int, long]( + deref(handle_ptr), + shuffled_src, + shuffled_dst, + deref(edge_counts_64.get()), + transposed, + do_check, + mg_flag).release()) - pair_original = ptr_renum_tuple_32_64.get().get_dv_wrap() # original vertices: see helper + # original vertices: see helper + pair_original = ptr_renum_tuple_32_64.get().get_dv_wrap() original_series = move_device_buffer_to_series( move(pair_original.first), vertex_t, "original") # extract unique_ptr[partition_offsets]: # - uniq_partition_vector_32 = move(ptr_renum_tuple_32_64.get().get_partition_offsets_wrap()) + uniq_partition_vector_32 = move( + ptr_renum_tuple_32_64.get().get_partition_offsets_wrap()) # create series out of a partition range from rank to rank+1: # if is_multi_gpu: - new_series = cudf.Series(np.arange(uniq_partition_vector_32.get()[0].at(rank_indx), - uniq_partition_vector_32.get()[0].at(rank_indx+1)), - dtype=vertex_t) + new_series = cudf.Series( + np.arange(uniq_partition_vector_32.get()[0].at(rank_indx), + uniq_partition_vector_32.get()[0].at(rank_indx+1)), + dtype=vertex_t) else: - new_series = cudf.Series(np.arange(0, ptr_renum_tuple_32_64.get().get_num_vertices()), - dtype=vertex_t) + new_series = cudf.Series( + np.arange(0, ptr_renum_tuple_32_64.get().get_num_vertices()), + dtype=vertex_t) # create new cudf df # @@ -381,31 +436,43 @@ def renumber(input_df, # maybe use cpdef ? renumbered_map['original_ids'] = original_series renumbered_map['new_ids'] = new_series - uniq_segment_vector_32 = move(ptr_renum_tuple_32_64.get().get_segment_offsets_wrap()) - segment_offsets = [None] * (deref(uniq_segment_vector_32).size()) + uniq_segment_vector_32 = move( + ptr_renum_tuple_32_64.get().get_segment_offsets_wrap()) + segment_offsets = [None] * ( + deref(uniq_segment_vector_32).size()) for i in range(len(segment_offsets)): - segment_offsets[i] = deref(uniq_segment_vector_32)[i] + segment_offsets[i] = deref(uniq_segment_vector_32)[i] return renumbered_map, segment_offsets, shuffled_df - elif( weight_t == np.dtype("float64")): - if(is_multi_gpu): - ptr_shuffled_32_64_64.reset(call_shuffle[int, long, double](deref(handle_ptr), - c_major_vertices, - c_minor_vertices, - c_edge_weights, - num_local_edges, - weights is not None).release()) - - shuffled_df = renumber_helper(ptr_shuffled_32_64_64.get(), vertex_t, weights) + elif weight_t == np.dtype("float64"): + if is_multi_gpu: + ptr_shuffled_32_64_64.reset(call_shuffle[int, long, double]( + deref(handle_ptr), + c_major_vertices, + c_minor_vertices, + c_edge_weights, + num_local_edges, + weights is not None).release()) + + shuffled_df = renumber_helper( + ptr_shuffled_32_64_64.get(), vertex_t, weights) major_vertices = shuffled_df['major_vertices'] minor_vertices = shuffled_df['minor_vertices'] num_local_edges = len(shuffled_df) if not transposed: - major = renumbered_src_col_name; minor = renumbered_dst_col_name + major = renumbered_src_col_name + minor = renumbered_dst_col_name else: - major = renumbered_dst_col_name; minor = renumbered_src_col_name - shuffled_df = shuffled_df.rename(columns={'major_vertices':major, 'minor_vertices':minor}, copy=False) - edge_counts_64 = move(ptr_shuffled_32_64_64.get().get_edge_counts_wrap()) + major = renumbered_dst_col_name + minor = renumbered_src_col_name + shuffled_df = shuffled_df.rename( + columns={ + 'major_vertices': major, + 'minor_vertices': minor, + }, + copy=False) + edge_counts_64 = move( + ptr_shuffled_32_64_64.get().get_edge_counts_wrap()) else: shuffled_df = input_df edge_counts_64 = make_unique[vector[long]](1, num_local_edges) @@ -417,32 +484,37 @@ def renumber(input_df, # maybe use cpdef ? shuffled_src = minor_vertices.__cuda_array_interface__['data'][0] shuffled_dst = major_vertices.__cuda_array_interface__['data'][0] - ptr_renum_tuple_32_64.reset(call_renumber[int, long](deref(handle_ptr), - shuffled_src, - shuffled_dst, - deref(edge_counts_64.get()), - transposed, - do_check, - mg_flag).release()) + ptr_renum_tuple_32_64.reset(call_renumber[int, long]( + deref(handle_ptr), + shuffled_src, + shuffled_dst, + deref(edge_counts_64.get()), + transposed, + do_check, + mg_flag).release()) - pair_original = ptr_renum_tuple_32_64.get().get_dv_wrap() # original vertices: see helper + # original vertices: see helper + pair_original = ptr_renum_tuple_32_64.get().get_dv_wrap() original_series = move_device_buffer_to_series( move(pair_original.first), vertex_t, "original") # extract unique_ptr[partition_offsets]: # - uniq_partition_vector_32 = move(ptr_renum_tuple_32_64.get().get_partition_offsets_wrap()) + uniq_partition_vector_32 = move( + ptr_renum_tuple_32_64.get().get_partition_offsets_wrap()) # create series out of a partition range from rank to rank+1: # if is_multi_gpu: - new_series = cudf.Series(np.arange(uniq_partition_vector_32.get()[0].at(rank_indx), - uniq_partition_vector_32.get()[0].at(rank_indx+1)), - dtype=vertex_t) + new_series = cudf.Series( + np.arange(uniq_partition_vector_32.get()[0].at(rank_indx), + uniq_partition_vector_32.get()[0].at(rank_indx+1)), + dtype=vertex_t) else: - new_series = cudf.Series(np.arange(0, ptr_renum_tuple_32_64.get().get_num_vertices()), - dtype=vertex_t) + new_series = cudf.Series( + np.arange(0, ptr_renum_tuple_32_64.get().get_num_vertices()), + dtype=vertex_t) # create new cudf df # # and add the previous series to it: @@ -451,34 +523,46 @@ def renumber(input_df, # maybe use cpdef ? renumbered_map['original_ids'] = original_series renumbered_map['new_ids'] = new_series - uniq_segment_vector_32 = move(ptr_renum_tuple_32_64.get().get_segment_offsets_wrap()) - segment_offsets = [None] * (deref(uniq_segment_vector_32).size()) + uniq_segment_vector_32 = move( + ptr_renum_tuple_32_64.get().get_segment_offsets_wrap()) + segment_offsets = [None] * ( + deref(uniq_segment_vector_32).size()) for i in range(len(segment_offsets)): - segment_offsets[i] = deref(uniq_segment_vector_32)[i] + segment_offsets[i] = deref(uniq_segment_vector_32)[i] return renumbered_map, segment_offsets, shuffled_df - elif (vertex_t == np.dtype("int64")): - if ( edge_t == np.dtype("int64")): - if( weight_t == np.dtype("float32")): - if(is_multi_gpu): - ptr_shuffled_64_64_32.reset(call_shuffle[long, long, float](deref(handle_ptr), - c_major_vertices, - c_minor_vertices, - c_edge_weights, - num_local_edges, - weights is not None).release()) - - shuffled_df = renumber_helper(ptr_shuffled_64_64_32.get(), vertex_t, weights) + elif vertex_t == np.dtype("int64"): + if edge_t == np.dtype("int64"): + if weight_t == np.dtype("float32"): + if is_multi_gpu: + ptr_shuffled_64_64_32.reset(call_shuffle[long, long, float]( + deref(handle_ptr), + c_major_vertices, + c_minor_vertices, + c_edge_weights, + num_local_edges, + weights is not None).release()) + + shuffled_df = renumber_helper( + ptr_shuffled_64_64_32.get(), vertex_t, weights) major_vertices = shuffled_df['major_vertices'] minor_vertices = shuffled_df['minor_vertices'] num_local_edges = len(shuffled_df) if not transposed: - major = renumbered_src_col_name; minor = renumbered_dst_col_name + major = renumbered_src_col_name + minor = renumbered_dst_col_name else: - major = renumbered_dst_col_name; minor = renumbered_src_col_name - shuffled_df = shuffled_df.rename(columns={'major_vertices':major, 'minor_vertices':minor}, copy=False) - edge_counts_64 = move(ptr_shuffled_64_64_32.get().get_edge_counts_wrap()) + major = renumbered_dst_col_name + minor = renumbered_src_col_name + shuffled_df = shuffled_df.rename( + columns={ + 'major_vertices': major, + 'minor_vertices': minor, + }, + copy=False) + edge_counts_64 = move( + ptr_shuffled_64_64_32.get().get_edge_counts_wrap()) else: shuffled_df = input_df edge_counts_64 = make_unique[vector[long]](1, num_local_edges) @@ -490,32 +574,37 @@ def renumber(input_df, # maybe use cpdef ? shuffled_src = minor_vertices.__cuda_array_interface__['data'][0] shuffled_dst = major_vertices.__cuda_array_interface__['data'][0] - ptr_renum_tuple_64_64.reset(call_renumber[long, long](deref(handle_ptr), - shuffled_src, - shuffled_dst, - deref(edge_counts_64.get()), - transposed, - do_check, - mg_flag).release()) + ptr_renum_tuple_64_64.reset(call_renumber[long, long]( + deref(handle_ptr), + shuffled_src, + shuffled_dst, + deref(edge_counts_64.get()), + transposed, + do_check, + mg_flag).release()) - pair_original = ptr_renum_tuple_64_64.get().get_dv_wrap() # original vertices: see helper + # original vertices: see helper + pair_original = ptr_renum_tuple_64_64.get().get_dv_wrap() original_series = move_device_buffer_to_series( move(pair_original.first), vertex_t, "original") # extract unique_ptr[partition_offsets]: # - uniq_partition_vector_64 = move(ptr_renum_tuple_64_64.get().get_partition_offsets_wrap()) + uniq_partition_vector_64 = move( + ptr_renum_tuple_64_64.get().get_partition_offsets_wrap()) # create series out of a partition range from rank to rank+1: # if is_multi_gpu: - new_series = cudf.Series(np.arange(uniq_partition_vector_64.get()[0].at(rank_indx), - uniq_partition_vector_64.get()[0].at(rank_indx+1)), - dtype=vertex_t) + new_series = cudf.Series( + np.arange(uniq_partition_vector_64.get()[0].at(rank_indx), + uniq_partition_vector_64.get()[0].at(rank_indx+1)), + dtype=vertex_t) else: - new_series = cudf.Series(np.arange(0, ptr_renum_tuple_64_64.get().get_num_vertices()), - dtype=vertex_t) + new_series = cudf.Series( + np.arange(0, ptr_renum_tuple_64_64.get().get_num_vertices()), + dtype=vertex_t) # create new cudf df # @@ -525,32 +614,44 @@ def renumber(input_df, # maybe use cpdef ? renumbered_map['original_ids'] = original_series renumbered_map['new_ids'] = new_series - uniq_segment_vector_64 = move(ptr_renum_tuple_64_64.get().get_segment_offsets_wrap()) - segment_offsets = [None] * (deref(uniq_segment_vector_64).size()) + uniq_segment_vector_64 = move( + ptr_renum_tuple_64_64.get().get_segment_offsets_wrap()) + segment_offsets = [None] * ( + deref(uniq_segment_vector_64).size()) for i in range(len(segment_offsets)): - segment_offsets[i] = deref(uniq_segment_vector_64)[i] + segment_offsets[i] = deref(uniq_segment_vector_64)[i] return renumbered_map, segment_offsets, shuffled_df - elif( weight_t == np.dtype("float64")): - if(is_multi_gpu): - ptr_shuffled_64_64_64.reset(call_shuffle[long, long, double](deref(handle_ptr), - c_major_vertices, - c_minor_vertices, - c_edge_weights, - num_local_edges, - weights is not None).release()) - - shuffled_df = renumber_helper(ptr_shuffled_64_64_64.get(), vertex_t, weights) + elif weight_t == np.dtype("float64"): + if is_multi_gpu: + ptr_shuffled_64_64_64.reset(call_shuffle[long, long, double]( + deref(handle_ptr), + c_major_vertices, + c_minor_vertices, + c_edge_weights, + num_local_edges, + weights is not None).release()) + + shuffled_df = renumber_helper( + ptr_shuffled_64_64_64.get(), vertex_t, weights) major_vertices = shuffled_df['major_vertices'] minor_vertices = shuffled_df['minor_vertices'] num_local_edges = len(shuffled_df) if not transposed: - major = renumbered_src_col_name; minor = renumbered_dst_col_name + major = renumbered_src_col_name + minor = renumbered_dst_col_name else: - major = renumbered_dst_col_name; minor = renumbered_src_col_name - shuffled_df = shuffled_df.rename(columns={'major_vertices':major, 'minor_vertices':minor}, copy=False) - edge_counts_64 = move(ptr_shuffled_64_64_64.get().get_edge_counts_wrap()) + major = renumbered_dst_col_name + minor = renumbered_src_col_name + shuffled_df = shuffled_df.rename( + columns={ + 'major_vertices': major, + 'minor_vertices': minor, + }, + copy=False) + edge_counts_64 = move( + ptr_shuffled_64_64_64.get().get_edge_counts_wrap()) else: shuffled_df = input_df edge_counts_64 = make_unique[vector[long]](1, num_local_edges) @@ -562,32 +663,37 @@ def renumber(input_df, # maybe use cpdef ? shuffled_src = minor_vertices.__cuda_array_interface__['data'][0] shuffled_dst = major_vertices.__cuda_array_interface__['data'][0] - ptr_renum_tuple_64_64.reset(call_renumber[long, long](deref(handle_ptr), - shuffled_src, - shuffled_dst, - deref(edge_counts_64.get()), - transposed, - do_check, - mg_flag).release()) + ptr_renum_tuple_64_64.reset(call_renumber[long, long]( + deref(handle_ptr), + shuffled_src, + shuffled_dst, + deref(edge_counts_64.get()), + transposed, + do_check, + mg_flag).release()) - pair_original = ptr_renum_tuple_64_64.get().get_dv_wrap() # original vertices: see helper + # original vertices: see helper + pair_original = ptr_renum_tuple_64_64.get().get_dv_wrap() original_series = move_device_buffer_to_series( move(pair_original.first), vertex_t, "original") # extract unique_ptr[partition_offsets]: # - uniq_partition_vector_64 = move(ptr_renum_tuple_64_64.get().get_partition_offsets_wrap()) + uniq_partition_vector_64 = move( + ptr_renum_tuple_64_64.get().get_partition_offsets_wrap()) # create series out of a partition range from rank to rank+1: # if is_multi_gpu: - new_series = cudf.Series(np.arange(uniq_partition_vector_64.get()[0].at(rank_indx), - uniq_partition_vector_64.get()[0].at(rank_indx+1)), - dtype=vertex_t) + new_series = cudf.Series( + np.arange(uniq_partition_vector_64.get()[0].at(rank_indx), + uniq_partition_vector_64.get()[0].at(rank_indx+1)), + dtype=vertex_t) else: - new_series = cudf.Series(np.arange(0, ptr_renum_tuple_64_64.get().get_num_vertices()), - dtype=vertex_t) + new_series = cudf.Series( + np.arange(0, ptr_renum_tuple_64_64.get().get_num_vertices()), + dtype=vertex_t) # create new cudf df # @@ -597,9 +703,11 @@ def renumber(input_df, # maybe use cpdef ? renumbered_map['original_ids'] = original_series renumbered_map['new_ids'] = new_series - uniq_segment_vector_64 = move(ptr_renum_tuple_64_64.get().get_segment_offsets_wrap()) - segment_offsets = [None] * (deref(uniq_segment_vector_64).size()) + uniq_segment_vector_64 = move( + ptr_renum_tuple_64_64.get().get_segment_offsets_wrap()) + segment_offsets = [None] * ( + deref(uniq_segment_vector_64).size()) for i in range(len(segment_offsets)): - segment_offsets[i] = deref(uniq_segment_vector_64)[i] + segment_offsets[i] = deref(uniq_segment_vector_64)[i] return renumbered_map, segment_offsets, shuffled_df diff --git a/python/cugraph/cugraph/structure/utils.pxd b/python/cugraph/cugraph/structure/utils.pxd index 687109215bd..2089b8ea0f5 100644 --- a/python/cugraph/cugraph/structure/utils.pxd +++ b/python/cugraph/cugraph/structure/utils.pxd @@ -22,10 +22,10 @@ from libcpp.memory cimport unique_ptr cdef extern from "cugraph/legacy/functions.hpp" namespace "cugraph": - cdef unique_ptr[GraphCSR[VT,ET,WT]] coo_to_csr[VT,ET,WT]( - const GraphCOOView[VT,ET,WT] &graph) except + + cdef unique_ptr[GraphCSR[VT, ET, WT]] coo_to_csr[VT, ET, WT]( + const GraphCOOView[VT, ET, WT] &graph) except + cdef void comms_bcast[value_t]( - const handle_t &handle, - value_t *dst, - size_t size) except + + const handle_t &handle, + value_t *dst, + size_t size) except + diff --git a/python/cugraph/cugraph/structure/utils_wrapper.pyx b/python/cugraph/cugraph/structure/utils_wrapper.pyx index d8b14669789..ddf7fb2a485 100644 --- a/python/cugraph/cugraph/structure/utils_wrapper.pyx +++ b/python/cugraph/cugraph/structure/utils_wrapper.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021, NVIDIA CORPORATION. +# Copyright (c) 2020-2022, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -43,9 +43,10 @@ def create_csr_float(source_col, dest_col, weights): if weights is not None: c_weights = weights.__cuda_array_interface__['data'][0] - cdef GraphCOOView[int,int,float] in_graph - in_graph = GraphCOOView[int,int,float](c_src, c_dst, c_weights, num_verts, num_edges) - return csr_to_series(move(c_utils.coo_to_csr[int,int,float](in_graph))) + cdef GraphCOOView[int, int, float] in_graph + in_graph = GraphCOOView[int, int, float]( + c_src, c_dst, c_weights, num_verts, num_edges) + return csr_to_series(move(c_utils.coo_to_csr[int, int, float](in_graph))) def create_csr_double(source_col, dest_col, weights): @@ -59,14 +60,16 @@ def create_csr_double(source_col, dest_col, weights): if weights is not None: c_weights = weights.__cuda_array_interface__['data'][0] - cdef GraphCOOView[int,int,double] in_graph - in_graph = GraphCOOView[int,int,double](c_src, c_dst, c_weights, num_verts, num_edges) - return csr_to_series(move(c_utils.coo_to_csr[int,int,double](in_graph))) + cdef GraphCOOView[int, int, double] in_graph + in_graph = GraphCOOView[int, int, double]( + c_src, c_dst, c_weights, num_verts, num_edges) + return csr_to_series(move(c_utils.coo_to_csr[int, int, double](in_graph))) def coo2csr(source_col, dest_col, weights=None): if len(source_col) != len(dest_col): - raise Exception("source_col and dest_col should have the same number of elements") + raise Exception( + "source_col and dest_col should have the same number of elements") if source_col.dtype != dest_col.dtype: raise Exception("source_col and dest_col should be the same type") @@ -75,7 +78,11 @@ def coo2csr(source_col, dest_col, weights=None): raise Exception("source_col and dest_col must be type np.int32") if len(source_col) == 0: - return cudf.Series(np.zeros(1, dtype=np.int32)), cudf.Series(np.zeros(1, dtype=np.int32)), weights + return ( + cudf.Series(np.zeros(1, dtype=np.int32)), + cudf.Series(np.zeros(1, dtype=np.int32)), + weights, + ) if weight_type(weights) == np.float64: return create_csr_double(source_col, dest_col, weights) diff --git a/python/cugraph/cugraph/tree/minimum_spanning_tree.pxd b/python/cugraph/cugraph/tree/minimum_spanning_tree.pxd index 32c76ede554..5cf89f89bd0 100644 --- a/python/cugraph/cugraph/tree/minimum_spanning_tree.pxd +++ b/python/cugraph/cugraph/tree/minimum_spanning_tree.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -21,5 +21,6 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": - cdef unique_ptr[GraphCOO[VT,ET,WT]] minimum_spanning_tree[VT,ET,WT](const handle_t &handle, - const GraphCSRView[VT,ET,WT] &graph) except + + cdef unique_ptr[GraphCOO[VT, ET, WT]] minimum_spanning_tree[VT, ET, WT]( + const handle_t &handle, + const GraphCSRView[VT, ET, WT] &graph) except + diff --git a/python/cugraph/cugraph/tree/minimum_spanning_tree_wrapper.pyx b/python/cugraph/cugraph/tree/minimum_spanning_tree_wrapper.pyx index 7e51a07a5c2..d34aebcc8c5 100644 --- a/python/cugraph/cugraph/tree/minimum_spanning_tree_wrapper.pyx +++ b/python/cugraph/cugraph/tree/minimum_spanning_tree_wrapper.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021, NVIDIA CORPORATION. +# Copyright (c) 2020-2022, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -28,62 +28,70 @@ import cudf import numpy as np import cupy as cp + def mst_float(num_verts, num_edges, offsets, indices, weights): cdef unique_ptr[handle_t] handle_ptr handle_ptr.reset(new handle_t()) - handle_ = handle_ptr.get(); + handle_ = handle_ptr.get() cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,float] graph_float - graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, c_weights, num_verts, num_edges) - return coo_to_df(move(c_mst[int,int,float](handle_[0], graph_float))) + cdef GraphCSRView[int, int, float] graph_float + graph_float = GraphCSRView[int, int, float]( + c_offsets, c_indices, c_weights, num_verts, num_edges) + return coo_to_df(move(c_mst[int, int, float](handle_[0], graph_float))) def mst_double(num_verts, num_edges, offsets, indices, weights): cdef unique_ptr[handle_t] handle_ptr handle_ptr.reset(new handle_t()) - handle_ = handle_ptr.get(); + handle_ = handle_ptr.get() cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,double] graph_double - graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, c_weights, num_verts, num_edges) - return coo_to_df(move(c_mst[int,int,double](handle_[0], graph_double))) + cdef GraphCSRView[int, int, double] graph_double + graph_double = GraphCSRView[int, int, double]( + c_offsets, c_indices, c_weights, num_verts, num_edges) + return coo_to_df(move(c_mst[int, int, double](handle_[0], graph_double))) def minimum_spanning_tree(input_graph): if not input_graph.adjlist: input_graph.view_adj_list() - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) if input_graph.adjlist.weights is not None: - [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.weights], [np.float32, np.float64]) else: weights = cudf.Series(cp.full(num_edges, 1.0, dtype=np.float32)) if graph_primtypes_wrapper.weight_type(input_graph) == np.float32: - df = mst_float(num_verts, num_edges, offsets, indices, weights) - return df + df = mst_float(num_verts, num_edges, offsets, indices, weights) + return df else: return mst_double(num_verts, num_edges, offsets, indices, weights) + def maximum_spanning_tree(input_graph): if not input_graph.adjlist: input_graph.view_adj_list() - [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) if input_graph.adjlist.weights is not None: - [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast( + [input_graph.adjlist.weights], [np.float32, np.float64]) else: weights = cudf.Series(cp.full(num_edges, 1.0, dtype=np.float32)) if graph_primtypes_wrapper.weight_type(input_graph) == np.float32: - df = mst_float(num_verts, num_edges, offsets, indices, weights) - return df + df = mst_float(num_verts, num_edges, offsets, indices, weights) + return df else: return mst_double(num_verts, num_edges, offsets, indices, weights) diff --git a/python/cugraph/cugraph/utilities/path_retrieval.pxd b/python/cugraph/cugraph/utilities/path_retrieval.pxd index dcbbef5127d..2396f461518 100644 --- a/python/cugraph/cugraph/utilities/path_retrieval.pxd +++ b/python/cugraph/cugraph/utilities/path_retrieval.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2021, NVIDIA CORPORATION. +# Copyright (c) 2021-2022, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -20,10 +20,11 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/utilities/path_retrieval.hpp" namespace "cugraph": - cdef void get_traversed_cost[vertex_t, weight_t](const handle_t &handle, - const vertex_t *vertices, - const vertex_t *preds, - const weight_t *info_weights, - weight_t *out, - vertex_t stop_vertex, - vertex_t num_vertices) except + + cdef void get_traversed_cost[vertex_t, weight_t]( + const handle_t &handle, + const vertex_t *vertices, + const vertex_t *preds, + const weight_t *info_weights, + weight_t *out, + vertex_t stop_vertex, + vertex_t num_vertices) except + diff --git a/python/cugraph/cugraph/utilities/path_retrieval_wrapper.pyx b/python/cugraph/cugraph/utilities/path_retrieval_wrapper.pyx index 98d11ad07df..062a63e1d0a 100644 --- a/python/cugraph/cugraph/utilities/path_retrieval_wrapper.pyx +++ b/python/cugraph/cugraph/utilities/path_retrieval_wrapper.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2021, NVIDIA CORPORATION. +# Copyright (c) 2021-2022, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -38,7 +38,7 @@ def get_traversed_cost(input_df, stop_vertex): cdef unique_ptr[handle_t] handle_ptr handle_ptr.reset(new handle_t()) - handle_ = handle_ptr.get(); + handle_ = handle_ptr.get() cdef uintptr_t vertices = NULL cdef uintptr_t preds = NULL @@ -51,7 +51,8 @@ def get_traversed_cost(input_df, stop_vertex): out = df['info'].__cuda_array_interface__['data'][0] if weight_t == np.float32: - c_get_traversed_cost(handle_[0], + c_get_traversed_cost( + handle_[0], vertices, preds, info_weights, @@ -59,7 +60,8 @@ def get_traversed_cost(input_df, stop_vertex): stop_vertex, num_verts) elif weight_t == np.float64: - c_get_traversed_cost(handle_[0], + c_get_traversed_cost( + handle_[0], vertices, preds, info_weights, diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/algorithms.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/algorithms.pxd index be377257d46..3de813d62f6 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/algorithms.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/algorithms.pxd @@ -135,7 +135,7 @@ cdef extern from "cugraph_c/algorithms.h": cugraph_random_walk_result_get_path_sizes( cugraph_random_walk_result_t* result ) - + cdef size_t \ cugraph_random_walk_result_get_max_path_length( cugraph_random_walk_result_t* result @@ -160,7 +160,6 @@ cdef extern from "cugraph_c/algorithms.h": cugraph_error_t** error ) - ########################################################################### # sampling ctypedef struct cugraph_sample_result_t: @@ -222,7 +221,7 @@ cdef extern from "cugraph_c/algorithms.h": cugraph_random_walk_result_t** result, cugraph_error_t** error ) - + # biased random walks cdef cugraph_error_code_t \ cugraph_based_random_walks( diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/centrality_algorithms.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/centrality_algorithms.pxd index 8e8b1c8e923..9981d04e0f8 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/centrality_algorithms.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/centrality_algorithms.pxd @@ -56,8 +56,8 @@ cdef extern from "cugraph_c/centrality_algorithms.h": cugraph_pagerank( const cugraph_resource_handle_t* handle, cugraph_graph_t* graph, - const cugraph_type_erased_device_array_view_t* precomputed_vertex_out_weight_vertices, - const cugraph_type_erased_device_array_view_t* precomputed_vertex_out_weight_sums, + const cugraph_type_erased_device_array_view_t* precomputed_vertex_out_weight_vertices, # noqa: E501 + const cugraph_type_erased_device_array_view_t* precomputed_vertex_out_weight_sums, # noqa: E501 const cugraph_type_erased_device_array_view_t* initial_guess_vertices, const cugraph_type_erased_device_array_view_t* initial_guess_values, double alpha, @@ -72,8 +72,8 @@ cdef extern from "cugraph_c/centrality_algorithms.h": cugraph_personalized_pagerank( const cugraph_resource_handle_t* handle, cugraph_graph_t* graph, - const cugraph_type_erased_device_array_view_t* precomputed_vertex_out_weight_vertices, - const cugraph_type_erased_device_array_view_t* precomputed_vertex_out_weight_sums, + const cugraph_type_erased_device_array_view_t* precomputed_vertex_out_weight_vertices, # noqa: E501 + const cugraph_type_erased_device_array_view_t* precomputed_vertex_out_weight_sums, # noqa: E501 const cugraph_type_erased_device_array_view_t* initial_guess_vertices, const cugraph_type_erased_device_array_view_t* initial_guess_values, const cugraph_type_erased_device_array_view_t* personalization_vertices, @@ -98,7 +98,7 @@ cdef extern from "cugraph_c/centrality_algorithms.h": cugraph_centrality_result_t** result, cugraph_error_t** error ) - + ########################################################################### # katz centrality cdef cugraph_error_code_t \ @@ -124,17 +124,17 @@ cdef extern from "cugraph_c/centrality_algorithms.h": cugraph_hits_result_get_vertices( cugraph_hits_result_t* result ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_hits_result_get_hubs( cugraph_hits_result_t* result ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_hits_result_get_authorities( cugraph_hits_result_t* result ) - + cdef void \ cugraph_hits_result_free( cugraph_hits_result_t* result diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/community_algorithms.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/community_algorithms.pxd index 90ae44cbead..4dbfba55fa6 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/community_algorithms.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/community_algorithms.pxd @@ -45,17 +45,17 @@ cdef extern from "cugraph_c/community_algorithms.h": cugraph_triangle_count_result_get_vertices( cugraph_triangle_count_result_t* result ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_triangle_count_result_get_counts( cugraph_triangle_count_result_t* result ) - + cdef void \ cugraph_triangle_count_result_free( cugraph_triangle_count_result_t* result ) - + cdef cugraph_error_code_t \ cugraph_triangle_count( const cugraph_resource_handle_t* handle, @@ -80,10 +80,10 @@ cdef extern from "cugraph_c/community_algorithms.h": cugraph_heirarchical_clustering_result_get_clusters( cugraph_heirarchical_clustering_result_t* result ) - + cdef double cugraph_heirarchical_clustering_result_get_modularity( cugraph_heirarchical_clustering_result_t* result - ) + ) cdef void \ cugraph_heirarchical_clustering_result_free( @@ -100,7 +100,7 @@ cdef extern from "cugraph_c/community_algorithms.h": cugraph_heirarchical_clustering_result_t** result, cugraph_error_t** error ) - + # extract_ego cdef cugraph_error_code_t \ cugraph_extract_ego( diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/core_algorithms.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/core_algorithms.pxd index 4d3509e8b7f..8d5d7c346cd 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/core_algorithms.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/core_algorithms.pxd @@ -36,7 +36,7 @@ cdef extern from "cugraph_c/core_algorithms.h": # core number ctypedef struct cugraph_core_result_t: pass - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_core_result_get_vertices( cugraph_core_result_t* result @@ -46,7 +46,7 @@ cdef extern from "cugraph_c/core_algorithms.h": cugraph_core_result_get_core_numbers( cugraph_core_result_t* result ) - + cdef void \ cugraph_core_result_free( cugraph_core_result_t* result @@ -66,7 +66,7 @@ cdef extern from "cugraph_c/core_algorithms.h": cugraph_core_result_t** result, cugraph_error_t** error ) - + ########################################################################### # k-core ctypedef struct cugraph_k_core_result_t: @@ -76,22 +76,22 @@ cdef extern from "cugraph_c/core_algorithms.h": cugraph_k_core_result_get_src_vertices( cugraph_k_core_result_t* result ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_k_core_result_get_dst_vertices( cugraph_k_core_result_t* result ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_k_core_result_get_weights( cugraph_k_core_result_t* result ) - + cdef void \ cugraph_k_core_result_free( cugraph_k_core_result_t* result ) - + cdef cugraph_error_code_t \ cugraph_core_result_create( const cugraph_resource_handle_t* handle, @@ -100,7 +100,7 @@ cdef extern from "cugraph_c/core_algorithms.h": cugraph_core_result_t** core_result, cugraph_error_t** error ) - + cdef cugraph_error_code_t \ cugraph_k_core( const cugraph_resource_handle_t* handle, diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/error.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/error.pxd index 4b20daa1135..7dee4a5eb74 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/error.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/error.pxd @@ -26,7 +26,7 @@ cdef extern from "cugraph_c/error.h": CUGRAPH_UNSUPPORTED_TYPE_COMBINATION ctypedef struct cugraph_error_t: - pass + pass const char* \ cugraph_error_message( diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/graph.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/graph.pxd index 590c5679264..39ec4e766da 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/graph.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/graph.pxd @@ -38,19 +38,20 @@ cdef extern from "cugraph_c/graph.h": bool_t is_multigraph cdef cugraph_error_code_t \ - cugraph_sg_graph_create( - const cugraph_resource_handle_t* handle, - const cugraph_graph_properties_t* properties, - const cugraph_type_erased_device_array_view_t* src, - const cugraph_type_erased_device_array_view_t* dst, - const cugraph_type_erased_device_array_view_t* weights, - const cugraph_type_erased_device_array_view_t* edge_ids, - const cugraph_type_erased_device_array_view_t* edge_types, - bool_t store_transposed, - bool_t renumber, - bool_t check, - cugraph_graph_t** graph, - cugraph_error_t** error) + cugraph_sg_graph_create( + const cugraph_resource_handle_t* handle, + const cugraph_graph_properties_t* properties, + const cugraph_type_erased_device_array_view_t* src, + const cugraph_type_erased_device_array_view_t* dst, + const cugraph_type_erased_device_array_view_t* weights, + const cugraph_type_erased_device_array_view_t* edge_ids, + const cugraph_type_erased_device_array_view_t* edge_types, + bool_t store_transposed, + bool_t renumber, + bool_t check, + cugraph_graph_t** graph, + cugraph_error_t** error + ) # This may get renamed to cugraph_graph_free() cdef void \ @@ -79,7 +80,7 @@ cdef extern from "cugraph_c/graph.h": cugraph_mg_graph_free( cugraph_graph_t* graph ) - + cdef cugraph_error_code_t \ cugraph_sg_graph_create_from_csr( const cugraph_resource_handle_t* handle, @@ -95,12 +96,12 @@ cdef extern from "cugraph_c/graph.h": cugraph_graph_t** graph, cugraph_error_t** error ) - + cdef void \ cugraph_sg_graph_free( cugraph_graph_t* graph ) - + cdef cugraph_error_code_t \ cugraph_mg_graph_create( const cugraph_resource_handle_t* handle, @@ -116,7 +117,7 @@ cdef extern from "cugraph_c/graph.h": cugraph_graph_t** graph, cugraph_error_t** error ) - + cdef void \ cugraph_mg_graph_free( cugraph_graph_t* graph diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/graph_functions.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/graph_functions.pxd index f18e9848182..eab1e5cf09d 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/graph_functions.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/graph_functions.pxd @@ -36,13 +36,13 @@ from pylibcugraph._cugraph_c.array cimport ( ) cdef extern from "cugraph_c/graph_functions.h": - #""" - #ctypedef struct cugraph_similarity_result_t: - # pass - #""" + # """ + # ctypedef struct cugraph_similarity_result_t: + # pass + # """ ctypedef struct cugraph_vertex_pairs_t: pass - + from pylibcugraph._cugraph_c.error cimport ( cugraph_error_code_t, @@ -61,22 +61,22 @@ cdef extern from "cugraph_c/graph_functions.h": # vertex_pairs ctypedef struct cugraph_vertex_pairs_t: pass - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_vertex_pairs_get_first( cugraph_vertex_pairs_t* vertex_pairs ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_vertex_pairs_get_second( cugraph_vertex_pairs_t* vertex_pairs ) - + cdef void \ cugraph_vertex_pairs_free( cugraph_vertex_pairs_t* vertex_pairs ) - + cdef cugraph_error_code_t \ cugraph_create_vertex_pairs( const cugraph_resource_handle_t* handle, @@ -86,21 +86,21 @@ cdef extern from "cugraph_c/graph_functions.h": cugraph_vertex_pairs_t** vertex_pairs, cugraph_error_t** error ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_vertex_pairs_get_first( cugraph_vertex_pairs_t* vertex_pairs ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_vertex_pairs_get_second( cugraph_vertex_pairs_t* vertex_pairs ) - + cdef void cugraph_vertex_pairs_free( cugraph_vertex_pairs_t* vertex_pairs - ) - + ) + cdef cugraph_error_code_t cugraph_two_hop_neighbors( const cugraph_resource_handle_t* handle, const cugraph_graph_t* graph, @@ -117,7 +117,7 @@ cdef extern from "cugraph_c/graph_functions.h": cugraph_vertex_pairs_t** result, cugraph_error_t** error ) - + ########################################################################### # induced_subgraph ctypedef struct cugraph_induced_subgraph_result_t: @@ -127,27 +127,27 @@ cdef extern from "cugraph_c/graph_functions.h": cugraph_induced_subgraph_get_sources( cugraph_induced_subgraph_result_t* induced_subgraph ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_induced_subgraph_get_destinations( cugraph_induced_subgraph_result_t* induced_subgraph ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_induced_subgraph_get_edge_weights( cugraph_induced_subgraph_result_t* induced_subgraph ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_induced_subgraph_get_subgraph_offsets( cugraph_induced_subgraph_result_t* induced_subgraph ) - + cdef void \ cugraph_induced_subgraph_result_free( cugraph_induced_subgraph_result_t* induced_subgraph ) - + cdef cugraph_error_code_t \ cugraph_extract_induced_subgraph( const cugraph_resource_handle_t* handle, diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/labeling_algorithms.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/labeling_algorithms.pxd index 7c911235a54..e1072d4c24c 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/labeling_algorithms.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/labeling_algorithms.pxd @@ -41,17 +41,17 @@ cdef extern from "cugraph_c/labeling_algorithms.h": cugraph_labeling_result_get_vertices( cugraph_labeling_result_t* result ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_labeling_result_get_labels( cugraph_labeling_result_t* result ) - + cdef void \ cugraph_labeling_result_free( cugraph_labeling_result_t* result ) - + cdef cugraph_error_code_t \ cugraph_weakly_connected_components( const cugraph_resource_handle_t* handle, @@ -60,4 +60,3 @@ cdef extern from "cugraph_c/labeling_algorithms.h": cugraph_labeling_result_t** result, cugraph_error_t** error ) - \ No newline at end of file diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/resource_handle.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/resource_handle.pxd index 633107a1acb..df688a08760 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/resource_handle.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/resource_handle.pxd @@ -36,17 +36,14 @@ cdef extern from "cugraph_c/resource_handle.h": pass # FIXME: the void* raft_handle arg will change in a future release - cdef cugraph_resource_handle_t* \ - cugraph_create_resource_handle( - void* raft_handle - ) - - cdef int \ - cugraph_resource_handle_get_rank( - const cugraph_resource_handle_t* handle - ) - - cdef void \ - cugraph_free_resource_handle( - cugraph_resource_handle_t* p_handle - ) + cdef cugraph_resource_handle_t* cugraph_create_resource_handle( + void* raft_handle + ) + + cdef int cugraph_resource_handle_get_rank( + const cugraph_resource_handle_t* handle + ) + + cdef void cugraph_free_resource_handle( + cugraph_resource_handle_t* p_handle + ) diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/similarity_algorithms.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/similarity_algorithms.pxd index 0d98bb8e14a..6f20096a428 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/similarity_algorithms.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/similarity_algorithms.pxd @@ -36,21 +36,21 @@ from pylibcugraph._cugraph_c.graph_functions cimport ( cdef extern from "cugraph_c/similarity_algorithms.h": ########################################################################### - #""" + # """ ctypedef struct cugraph_similarity_result_t: pass - #""" + # """ cdef cugraph_type_erased_device_array_view_t* \ cugraph_similarity_result_get_similarity( cugraph_similarity_result_t* result ) - + cdef void \ cugraph_similarity_result_free( cugraph_similarity_result_t* result ) - + ########################################################################### # jaccard coefficients cdef cugraph_error_code_t \ diff --git a/python/pylibcugraph/pylibcugraph/bfs.pyx b/python/pylibcugraph/pylibcugraph/bfs.pyx index 6886e6b059a..0eb3da99918 100644 --- a/python/pylibcugraph/pylibcugraph/bfs.pyx +++ b/python/pylibcugraph/pylibcugraph/bfs.pyx @@ -56,8 +56,9 @@ from pylibcugraph.graphs cimport ( _GPUGraph, ) -def bfs(ResourceHandle handle, _GPUGraph graph, - sources, bool_t direction_optimizing, int32_t depth_limit, + +def bfs(ResourceHandle handle, _GPUGraph graph, + sources, bool_t direction_optimizing, int32_t depth_limit, bool_t compute_predecessors, bool_t do_expensive_check): """ Performs a Breadth-first search starting from the provided sources. @@ -108,10 +109,10 @@ def bfs(ResourceHandle handle, _GPUGraph graph, weights = G.edgelist.edgelist_df['weights'] sg = SGGraph( - resource_handle = handle, - graph_properties = GraphProperties(is_multigraph=G.is_multigraph()), - src_array = srcs, - dst_array = dsts, + resource_handle = handle, + graph_properties = GraphProperties(is_multigraph=G.is_multigraph()), + src_array = srcs, + dst_array = dsts, weight_array = weights, store_transposed=False, renumber=False, @@ -119,7 +120,7 @@ def bfs(ResourceHandle handle, _GPUGraph graph, ) res = pylibcugraph_bfs( - handle, + handle, sg, cudf.Series([0], dtype='int32'), False, @@ -129,7 +130,7 @@ def bfs(ResourceHandle handle, _GPUGraph graph, ) distances, predecessors, vertices = res - + final_results = cudf.DataFrame({ 'distance': cudf.Series(distances), 'vertex': cudf.Series(vertices), @@ -163,7 +164,7 @@ def bfs(ResourceHandle handle, _GPUGraph graph, cai_sources_ptr, len(sources), get_c_type_from_numpy_type(sources.dtype)) - + cdef cugraph_paths_result_t* result_ptr error_code = cugraph_bfs( @@ -185,7 +186,7 @@ def bfs(ResourceHandle handle, _GPUGraph graph, cdef cugraph_type_erased_device_array_view_t* predecessors_ptr = \ cugraph_paths_result_get_predecessors(result_ptr) - + cdef cugraph_type_erased_device_array_view_t* vertices_ptr = \ cugraph_paths_result_get_vertices(result_ptr) @@ -193,7 +194,7 @@ def bfs(ResourceHandle handle, _GPUGraph graph, cupy_distances = copy_to_cupy_array(c_resource_handle_ptr, distances_ptr) cupy_predecessors = copy_to_cupy_array(c_resource_handle_ptr, predecessors_ptr) cupy_vertices = copy_to_cupy_array(c_resource_handle_ptr, vertices_ptr) - + # deallocate the no-longer needed result struct cugraph_paths_result_free(result_ptr) diff --git a/python/pylibcugraph/pylibcugraph/components/_connectivity.pxd b/python/pylibcugraph/pylibcugraph/components/_connectivity.pxd index b1915ee108b..ff9fb17e12c 100644 --- a/python/pylibcugraph/pylibcugraph/components/_connectivity.pxd +++ b/python/pylibcugraph/pylibcugraph/components/_connectivity.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021, NVIDIA CORPORATION. +# Copyright (c) 2019-2022, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -27,8 +27,8 @@ cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": CUGRAPH_STRONG "cugraph::cugraph_cc_t::CUGRAPH_STRONG" NUM_CONNECTIVITY_TYPES "cugraph::cugraph_cc_t::NUM_CONNECTIVITY_TYPES" - cdef void connected_components[VT,ET,WT]( - const GraphCSRView[VT,ET,WT] &graph, + cdef void connected_components[VT, ET, WT]( + const GraphCSRView[VT, ET, WT] &graph, cugraph_cc_t connect_type, VT *labels) except + @@ -37,4 +37,3 @@ cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": const handle_t &handle, const graph_container_t &g, vertex_t *identifiers) except + - diff --git a/python/pylibcugraph/pylibcugraph/components/_connectivity.pyx b/python/pylibcugraph/pylibcugraph/components/_connectivity.pyx index 02e7549d1c5..c3d63a1b4d9 100644 --- a/python/pylibcugraph/pylibcugraph/components/_connectivity.pyx +++ b/python/pylibcugraph/pylibcugraph/components/_connectivity.pyx @@ -39,7 +39,9 @@ def _ensure_arg_types(**kwargs): raise TypeError(f"{arg_name} array must have a dtype of int32") -def strongly_connected_components(offsets, indices, weights, num_verts, num_edges, labels): +def strongly_connected_components( + offsets, indices, weights, num_verts, num_edges, labels +): """ Generate the Strongly Connected Components and attach a component label to each vertex. @@ -122,10 +124,10 @@ def strongly_connected_components(offsets, indices, weights, num_verts, num_edge cdef uintptr_t c_edge_weights = NULL cdef uintptr_t c_labels = labels.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int,int,float] g + cdef GraphCSRView[int, int, float] g - g = GraphCSRView[int,int,float](c_offsets, c_indices, NULL, num_verts, num_edges) + g = GraphCSRView[int, int, float]( + c_offsets, c_indices, NULL, num_verts, num_edges) cdef cugraph_cc_t connect_type=CUGRAPH_STRONG connected_components(g, connect_type, c_labels) - diff --git a/python/pylibcugraph/pylibcugraph/core_number.pyx b/python/pylibcugraph/pylibcugraph/core_number.pyx index 7d0c42f7dd0..ccc49a35850 100644 --- a/python/pylibcugraph/pylibcugraph/core_number.pyx +++ b/python/pylibcugraph/pylibcugraph/core_number.pyx @@ -31,7 +31,7 @@ from pylibcugraph._cugraph_c.array cimport ( from pylibcugraph._cugraph_c.graph cimport ( cugraph_graph_t, ) -from pylibcugraph._cugraph_c.core_algorithms cimport ( +from pylibcugraph._cugraph_c.core_algorithms cimport ( cugraph_core_result_t, cugraph_core_number, cugraph_k_core_degree_type_t, @@ -51,6 +51,7 @@ from pylibcugraph.utils cimport ( get_c_type_from_numpy_type, ) + def core_number(ResourceHandle resource_handle, _GPUGraph graph, degree_type, @@ -63,17 +64,17 @@ def core_number(ResourceHandle resource_handle, resource_handle: ResourceHandle Handle to the underlying device and host resource needed for referencing data and running algorithms. - + graph : SGGraph or MGGraph The input graph, for either Single or Multi-GPU operations. - + degree_type: str This option determines if the core number computation should be based on input, output, or both directed edges, with valid values being "incoming", "outgoing", and "bidirectional" respectively. This option is currently ignored in this release, and setting it will result in a warning. - + do_expensive_check: bool If True, performs more extensive tests on the inputs to ensure validity, at the expense of increased run time. diff --git a/python/pylibcugraph/pylibcugraph/egonet.pyx b/python/pylibcugraph/pylibcugraph/egonet.pyx index 639e4c386a7..862e22f103c 100644 --- a/python/pylibcugraph/pylibcugraph/egonet.pyx +++ b/python/pylibcugraph/pylibcugraph/egonet.pyx @@ -73,7 +73,7 @@ def ego_graph(ResourceHandle resource_handle, graph : SGGraph or MGGraph The input graph. - + source_vertices : cudf.Series The centered nodes from which the induced subgraph will be extracted @@ -124,10 +124,8 @@ def ego_graph(ResourceHandle resource_handle, cdef cugraph_error_code_t error_code cdef cugraph_error_t* error_ptr - cdef cugraph_type_erased_device_array_view_t* \ - source_vertices_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - source_vertices) + cdef cugraph_type_erased_device_array_view_t* source_vertices_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj(source_vertices) error_code = cugraph_extract_ego(c_resource_handle_ptr, c_graph_ptr, @@ -164,4 +162,4 @@ def ego_graph(ResourceHandle resource_handle, cugraph_induced_subgraph_result_free(result_ptr) return (cupy_sources, cupy_destinations, - cupy_edge_weights, cupy_subgraph_offsets) + cupy_edge_weights, cupy_subgraph_offsets) diff --git a/python/pylibcugraph/pylibcugraph/eigenvector_centrality.pyx b/python/pylibcugraph/pylibcugraph/eigenvector_centrality.pyx index 88612c242e2..20014e80546 100644 --- a/python/pylibcugraph/pylibcugraph/eigenvector_centrality.pyx +++ b/python/pylibcugraph/pylibcugraph/eigenvector_centrality.pyx @@ -127,7 +127,7 @@ def eigenvector_centrality(ResourceHandle resource_handle, cugraph_centrality_result_get_vertices(result_ptr) cdef cugraph_type_erased_device_array_view_t* values_ptr = \ cugraph_centrality_result_get_values(result_ptr) - + cupy_vertices = copy_to_cupy_array(c_resource_handle_ptr, vertices_ptr) cupy_values = copy_to_cupy_array(c_resource_handle_ptr, values_ptr) diff --git a/python/pylibcugraph/pylibcugraph/graph_properties.pxd b/python/pylibcugraph/pylibcugraph/graph_properties.pxd index 491c343480d..628da39846a 100644 --- a/python/pylibcugraph/pylibcugraph/graph_properties.pxd +++ b/python/pylibcugraph/pylibcugraph/graph_properties.pxd @@ -14,9 +14,7 @@ # Have cython use python 3 syntax # cython: language_level = 3 -from pylibcugraph._cugraph_c.graph cimport ( - cugraph_graph_properties_t, -) +from pylibcugraph._cugraph_c.graph cimport cugraph_graph_properties_t cdef class GraphProperties: diff --git a/python/pylibcugraph/pylibcugraph/graph_properties.pyx b/python/pylibcugraph/pylibcugraph/graph_properties.pyx index ad1431900f6..c0f3565045e 100644 --- a/python/pylibcugraph/pylibcugraph/graph_properties.pyx +++ b/python/pylibcugraph/pylibcugraph/graph_properties.pyx @@ -26,7 +26,7 @@ cdef class GraphProperties: def __getnewargs_ex__(self): is_symmetric = self.c_graph_properties.is_symmetric is_multigraph = self.c_graph_properties.is_multigraph - return ((),{"is_symmetric":is_symmetric, "is_multigraph":is_multigraph}) + return ((), {"is_symmetric": is_symmetric, "is_multigraph": is_multigraph}) def __getstate__(self): return () diff --git a/python/pylibcugraph/pylibcugraph/graphs.pxd b/python/pylibcugraph/pylibcugraph/graphs.pxd index e468738f529..62a3ef999a6 100644 --- a/python/pylibcugraph/pylibcugraph/graphs.pxd +++ b/python/pylibcugraph/pylibcugraph/graphs.pxd @@ -28,5 +28,4 @@ cdef class SGGraph(_GPUGraph): pass cdef class MGGraph(_GPUGraph): - pass - + pass diff --git a/python/pylibcugraph/pylibcugraph/graphs.pyx b/python/pylibcugraph/pylibcugraph/graphs.pyx index 7640f5cdee5..70a0c3954a0 100644 --- a/python/pylibcugraph/pylibcugraph/graphs.pyx +++ b/python/pylibcugraph/pylibcugraph/graphs.pyx @@ -74,7 +74,7 @@ cdef class SGGraph(_GPUGraph): Object defining intended properties for the graph. src_or_offset_array : device array type - Device array containing either the vertex identifiers of the source of + Device array containing either the vertex identifiers of the source of each directed edge if represented in COO format or the offset if CSR format. In the case of a COO, the order of the array corresponds to the ordering of the dst_or_index_array, where the ith item in @@ -106,22 +106,22 @@ cdef class SGGraph(_GPUGraph): do_expensive_check : bool If True, performs more extensive tests on the inputs to ensure validitity, at the expense of increased run time. - + edge_id_array : device array type Device array containing the edge ids of each directed edge. Must match the ordering of the src/dst arrays. Optional (may be null). If provided, edge_type_array must also be provided. - + edge_type_array : device array type Device array containing the edge types of each directed edge. Must match the ordering of the src/dst/edge_id arrays. Optional (may be null). If provided, edge_id_array must be provided. - + input_array_format: str, optional (default='COO') Input representation used to construct a graph COO: arrays represent src_array and dst_array CSR: arrays represent offset_array and index_array - + Examples --------- >>> import pylibcugraph, cupy, numpy @@ -168,7 +168,8 @@ cdef class SGGraph(_GPUGraph): if edge_type_array is not None: assert_CAI_type(edge_type_array, "edge_type_array") - # FIXME: assert that src_or_offset_array and dst_or_index_array have the same type + # FIXME: assert that src_or_offset_array and dst_or_index_array have + # the same type cdef cugraph_error_t* error_ptr cdef cugraph_error_code_t error_code @@ -210,7 +211,7 @@ cdef class SGGraph(_GPUGraph): &error_ptr) assert_success(error_code, error_ptr, - "cugraph_sg_graph_create()") + "cugraph_sg_graph_create()") elif input_array_format == "CSR": error_code = cugraph_sg_graph_create_from_csr( @@ -228,11 +229,12 @@ cdef class SGGraph(_GPUGraph): &error_ptr) assert_success(error_code, error_ptr, - "cugraph_sg_graph_create_from_csr()") - + "cugraph_sg_graph_create_from_csr()") + else: - raise ValueError("invalid 'input_array_format'. Only " - "'COO' and 'CSR' format are supported." + raise ValueError( + "invalid 'input_array_format'. Only 'COO' and 'CSR' format " + "are supported." ) cugraph_type_erased_device_array_view_free(srcs_or_offsets_view_ptr) @@ -283,10 +285,10 @@ cdef class MGGraph(_GPUGraph): store_transposed : bool Set to True if the graph should be transposed. This is required for some algorithms, such as pagerank. - + num_edges : int Number of edges - + do_expensive_check : bool If True, performs more extensive tests on the inputs to ensure validitity, at the expense of increased run time. @@ -295,7 +297,7 @@ cdef class MGGraph(_GPUGraph): Device array containing the edge ids of each directed edge. Must match the ordering of the src/dst arrays. Optional (may be null). If provided, edge_type_array must also be provided. - + edge_type_array : device array type Device array containing the edge types of each directed edge. Must match the ordering of the src/dst/edge_id arrays. Optional (may be @@ -331,7 +333,7 @@ cdef class MGGraph(_GPUGraph): if edge_id_array is not None: assert_CAI_type(edge_id_array, "edge_id_array") if edge_type_array is not None: - assert_CAI_type(edge_type_array, "edge_type_array") + assert_CAI_type(edge_type_array, "edge_type_array") # FIXME: assert that src_array and dst_array have the same type diff --git a/python/pylibcugraph/pylibcugraph/hits.pyx b/python/pylibcugraph/pylibcugraph/hits.pyx index 7c472f54866..0615a1cf77c 100644 --- a/python/pylibcugraph/pylibcugraph/hits.pyx +++ b/python/pylibcugraph/pylibcugraph/hits.pyx @@ -55,14 +55,16 @@ from pylibcugraph.utils cimport ( ) -def hits(ResourceHandle resource_handle, - _GPUGraph graph, - double tol, - size_t max_iter, - initial_hubs_guess_vertices, - initial_hubs_guess_values, - bool_t normalized, - bool_t do_expensive_check): +def hits( + ResourceHandle resource_handle, + _GPUGraph graph, + double tol, + size_t max_iter, + initial_hubs_guess_vertices, + initial_hubs_guess_values, + bool_t normalized, + bool_t do_expensive_check +): """ Compute HITS hubs and authorities values for each vertex @@ -78,7 +80,7 @@ def hits(ResourceHandle resource_handle, graph : SGGraph or MGGraph The input graph, for either Single or Multi-GPU operations. - + tol : float, optional (default=1.0e-5) Set the tolerance the approximation, this parameter should be a small magnitude value. This parameter is not currently supported. @@ -104,7 +106,7 @@ def hits(ResourceHandle resource_handle, A tuple of device arrays, where the third item in the tuple is a device array containing the vertex identifiers, the first and second items are device arrays containing respectively the hubs and authorities values for the corresponding - vertices + vertices Examples -------- @@ -115,30 +117,32 @@ def hits(ResourceHandle resource_handle, cdef uintptr_t cai_initial_hubs_guess_vertices_ptr = NULL cdef uintptr_t cai_initial_hubs_guess_values_ptr = NULL - cdef cugraph_type_erased_device_array_view_t* initial_hubs_guess_vertices_view_ptr = NULL - cdef cugraph_type_erased_device_array_view_t* initial_hubs_guess_values_view_ptr = NULL + cdef cugraph_type_erased_device_array_view_t* \ + initial_hubs_guess_vertices_view_ptr = NULL + cdef cugraph_type_erased_device_array_view_t* \ + initial_hubs_guess_values_view_ptr = NULL - # FIXME: Add check ensuring that both initial_hubs_guess_vertices + # FIXME: Add check ensuring that both initial_hubs_guess_vertices # and initial_hubs_guess_values are passed when calling only pylibcugraph HITS. # This is already True for cugraph HITS - - if initial_hubs_guess_vertices is not None: + + if initial_hubs_guess_vertices is not None: assert_CAI_type(initial_hubs_guess_vertices, "initial_hubs_guess_vertices") - + cai_initial_hubs_guess_vertices_ptr = \ - initial_hubs_guess_vertices.__cuda_array_interface__["data"][0] + initial_hubs_guess_vertices.__cuda_array_interface__["data"][0] initial_hubs_guess_vertices_view_ptr = \ cugraph_type_erased_device_array_view_create( cai_initial_hubs_guess_vertices_ptr, len(initial_hubs_guess_vertices), get_c_type_from_numpy_type(initial_hubs_guess_vertices.dtype)) - + if initial_hubs_guess_values is not None: assert_CAI_type(initial_hubs_guess_values, "initial_hubs_guess_values") cai_initial_hubs_guess_values_ptr = \ - initial_hubs_guess_values.__cuda_array_interface__["data"][0] + initial_hubs_guess_values.__cuda_array_interface__["data"][0] initial_hubs_guess_values_view_ptr = \ cugraph_type_erased_device_array_view_create( @@ -179,13 +183,13 @@ def hits(ResourceHandle resource_handle, cupy_hubs = copy_to_cupy_array(c_resource_handle_ptr, hubs_ptr) cupy_authorities = copy_to_cupy_array(c_resource_handle_ptr, authorities_ptr) - + cugraph_hits_result_free(result_ptr) if initial_hubs_guess_vertices is not None: cugraph_type_erased_device_array_view_free( initial_hubs_guess_vertices_view_ptr) - + if initial_hubs_guess_values is not None: cugraph_type_erased_device_array_view_free( initial_hubs_guess_values_view_ptr) diff --git a/python/pylibcugraph/pylibcugraph/jaccard_coefficients.pyx b/python/pylibcugraph/pylibcugraph/jaccard_coefficients.pyx index 805ee821eab..ee0e2da4f28 100644 --- a/python/pylibcugraph/pylibcugraph/jaccard_coefficients.pyx +++ b/python/pylibcugraph/pylibcugraph/jaccard_coefficients.pyx @@ -57,15 +57,17 @@ from pylibcugraph.utils cimport ( ) -def EXPERIMENTAL__jaccard_coefficients(ResourceHandle resource_handle, - _GPUGraph graph, - first, - second, - bool_t use_weight, - bool_t do_expensive_check): +def EXPERIMENTAL__jaccard_coefficients( + ResourceHandle resource_handle, + _GPUGraph graph, + first, + second, + bool_t use_weight, + bool_t do_expensive_check +): """ Compute the Jaccard coefficients for the specified vertex_pairs. - + Note that Jaccard similarity must run on a symmetric graph. Parameters @@ -76,13 +78,13 @@ def EXPERIMENTAL__jaccard_coefficients(ResourceHandle resource_handle, graph : SGGraph or MGGraph The input graph, for either Single or Multi-GPU operations. - + first : Source of the vertex pair. - + second : Destination of the vertex pair. - + use_weight : bool, optional (default=False) Currently not supported @@ -112,16 +114,12 @@ def EXPERIMENTAL__jaccard_coefficients(ResourceHandle resource_handle, cdef cugraph_error_t* error_ptr # 'first' is a required parameter - cdef cugraph_type_erased_device_array_view_t* \ - first_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - first) + cdef cugraph_type_erased_device_array_view_t* first_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj(first) # 'second' is a required parameter - cdef cugraph_type_erased_device_array_view_t* \ - second_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - second) + cdef cugraph_type_erased_device_array_view_t* second_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj(second) error_code = cugraph_create_vertex_pairs(c_resource_handle_ptr, c_graph_ptr, diff --git a/python/pylibcugraph/pylibcugraph/k_core.pyx b/python/pylibcugraph/pylibcugraph/k_core.pyx index 50344469b11..010a9270b5b 100644 --- a/python/pylibcugraph/pylibcugraph/k_core.pyx +++ b/python/pylibcugraph/pylibcugraph/k_core.pyx @@ -31,7 +31,7 @@ from pylibcugraph._cugraph_c.array cimport ( from pylibcugraph._cugraph_c.graph cimport ( cugraph_graph_t, ) -from pylibcugraph._cugraph_c.core_algorithms cimport ( +from pylibcugraph._cugraph_c.core_algorithms cimport ( cugraph_core_result_t, cugraph_k_core_result_t, cugraph_core_result_create, @@ -55,6 +55,7 @@ from pylibcugraph.utils cimport ( create_cugraph_type_erased_device_array_view_from_py_obj, ) + def k_core(ResourceHandle resource_handle, _GPUGraph graph, size_t k, @@ -72,21 +73,21 @@ def k_core(ResourceHandle resource_handle, resource_handle: ResourceHandle Handle to the underlying device and host resource needed for referencing data and running algorithms. - + graph : SGGraph or MGGraph The input graph, for either Single or Multi-GPU operations. - + k : size_t (default=None) Order of the core. This value must not be negative. If set to None the main core is returned. - + degree_type: str This option determines if the core number computation should be based on input, output, or both directed edges, with valid values being "incoming", "outgoing", and "bidirectional" respectively. This option is currently ignored in this release, and setting it will result in a warning. - + core_result : device array type Precomputed core number of the nodes of the graph G If set to None, the core numbers of the nodes are calculated @@ -115,22 +116,17 @@ def k_core(ResourceHandle resource_handle, cdef cugraph_error_code_t error_code cdef cugraph_error_t* error_ptr - degree_type_map = { "incoming": cugraph_k_core_degree_type_t.K_CORE_DEGREE_TYPE_IN, "outgoing": cugraph_k_core_degree_type_t.K_CORE_DEGREE_TYPE_OUT, "bidirectional": cugraph_k_core_degree_type_t.K_CORE_DEGREE_TYPE_INOUT} - cdef cugraph_type_erased_device_array_view_t* \ - vertices_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - core_result["vertex"]) - - cdef cugraph_type_erased_device_array_view_t* \ - core_numbers_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - core_result["values"]) - + cdef cugraph_type_erased_device_array_view_t* vertices_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj(core_result["vertex"]) + + cdef cugraph_type_erased_device_array_view_t* core_numbers_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj(core_result["values"]) + # Create a core_number result error_code = cugraph_core_result_create(c_resource_handle_ptr, vertices_view_ptr, @@ -139,7 +135,6 @@ def k_core(ResourceHandle resource_handle, &error_ptr) assert_success(error_code, error_ptr, "cugraph_core_result_create") - # compute k_core error_code = cugraph_k_core(c_resource_handle_ptr, c_graph_ptr, @@ -151,7 +146,6 @@ def k_core(ResourceHandle resource_handle, &error_ptr) assert_success(error_code, error_ptr, "cugraph_k_core_number") - cdef cugraph_type_erased_device_array_view_t* src_vertices_ptr = \ cugraph_k_core_result_get_src_vertices(k_core_result_ptr) cdef cugraph_type_erased_device_array_view_t* dst_vertices_ptr = \ diff --git a/python/pylibcugraph/pylibcugraph/katz_centrality.pyx b/python/pylibcugraph/pylibcugraph/katz_centrality.pyx index 0f08e690f92..8652f651d0a 100644 --- a/python/pylibcugraph/pylibcugraph/katz_centrality.pyx +++ b/python/pylibcugraph/pylibcugraph/katz_centrality.pyx @@ -97,7 +97,7 @@ def katz_centrality(ResourceHandle resource_handle, do_expensive_check : bool_t A flag to run expensive checks for input arguments if True. - + Returns ------- @@ -114,9 +114,9 @@ def katz_centrality(ResourceHandle resource_handle, cdef cugraph_error_code_t error_code cdef cugraph_error_t* error_ptr - cdef uintptr_t cai_betas_ptr + cdef uintptr_t cai_betas_ptr cdef cugraph_type_erased_device_array_view_t* betas_ptr - + if betas is not None: cai_betas_ptr = betas.__cuda_array_interface__["data"][0] betas_ptr = \ @@ -145,7 +145,7 @@ def katz_centrality(ResourceHandle resource_handle, cugraph_centrality_result_get_vertices(result_ptr) cdef cugraph_type_erased_device_array_view_t* values_ptr = \ cugraph_centrality_result_get_values(result_ptr) - + cupy_vertices = copy_to_cupy_array(c_resource_handle_ptr, vertices_ptr) cupy_values = copy_to_cupy_array(c_resource_handle_ptr, values_ptr) diff --git a/python/pylibcugraph/pylibcugraph/node2vec.pyx b/python/pylibcugraph/pylibcugraph/node2vec.pyx index a550070e7a7..2ef962ae0c6 100644 --- a/python/pylibcugraph/pylibcugraph/node2vec.pyx +++ b/python/pylibcugraph/pylibcugraph/node2vec.pyx @@ -55,13 +55,15 @@ from pylibcugraph.utils cimport ( ) -def node2vec(ResourceHandle resource_handle, - _GPUGraph graph, - seed_array, - size_t max_depth, - bool_t compress_result, - double p, - double q): +def node2vec( + ResourceHandle resource_handle, + _GPUGraph graph, + seed_array, + size_t max_depth, + bool_t compress_result, + double p, + double q +): """ Computes random walks under node2vec sampling procedure. @@ -172,8 +174,8 @@ def node2vec(ResourceHandle resource_handle, cupy_paths = copy_to_cupy_array(c_resource_handle_ptr, paths_ptr) cupy_weights = copy_to_cupy_array(c_resource_handle_ptr, weights_ptr) cupy_path_sizes = copy_to_cupy_array(c_resource_handle_ptr, - path_sizes_ptr) - + path_sizes_ptr) + cugraph_random_walk_result_free(result_ptr) cugraph_type_erased_device_array_view_free(seed_view_ptr) diff --git a/python/pylibcugraph/pylibcugraph/overlap_coefficients.pyx b/python/pylibcugraph/pylibcugraph/overlap_coefficients.pyx index 6af71116469..8eea14ec48d 100644 --- a/python/pylibcugraph/pylibcugraph/overlap_coefficients.pyx +++ b/python/pylibcugraph/pylibcugraph/overlap_coefficients.pyx @@ -57,15 +57,17 @@ from pylibcugraph.utils cimport ( ) -def EXPERIMENTAL__overlap_coefficients(ResourceHandle resource_handle, - _GPUGraph graph, - first, - second, - bool_t use_weight, - bool_t do_expensive_check): +def EXPERIMENTAL__overlap_coefficients( + ResourceHandle resource_handle, + _GPUGraph graph, + first, + second, + bool_t use_weight, + bool_t do_expensive_check +): """ Compute the Overlap coefficients for the specified vertex_pairs. - + Note that Overlap similarity must run on a symmetric graph. @@ -77,13 +79,13 @@ def EXPERIMENTAL__overlap_coefficients(ResourceHandle resource_handle, graph : SGGraph or MGGraph The input graph, for either Single or Multi-GPU operations. - + first : Source of the vertex pair. - + second : Destination of the vertex pair. - + use_weight : bool, optional (default=False) Currently not supported @@ -113,16 +115,12 @@ def EXPERIMENTAL__overlap_coefficients(ResourceHandle resource_handle, cdef cugraph_error_t* error_ptr # 'first' is a required parameter - cdef cugraph_type_erased_device_array_view_t* \ - first_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - first) + cdef cugraph_type_erased_device_array_view_t* first_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj(first) # 'second' is a required parameter - cdef cugraph_type_erased_device_array_view_t* \ - second_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - second) + cdef cugraph_type_erased_device_array_view_t* second_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj(second) error_code = cugraph_create_vertex_pairs(c_resource_handle_ptr, c_graph_ptr, diff --git a/python/pylibcugraph/pylibcugraph/pagerank.pyx b/python/pylibcugraph/pylibcugraph/pagerank.pyx index 7d8f7807ead..1a01efd146c 100644 --- a/python/pylibcugraph/pylibcugraph/pagerank.pyx +++ b/python/pylibcugraph/pylibcugraph/pagerank.pyx @@ -55,16 +55,18 @@ from pylibcugraph.utils cimport ( ) -def pagerank(ResourceHandle resource_handle, - _GPUGraph graph, - precomputed_vertex_out_weight_vertices, - precomputed_vertex_out_weight_sums, - initial_guess_vertices, - initial_guess_values, - double alpha, - double epsilon, - size_t max_iterations, - bool_t do_expensive_check): +def pagerank( + ResourceHandle resource_handle, + _GPUGraph graph, + precomputed_vertex_out_weight_vertices, + precomputed_vertex_out_weight_sums, + initial_guess_vertices, + initial_guess_values, + double alpha, + double epsilon, + size_t max_iterations, + bool_t do_expensive_check +): """ Find the PageRank score for every vertex in a graph by computing an approximation of the Pagerank eigenvector using the power method. The @@ -166,15 +168,11 @@ def pagerank(ResourceHandle resource_handle, raise RuntimeError("pagerank requires the numpy package, which could " "not be imported") - cdef cugraph_type_erased_device_array_view_t* \ - initial_guess_vertices_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - initial_guess_vertices) + cdef cugraph_type_erased_device_array_view_t* initial_guess_vertices_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj(initial_guess_vertices) - cdef cugraph_type_erased_device_array_view_t* \ - initial_guess_values_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - initial_guess_values) + cdef cugraph_type_erased_device_array_view_t* initial_guess_values_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj(initial_guess_values) cdef cugraph_resource_handle_t* c_resource_handle_ptr = \ resource_handle.c_resource_handle_ptr @@ -182,15 +180,15 @@ def pagerank(ResourceHandle resource_handle, cdef cugraph_type_erased_device_array_view_t* \ precomputed_vertex_out_weight_vertices_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - precomputed_vertex_out_weight_vertices) + create_cugraph_type_erased_device_array_view_from_py_obj( + precomputed_vertex_out_weight_vertices) # FIXME: assert that precomputed_vertex_out_weight_sums # type == weight type cdef cugraph_type_erased_device_array_view_t* \ precomputed_vertex_out_weight_sums_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - precomputed_vertex_out_weight_sums) + create_cugraph_type_erased_device_array_view_from_py_obj( + precomputed_vertex_out_weight_sums) cdef cugraph_centrality_result_t* result_ptr cdef cugraph_error_code_t error_code @@ -227,8 +225,10 @@ def pagerank(ResourceHandle resource_handle, if initial_guess_values is not None: cugraph_type_erased_device_array_view_free(initial_guess_values_view_ptr) if precomputed_vertex_out_weight_vertices is not None: - cugraph_type_erased_device_array_view_free(precomputed_vertex_out_weight_vertices_view_ptr) + cugraph_type_erased_device_array_view_free( + precomputed_vertex_out_weight_vertices_view_ptr) if precomputed_vertex_out_weight_sums is not None: - cugraph_type_erased_device_array_view_free(precomputed_vertex_out_weight_sums_view_ptr) + cugraph_type_erased_device_array_view_free( + precomputed_vertex_out_weight_sums_view_ptr) return (cupy_vertices, cupy_pageranks) diff --git a/python/pylibcugraph/pylibcugraph/personalized_pagerank.pyx b/python/pylibcugraph/pylibcugraph/personalized_pagerank.pyx index 89b57f139a1..1fe29ab30aa 100644 --- a/python/pylibcugraph/pylibcugraph/personalized_pagerank.pyx +++ b/python/pylibcugraph/pylibcugraph/personalized_pagerank.pyx @@ -90,19 +90,19 @@ def personalized_pagerank(ResourceHandle resource_handle, precomputed_vertex_out_weight_sums : device array type Corresponding precomputed sum of outgoing vertices weight (a performance optimization) - + initial_guess_vertices : device array type Subset of vertices of graph for initial guess for pagerank values (a performance optimization) - + initial_guess_values : device array type Pagerank values for vertices (a performance optimization) - + personalization_vertices : device array type Subset of vertices of graph for personalization (a performance optimization) - + personalization_values : device array type Personalization values for vertices (a performance optimization) @@ -184,13 +184,13 @@ def personalized_pagerank(ResourceHandle resource_handle, cdef cugraph_type_erased_device_array_view_t* \ initial_guess_vertices_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - initial_guess_vertices) + create_cugraph_type_erased_device_array_view_from_py_obj( + initial_guess_vertices) cdef cugraph_type_erased_device_array_view_t* \ initial_guess_values_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - initial_guess_values) + create_cugraph_type_erased_device_array_view_from_py_obj( + initial_guess_values) cdef cugraph_resource_handle_t* c_resource_handle_ptr = \ resource_handle.c_resource_handle_ptr @@ -198,44 +198,45 @@ def personalized_pagerank(ResourceHandle resource_handle, cdef cugraph_type_erased_device_array_view_t* \ precomputed_vertex_out_weight_vertices_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - precomputed_vertex_out_weight_vertices) + create_cugraph_type_erased_device_array_view_from_py_obj( + precomputed_vertex_out_weight_vertices) # FIXME: assert that precomputed_vertex_out_weight_sums # type == weight type cdef cugraph_type_erased_device_array_view_t* \ precomputed_vertex_out_weight_sums_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - precomputed_vertex_out_weight_sums) - + create_cugraph_type_erased_device_array_view_from_py_obj( + precomputed_vertex_out_weight_sums) + cdef cugraph_type_erased_device_array_view_t* \ personalization_vertices_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - personalization_vertices) - + create_cugraph_type_erased_device_array_view_from_py_obj( + personalization_vertices) + cdef cugraph_type_erased_device_array_view_t* \ personalization_values_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - personalization_values) + create_cugraph_type_erased_device_array_view_from_py_obj( + personalization_values) cdef cugraph_centrality_result_t* result_ptr cdef cugraph_error_code_t error_code cdef cugraph_error_t* error_ptr - error_code = cugraph_personalized_pagerank(c_resource_handle_ptr, - c_graph_ptr, - precomputed_vertex_out_weight_vertices_view_ptr, - precomputed_vertex_out_weight_sums_view_ptr, - initial_guess_vertices_view_ptr, - initial_guess_values_view_ptr, - personalization_vertices_view_ptr, - personalization_values_view_ptr, - alpha, - epsilon, - max_iterations, - do_expensive_check, - &result_ptr, - &error_ptr) + error_code = cugraph_personalized_pagerank( + c_resource_handle_ptr, + c_graph_ptr, + precomputed_vertex_out_weight_vertices_view_ptr, + precomputed_vertex_out_weight_sums_view_ptr, + initial_guess_vertices_view_ptr, + initial_guess_values_view_ptr, + personalization_vertices_view_ptr, + personalization_values_view_ptr, + alpha, + epsilon, + max_iterations, + do_expensive_check, + &result_ptr, + &error_ptr) assert_success(error_code, error_ptr, "cugraph_personalized_pagerank") # Extract individual device array pointers from result and copy to cupy @@ -255,9 +256,11 @@ def personalized_pagerank(ResourceHandle resource_handle, if initial_guess_values is not None: cugraph_type_erased_device_array_view_free(initial_guess_values_view_ptr) if precomputed_vertex_out_weight_vertices is not None: - cugraph_type_erased_device_array_view_free(precomputed_vertex_out_weight_vertices_view_ptr) + cugraph_type_erased_device_array_view_free( + precomputed_vertex_out_weight_vertices_view_ptr) if precomputed_vertex_out_weight_sums is not None: - cugraph_type_erased_device_array_view_free(precomputed_vertex_out_weight_sums_view_ptr) + cugraph_type_erased_device_array_view_free( + precomputed_vertex_out_weight_sums_view_ptr) if personalization_vertices is not None: cugraph_type_erased_device_array_view_free(personalization_vertices_view_ptr) if personalization_values is not None: diff --git a/python/pylibcugraph/pylibcugraph/resource_handle.pyx b/python/pylibcugraph/pylibcugraph/resource_handle.pyx index 75f03e67d91..b5a97495138 100644 --- a/python/pylibcugraph/pylibcugraph/resource_handle.pyx +++ b/python/pylibcugraph/pylibcugraph/resource_handle.pyx @@ -18,7 +18,7 @@ from pylibcugraph._cugraph_c.resource_handle cimport ( cugraph_create_resource_handle, cugraph_free_resource_handle, ) -#from cugraph.dask.traversal cimport mg_bfs as c_bfs +# from cugraph.dask.traversal cimport mg_bfs as c_bfs from pylibcugraph cimport resource_handle as c_resource_handle diff --git a/python/pylibcugraph/pylibcugraph/sorensen_coefficients.pyx b/python/pylibcugraph/pylibcugraph/sorensen_coefficients.pyx index 12647baccb2..1b72baf0a26 100644 --- a/python/pylibcugraph/pylibcugraph/sorensen_coefficients.pyx +++ b/python/pylibcugraph/pylibcugraph/sorensen_coefficients.pyx @@ -57,15 +57,17 @@ from pylibcugraph.utils cimport ( ) -def EXPERIMENTAL__sorensen_coefficients(ResourceHandle resource_handle, - _GPUGraph graph, - first, - second, - bool_t use_weight, - bool_t do_expensive_check): +def EXPERIMENTAL__sorensen_coefficients( + ResourceHandle resource_handle, + _GPUGraph graph, + first, + second, + bool_t use_weight, + bool_t do_expensive_check +): """ Compute the Sorensen coefficients for the specified vertex_pairs. - + Note that Sorensen similarity must run on a symmetric graph. Parameters @@ -76,13 +78,13 @@ def EXPERIMENTAL__sorensen_coefficients(ResourceHandle resource_handle, graph : SGGraph or MGGraph The input graph, for either Single or Multi-GPU operations. - + first : Source of the vertex pair. - + second : Destination of the vertex pair. - + use_weight : bool, optional (default=False) Currently not supported @@ -112,16 +114,12 @@ def EXPERIMENTAL__sorensen_coefficients(ResourceHandle resource_handle, cdef cugraph_error_t* error_ptr # 'first' is a required parameter - cdef cugraph_type_erased_device_array_view_t* \ - first_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - first) + cdef cugraph_type_erased_device_array_view_t* first_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj(first) # 'second' is a required parameter - cdef cugraph_type_erased_device_array_view_t* \ - second_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - second) + cdef cugraph_type_erased_device_array_view_t* second_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj(second) error_code = cugraph_create_vertex_pairs(c_resource_handle_ptr, c_graph_ptr, @@ -132,12 +130,12 @@ def EXPERIMENTAL__sorensen_coefficients(ResourceHandle resource_handle, assert_success(error_code, error_ptr, "vertex_pairs") error_code = cugraph_sorensen_coefficients(c_resource_handle_ptr, - c_graph_ptr, - vertex_pairs_ptr, - use_weight, - do_expensive_check, - &result_ptr, - &error_ptr) + c_graph_ptr, + vertex_pairs_ptr, + use_weight, + do_expensive_check, + &result_ptr, + &error_ptr) assert_success(error_code, error_ptr, "cugraph_sorensen_coefficients") # Extract individual device array pointers from result and copy to cupy diff --git a/python/pylibcugraph/pylibcugraph/sssp.pyx b/python/pylibcugraph/pylibcugraph/sssp.pyx index b2cd829cb2e..4d55eb224e3 100644 --- a/python/pylibcugraph/pylibcugraph/sssp.pyx +++ b/python/pylibcugraph/pylibcugraph/sssp.pyx @@ -49,12 +49,14 @@ from pylibcugraph.utils cimport ( ) -def sssp(ResourceHandle resource_handle, - _GPUGraph graph, - size_t source, - double cutoff, - bool_t compute_predecessors, - bool_t do_expensive_check): +def sssp( + ResourceHandle resource_handle, + _GPUGraph graph, + size_t source, + double cutoff, + bool_t compute_predecessors, + bool_t do_expensive_check +): """ Compute the distance and predecessors for shortest paths from the specified source to all the vertices in the graph. The returned distances array will diff --git a/python/pylibcugraph/pylibcugraph/structure/graph_primtypes.pxd b/python/pylibcugraph/pylibcugraph/structure/graph_primtypes.pxd index 32b700dc513..ad88589d7ab 100644 --- a/python/pylibcugraph/pylibcugraph/structure/graph_primtypes.pxd +++ b/python/pylibcugraph/pylibcugraph/structure/graph_primtypes.pxd @@ -39,9 +39,9 @@ cdef extern from "cugraph/legacy/graph.hpp" namespace "cugraph::legacy": bool tree PropType has_negative_edges - cdef cppclass GraphViewBase[VT,ET,WT]: + cdef cppclass GraphViewBase[VT, ET, WT]: WT *edge_data - handle_t *handle; + handle_t *handle GraphProperties prop VT number_of_vertices ET number_of_edges @@ -52,30 +52,31 @@ cdef extern from "cugraph/legacy/graph.hpp" namespace "cugraph::legacy": void set_local_data(VT* local_vertices_, ET* local_edges_, VT* local_offsets_) void get_vertex_identifiers(VT *) const - GraphViewBase(WT*,VT,ET) + GraphViewBase(WT*, VT, ET) - cdef cppclass GraphCOOView[VT,ET,WT](GraphViewBase[VT,ET,WT]): + cdef cppclass GraphCOOView[VT, ET, WT](GraphViewBase[VT, ET, WT]): VT *src_indices VT *dst_indices - void degree(ET *,DegreeDirection) const + void degree(ET *, DegreeDirection) const GraphCOOView() GraphCOOView(const VT *, const ET *, const WT *, size_t, size_t) - cdef cppclass GraphCompressedSparseBaseView[VT,ET,WT](GraphViewBase[VT,ET,WT]): + cdef cppclass GraphCompressedSparseBaseView[VT, ET, WT](GraphViewBase[VT, ET, WT]): ET *offsets VT *indices void get_source_indices(VT *) const - void degree(ET *,DegreeDirection) const + void degree(ET *, DegreeDirection) const - GraphCompressedSparseBaseView(const VT *, const ET *, const WT *, size_t, size_t) + GraphCompressedSparseBaseView( + const VT *, const ET *, const WT *, size_t, size_t) - cdef cppclass GraphCSRView[VT,ET,WT](GraphCompressedSparseBaseView[VT,ET,WT]): + cdef cppclass GraphCSRView[VT, ET, WT](GraphCompressedSparseBaseView[VT, ET, WT]): GraphCSRView() GraphCSRView(const VT *, const ET *, const WT *, size_t, size_t) - cdef cppclass GraphCSCView[VT,ET,WT](GraphCompressedSparseBaseView[VT,ET,WT]): + cdef cppclass GraphCSCView[VT, ET, WT](GraphCompressedSparseBaseView[VT, ET, WT]): GraphCSCView() GraphCSCView(const VT *, const ET *, const WT *, size_t, size_t) diff --git a/python/pylibcugraph/pylibcugraph/structure/graph_utilities.pxd b/python/pylibcugraph/pylibcugraph/structure/graph_utilities.pxd index d9532cd4190..5d0c2326c10 100644 --- a/python/pylibcugraph/pylibcugraph/structure/graph_utilities.pxd +++ b/python/pylibcugraph/pylibcugraph/structure/graph_utilities.pxd @@ -30,7 +30,7 @@ cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": doubleType "cugraph::cython::numberTypeEnum::doubleType" cdef cppclass graph_container_t: - pass + pass cdef void populate_graph_container( graph_container_t &graph_container, diff --git a/python/pylibcugraph/pylibcugraph/testing/type_utils.pyx b/python/pylibcugraph/pylibcugraph/testing/type_utils.pyx index 253551eba11..8f6b5eb32f8 100644 --- a/python/pylibcugraph/pylibcugraph/testing/type_utils.pyx +++ b/python/pylibcugraph/pylibcugraph/testing/type_utils.pyx @@ -47,7 +47,7 @@ from pylibcugraph._cugraph_c.array cimport ( def create_sampling_result(ResourceHandle resource_handle, - device_sources, + device_sources, device_destinations, device_indices): """ diff --git a/python/pylibcugraph/pylibcugraph/triangle_count.pyx b/python/pylibcugraph/pylibcugraph/triangle_count.pyx index e26b2a291cf..00d55f544c8 100644 --- a/python/pylibcugraph/pylibcugraph/triangle_count.pyx +++ b/python/pylibcugraph/pylibcugraph/triangle_count.pyx @@ -74,11 +74,11 @@ def triangle_count(ResourceHandle resource_handle, start_list: device array type Device array containing the list of vertices for triangle counting. If 'None' the entire set of vertices in the graph is processed - + do_expensive_check: bool If True, performs more extensive tests on the inputs to ensure validitity, at the expense of increased run time. - + Returns ------- A tuple of device arrays, where the first item in the tuple is a device @@ -112,7 +112,7 @@ def triangle_count(ResourceHandle resource_handle, get_c_type_from_numpy_type(start_list.dtype)) else: start_ptr = NULL - + error_code = cugraph_triangle_count(c_resource_handle_ptr, c_graph_ptr, start_ptr, @@ -133,5 +133,5 @@ def triangle_count(ResourceHandle resource_handle, if start_list is not None: cugraph_type_erased_device_array_view_free(start_ptr) - + return (cupy_vertices, cupy_counts) diff --git a/python/pylibcugraph/pylibcugraph/two_hop_neighbors.pyx b/python/pylibcugraph/pylibcugraph/two_hop_neighbors.pyx index 649f7980747..3a25286240e 100644 --- a/python/pylibcugraph/pylibcugraph/two_hop_neighbors.pyx +++ b/python/pylibcugraph/pylibcugraph/two_hop_neighbors.pyx @@ -69,7 +69,7 @@ def get_two_hop_neighbors(ResourceHandle resource_handle, graph : SGGraph or MGGraph The input graph, for either Single or Multi-GPU operations. - + start_vertices : Optional array of starting vertices If None use all, if specified compute two-hop neighbors for these starting vertices @@ -90,10 +90,8 @@ def get_two_hop_neighbors(ResourceHandle resource_handle, cdef cugraph_type_erased_device_array_view_t* start_vertices_ptr - cdef cugraph_type_erased_device_array_view_t* \ - start_vertices_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - start_vertices) + cdef cugraph_type_erased_device_array_view_t* start_vertices_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj(start_vertices) error_code = cugraph_two_hop_neighbors(c_resource_handle_ptr, c_graph_ptr, @@ -105,16 +103,16 @@ def get_two_hop_neighbors(ResourceHandle resource_handle, cdef cugraph_type_erased_device_array_view_t* first_ptr = \ cugraph_vertex_pairs_get_first(result_ptr) - + cdef cugraph_type_erased_device_array_view_t* second_ptr = \ cugraph_vertex_pairs_get_second(result_ptr) - + cupy_first = copy_to_cupy_array(c_resource_handle_ptr, first_ptr) cupy_second = copy_to_cupy_array(c_resource_handle_ptr, second_ptr) # Free all pointers cugraph_vertex_pairs_free(result_ptr) if start_vertices is not None: - cugraph_type_erased_device_array_view_free(start_vertices_view_ptr) + cugraph_type_erased_device_array_view_free(start_vertices_view_ptr) return cupy_first, cupy_second diff --git a/python/pylibcugraph/pylibcugraph/uniform_neighbor_sample.pyx b/python/pylibcugraph/pylibcugraph/uniform_neighbor_sample.pyx index 0d86053a679..1b5c9d550c4 100644 --- a/python/pylibcugraph/pylibcugraph/uniform_neighbor_sample.pyx +++ b/python/pylibcugraph/pylibcugraph/uniform_neighbor_sample.pyx @@ -62,6 +62,7 @@ from pylibcugraph.internal_types.sampling_result cimport ( SamplingResult, ) + def uniform_neighbor_sample(ResourceHandle resource_handle, _GPUGraph input_graph, start_list, diff --git a/python/pylibcugraph/pylibcugraph/utils.pxd b/python/pylibcugraph/pylibcugraph/utils.pxd index 7fc140e9aed..44f51f09a93 100644 --- a/python/pylibcugraph/pylibcugraph/utils.pxd +++ b/python/pylibcugraph/pylibcugraph/utils.pxd @@ -44,12 +44,12 @@ cdef get_c_weight_type_from_numpy_edge_ids_type(numpy_type) cdef get_numpy_edge_ids_type_from_c_weight_type(data_type_id_t c_type) cdef copy_to_cupy_array( - cugraph_resource_handle_t* c_resource_handle_ptr, - cugraph_type_erased_device_array_view_t* device_array_view_ptr) + cugraph_resource_handle_t* c_resource_handle_ptr, + cugraph_type_erased_device_array_view_t* device_array_view_ptr) cdef copy_to_cupy_array_ids( - cugraph_resource_handle_t* c_resource_handle_ptr, - cugraph_type_erased_device_array_view_t* device_array_view_ptr) + cugraph_resource_handle_t* c_resource_handle_ptr, + cugraph_type_erased_device_array_view_t* device_array_view_ptr) cdef cugraph_type_erased_device_array_view_t* \ create_cugraph_type_erased_device_array_view_from_py_obj(python_obj) diff --git a/python/pylibcugraph/pylibcugraph/utils.pyx b/python/pylibcugraph/pylibcugraph/utils.pyx index a9fc8fce711..baab68788a3 100644 --- a/python/pylibcugraph/pylibcugraph/utils.pyx +++ b/python/pylibcugraph/pylibcugraph/utils.pyx @@ -68,7 +68,7 @@ cdef assert_success(cugraph_error_code_t code, raise ValueError(error_msg) elif code == cugraph_error_code_t.CUGRAPH_NOT_IMPLEMENTED: code_str = "CUGRAPH_NOT_IMPLEMENTED" - error_msg = f"non-success value returned from {api_name}: {code_str}\ "\ + error_msg = f"non-success value returned from {api_name}: {code_str} "\ f"{c_error}" raise NotImplementedError(error_msg) elif code == cugraph_error_code_t.CUGRAPH_UNSUPPORTED_TYPE_COMBINATION: @@ -133,8 +133,10 @@ cdef get_c_type_from_numpy_type(numpy_type): elif numpy_type == numpy.float64: return data_type_id_t.FLOAT64 else: - raise RuntimeError("Internal error: got invalid data type enum value " - f"from Numpy: {numpy_type}") + raise RuntimeError( + "Internal error: got invalid data type enum value from Numpy: " + f"{numpy_type}" + ) cdef get_c_weight_type_from_numpy_edge_ids_type(numpy_type): if numpy_type == numpy.int32: @@ -150,8 +152,9 @@ cdef get_numpy_edge_ids_type_from_c_weight_type(data_type_id_t c_weight_type): cdef copy_to_cupy_array( - cugraph_resource_handle_t* c_resource_handle_ptr, - cugraph_type_erased_device_array_view_t* device_array_view_ptr): + cugraph_resource_handle_t* c_resource_handle_ptr, + cugraph_type_erased_device_array_view_t* device_array_view_ptr +): """ Copy the contents from a device array view as returned by various cugraph_* APIs to a new cupy device array, typically intended to be used as a return @@ -186,8 +189,9 @@ cdef copy_to_cupy_array( return cupy_array cdef copy_to_cupy_array_ids( - cugraph_resource_handle_t* c_resource_handle_ptr, - cugraph_type_erased_device_array_view_t* device_array_view_ptr): + cugraph_resource_handle_t* c_resource_handle_ptr, + cugraph_type_erased_device_array_view_t* device_array_view_ptr +): """ Copy the contents from a device array view as returned by various cugraph_* APIs to a new cupy device array, typically intended to be used as a return @@ -207,7 +211,9 @@ cdef copy_to_cupy_array_ids( cdef cugraph_type_erased_device_array_view_t* cupy_array_view_ptr = \ cugraph_type_erased_device_array_view_create( - cupy_array_ptr, array_size, get_c_type_from_numpy_type(cupy_array.dtype)) + cupy_array_ptr, + array_size, + get_c_type_from_numpy_type(cupy_array.dtype)) cdef cugraph_error_t* error_ptr error_code = cugraph_type_erased_device_array_view_copy( @@ -223,21 +229,21 @@ cdef copy_to_cupy_array_ids( return cupy_array cdef cugraph_type_erased_device_array_view_t* \ - create_cugraph_type_erased_device_array_view_from_py_obj(python_obj): - cdef uintptr_t cai_ptr = NULL - cdef cugraph_type_erased_device_array_view_t* view_ptr = NULL - if python_obj is not None: - cai_ptr = python_obj.__cuda_array_interface__["data"][0] - view_ptr = cugraph_type_erased_device_array_view_create( - cai_ptr, - len(python_obj), - get_c_type_from_numpy_type(python_obj.dtype)) - - return view_ptr + create_cugraph_type_erased_device_array_view_from_py_obj(python_obj): + cdef uintptr_t cai_ptr = NULL + cdef cugraph_type_erased_device_array_view_t* view_ptr = NULL + if python_obj is not None: + cai_ptr = python_obj.__cuda_array_interface__["data"][0] + view_ptr = cugraph_type_erased_device_array_view_create( + cai_ptr, + len(python_obj), + get_c_type_from_numpy_type(python_obj.dtype)) + + return view_ptr cdef create_cupy_array_view_for_device_ptr( - cugraph_type_erased_device_array_view_t* device_array_view_ptr, - owning_py_object): + cugraph_type_erased_device_array_view_t* device_array_view_ptr, + owning_py_object): if device_array_view_ptr == NULL: raise ValueError("device_array_view_ptr cannot be NULL") diff --git a/python/pylibcugraph/pylibcugraph/weakly_connected_components.pyx b/python/pylibcugraph/pylibcugraph/weakly_connected_components.pyx index abd78aa8c10..26f991403b2 100644 --- a/python/pylibcugraph/pylibcugraph/weakly_connected_components.pyx +++ b/python/pylibcugraph/pylibcugraph/weakly_connected_components.pyx @@ -65,8 +65,7 @@ def _ensure_args(graph, offsets, indices, weights): else: invalid_input = [i for p in [offsets, indices] if p is None] input_type = "csr_arrays" - - + if len(invalid_input) != 0: raise TypeError("Invalid input combination: Must set either 'graph' or " "a combination of 'offsets', 'indices' and 'weights', not both") @@ -75,7 +74,7 @@ def _ensure_args(graph, offsets, indices, weights): assert_CAI_type(offsets, "offsets") assert_CAI_type(indices, "indices") assert_CAI_type(weights, "weights", True) - + return input_type @@ -99,7 +98,7 @@ def weakly_connected_components(ResourceHandle resource_handle, graph : SGGraph or MGGraph The input graph. - + offsets : object supporting a __cuda_array_interface__ interface Array containing the offsets values of a Compressed Sparse Row matrix that represents the graph. @@ -137,7 +136,7 @@ def weakly_connected_components(ResourceHandle resource_handle, ... store_transposed=False, renumber=True, do_expensive_check=False) >>> (vertices, labels) = weakly_connected_components( ... resource_handle, G, None, None, None, None, False) - + >>> vertices [0, 1, 2] >>> labels @@ -182,18 +181,20 @@ def weakly_connected_components(ResourceHandle resource_handle, resource_handle = ResourceHandle() graph_props = GraphProperties( - is_symmetric=True, is_multigraph=False) + is_symmetric=True, + is_multigraph=False, + ) graph = SGGraph( - resource_handle, - graph_props, - offsets, - indices, - weights, - store_transposed=False, - renumber=False, - do_expensive_check=True, - input_array_format="CSR" - ) + resource_handle, + graph_props, + offsets, + indices, + weights, + store_transposed=False, + renumber=False, + do_expensive_check=True, + input_array_format="CSR", + ) cdef cugraph_resource_handle_t* c_resource_handle_ptr = \ resource_handle.c_resource_handle_ptr From 46c3b86e2e9ec3963bbae8ec2f526af28cd6f4d1 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Fri, 9 Dec 2022 14:02:13 -0600 Subject: [PATCH 4/8] Revert "Apply flake8 to Cython code." This reverts commit 2e4f34fa354aff160b87f4e011a5b5c3349cb55c. --- .pre-commit-config.yaml | 2 +- .../betweenness_centrality_wrapper.pyx | 76 ++- .../edge_betweenness_centrality_wrapper.pyx | 77 ++- python/cugraph/cugraph/community/ecg.pxd | 6 +- .../cugraph/cugraph/community/ecg_wrapper.pyx | 50 +- .../cugraph/community/ktruss_subgraph.pxd | 6 +- .../community/ktruss_subgraph_wrapper.pyx | 21 +- python/cugraph/cugraph/community/leiden.pxd | 6 +- .../cugraph/community/leiden_wrapper.pyx | 30 +- .../cugraph/community/spectral_clustering.pxd | 22 +- .../community/spectral_clustering_wrapper.pyx | 177 ++---- .../cugraph/community/subgraph_extraction.pxd | 6 +- .../community/subgraph_extraction_wrapper.pyx | 43 +- .../cugraph/components/connectivity.pxd | 4 +- .../components/connectivity_wrapper.pyx | 16 +- python/cugraph/cugraph/dask/comms/comms.pxd | 4 +- .../cugraph/dask/structure/replication.pyx | 39 +- python/cugraph/cugraph/generators/rmat.pxd | 3 +- .../cugraph/generators/rmat_wrapper.pyx | 93 ++-- .../cugraph/layout/force_atlas2_wrapper.pyx | 109 ++-- .../cugraph/cugraph/linear_assignment/lap.pxd | 14 +- .../cugraph/linear_assignment/lap_wrapper.pyx | 88 +-- .../cugraph/link_prediction/jaccard.pxd | 10 +- .../link_prediction/jaccard_wrapper.pyx | 96 ++-- .../cugraph/link_prediction/overlap.pxd | 10 +- .../link_prediction/overlap_wrapper.pyx | 84 ++- .../cugraph/structure/graph_primtypes.pxd | 112 ++-- .../cugraph/structure/graph_primtypes.pyx | 53 +- .../structure/graph_primtypes_wrapper.pyx | 80 +-- .../cugraph/structure/graph_utilities.pxd | 11 +- .../cugraph/structure/renumber_wrapper.pyx | 512 +++++++----------- python/cugraph/cugraph/structure/utils.pxd | 10 +- .../cugraph/structure/utils_wrapper.pyx | 25 +- .../cugraph/tree/minimum_spanning_tree.pxd | 7 +- .../tree/minimum_spanning_tree_wrapper.pyx | 42 +- .../cugraph/utilities/path_retrieval.pxd | 17 +- .../utilities/path_retrieval_wrapper.pyx | 10 +- .../pylibcugraph/_cugraph_c/algorithms.pxd | 5 +- .../_cugraph_c/centrality_algorithms.pxd | 16 +- .../_cugraph_c/community_algorithms.pxd | 12 +- .../_cugraph_c/core_algorithms.pxd | 16 +- .../pylibcugraph/_cugraph_c/error.pxd | 2 +- .../pylibcugraph/_cugraph_c/graph.pxd | 35 +- .../_cugraph_c/graph_functions.pxd | 40 +- .../_cugraph_c/labeling_algorithms.pxd | 7 +- .../_cugraph_c/resource_handle.pxd | 25 +- .../_cugraph_c/similarity_algorithms.pxd | 8 +- python/pylibcugraph/pylibcugraph/bfs.pyx | 23 +- .../pylibcugraph/components/_connectivity.pxd | 7 +- .../pylibcugraph/components/_connectivity.pyx | 10 +- .../pylibcugraph/pylibcugraph/core_number.pyx | 9 +- python/pylibcugraph/pylibcugraph/egonet.pyx | 10 +- .../pylibcugraph/eigenvector_centrality.pyx | 2 +- .../pylibcugraph/graph_properties.pxd | 4 +- .../pylibcugraph/graph_properties.pyx | 2 +- python/pylibcugraph/pylibcugraph/graphs.pxd | 3 +- python/pylibcugraph/pylibcugraph/graphs.pyx | 32 +- python/pylibcugraph/pylibcugraph/hits.pyx | 46 +- .../pylibcugraph/jaccard_coefficients.pyx | 34 +- python/pylibcugraph/pylibcugraph/k_core.pyx | 30 +- .../pylibcugraph/katz_centrality.pyx | 8 +- python/pylibcugraph/pylibcugraph/node2vec.pyx | 20 +- .../pylibcugraph/overlap_coefficients.pyx | 34 +- python/pylibcugraph/pylibcugraph/pagerank.pyx | 48 +- .../pylibcugraph/personalized_pagerank.pyx | 71 ++- .../pylibcugraph/resource_handle.pyx | 2 +- .../pylibcugraph/sorensen_coefficients.pyx | 46 +- python/pylibcugraph/pylibcugraph/sssp.pyx | 14 +- .../structure/graph_primtypes.pxd | 21 +- .../structure/graph_utilities.pxd | 2 +- .../pylibcugraph/testing/type_utils.pyx | 2 +- .../pylibcugraph/triangle_count.pyx | 8 +- .../pylibcugraph/two_hop_neighbors.pyx | 14 +- .../pylibcugraph/uniform_neighbor_sample.pyx | 1 - python/pylibcugraph/pylibcugraph/utils.pxd | 8 +- python/pylibcugraph/pylibcugraph/utils.pyx | 48 +- .../weakly_connected_components.pyx | 33 +- 77 files changed, 1165 insertions(+), 1564 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dfba8744cb8..24136489a7f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,7 +24,7 @@ repos: args: ["--config=setup.cfg"] files: python/.*$ types: [file] - types_or: [python, cython] + types_or: [python] # TODO: Enable [python, cython] additional_dependencies: ["flake8-force"] - repo: https://github.com/asottile/yesqa rev: v1.3.0 diff --git a/python/cugraph/cugraph/centrality/betweenness_centrality_wrapper.pyx b/python/cugraph/cugraph/centrality/betweenness_centrality_wrapper.pyx index 27e29ee8102..3d34304ff13 100644 --- a/python/cugraph/cugraph/centrality/betweenness_centrality_wrapper.pyx +++ b/python/cugraph/cugraph/centrality/betweenness_centrality_wrapper.pyx @@ -16,9 +16,7 @@ # cython: embedsignature = True # cython: language_level = 3 -from cugraph.centrality.betweenness_centrality cimport ( - betweenness_centrality as c_betweenness_centrality -) +from cugraph.centrality.betweenness_centrality cimport betweenness_centrality as c_betweenness_centrality from cugraph.structure.graph_primtypes cimport * from libc.stdint cimport uintptr_t from libcpp cimport bool @@ -39,7 +37,7 @@ def get_output_df(number_of_vertices, result_dtype): def get_batch(sources, number_of_workers, current_worker): batch_size = len(sources) // number_of_workers - begin = current_worker * batch_size + begin = current_worker * batch_size end = (current_worker + 1) * batch_size if current_worker == (number_of_workers - 1): end = len(sources) @@ -57,25 +55,23 @@ cdef void run_c_betweenness_centrality(uintptr_t c_handle, uintptr_t c_batch, result_dtype): if result_dtype == np.float64: - c_betweenness_centrality[int, int, double, double]( - ( c_handle)[0], - ( c_graph)[0], - c_betweenness, - normalized, - endpoints, - c_weights, - number_of_sources_in_batch, - c_batch) + c_betweenness_centrality[int, int, double, double](( c_handle)[0], + ( c_graph)[0], + c_betweenness, + normalized, + endpoints, + c_weights, + number_of_sources_in_batch, + c_batch) elif result_dtype == np.float32: - c_betweenness_centrality[int, int, float, float]( - ( c_handle)[0], - ( c_graph)[0], - c_betweenness, - normalized, - endpoints, - c_weights, - number_of_sources_in_batch, - c_batch) + c_betweenness_centrality[int, int, float, float](( c_handle)[0], + ( c_graph)[0], + c_betweenness, + normalized, + endpoints, + c_weights, + number_of_sources_in_batch, + c_batch) else: raise ValueError("result_dtype can only be np.float64 or np.float32") @@ -131,8 +127,7 @@ def run_internal_work(handle, input_data, normalized, endpoints, raise ValueError("result_dtype can only be np.float64 or np.float32") c_identifier = result_df['vertex'].__cuda_array_interface__['data'][0] - c_betweenness = \ - result_df['betweenness_centrality'].__cuda_array_interface__['data'][0] + c_betweenness = result_df['betweenness_centrality'].__cuda_array_interface__['data'][0] if weights is not None: c_weights = weights.__cuda_array_interface__['data'][0] @@ -157,7 +152,6 @@ def run_internal_work(handle, input_data, normalized, endpoints, return result_df - def run_mg_work(input_data, normalized, endpoints, weights, sources, result_dtype, session_id): @@ -176,20 +170,20 @@ def run_mg_work(input_data, normalized, endpoints, def batch_betweenness_centrality(input_graph, normalized, endpoints, - weights, vertices, result_dtype): + weights, vertices, result_dtype): df = None client = get_client() comms = Comms.get_comms() replicated_adjlists = input_graph.batch_adjlists - work_futures = [client.submit(run_mg_work, - (data, input_graph.is_directed()), - normalized, - endpoints, - weights, - vertices, - result_dtype, - comms.sessionId, - workers=[worker]) for + work_futures = [client.submit(run_mg_work, + (data, input_graph.is_directed()), + normalized, + endpoints, + weights, + vertices, + result_dtype, + comms.sessionId, + workers=[worker]) for idx, (worker, data) in enumerate(replicated_adjlists.items())] dask.distributed.wait(work_futures) df = work_futures[0].result() @@ -221,13 +215,13 @@ def betweenness_centrality(input_graph, normalized, endpoints, weights, if not input_graph.adjlist: input_graph.view_adj_list() - if Comms.is_initialized() and input_graph.batch_enabled is True: + if Comms.is_initialized() and input_graph.batch_enabled == True: df = batch_betweenness_centrality(input_graph, - normalized, - endpoints, - weights, - vertices, - result_dtype) + normalized, + endpoints, + weights, + vertices, + result_dtype) else: df = sg_betweenness_centrality(input_graph, normalized, diff --git a/python/cugraph/cugraph/centrality/edge_betweenness_centrality_wrapper.pyx b/python/cugraph/cugraph/centrality/edge_betweenness_centrality_wrapper.pyx index ca3333e2a6c..bf4a80701ff 100644 --- a/python/cugraph/cugraph/centrality/edge_betweenness_centrality_wrapper.pyx +++ b/python/cugraph/cugraph/centrality/edge_betweenness_centrality_wrapper.pyx @@ -16,9 +16,7 @@ # cython: embedsignature = True # cython: language_level = 3 -from cugraph.centrality.betweenness_centrality cimport ( - edge_betweenness_centrality as c_edge_betweenness_centrality -) +from cugraph.centrality.betweenness_centrality cimport edge_betweenness_centrality as c_edge_betweenness_centrality from cugraph.structure import graph_primtypes_wrapper from cugraph.structure.graph_primtypes cimport * from libc.stdint cimport uintptr_t @@ -42,7 +40,7 @@ def get_output_df(indices, result_dtype): def get_batch(sources, number_of_workers, current_worker): batch_size = len(sources) // number_of_workers - begin = current_worker * batch_size + begin = current_worker * batch_size end = (current_worker + 1) * batch_size if current_worker == (number_of_workers - 1): end = len(sources) @@ -51,7 +49,7 @@ def get_batch(sources, number_of_workers, current_worker): def run_mg_work(input_data, normalized, weights, sources, - result_dtype, session_id): + result_dtype, session_id): result = None number_of_workers = Comms.get_n_workers(session_id) @@ -82,7 +80,7 @@ def run_internal_work(handle, input_data, normalized, weights, batch, cdef GraphCSRViewDouble graph_double cdef GraphCSRViewFloat graph_float - (offsets, indices, graph_weights), is_directed = input_data + (offsets, indices, graph_weights), is_directed = input_data if graph_weights is not None: c_graph_weights = graph_weights.__cuda_array_interface__['data'][0] @@ -95,8 +93,7 @@ def run_internal_work(handle, input_data, normalized, weights, batch, result_df = get_output_df(indices, result_dtype) c_src_identifier = result_df['src'].__cuda_array_interface__['data'][0] c_dst_identifier = result_df['dst'].__cuda_array_interface__['data'][0] - c_betweenness = \ - result_df['betweenness_centrality'].__cuda_array_interface__['data'][0] + c_betweenness = result_df['betweenness_centrality'].__cuda_array_interface__['data'][0] number_of_sources_in_batch = len(batch) if result_dtype == np.float64: @@ -143,41 +140,38 @@ cdef void run_c_edge_betweenness_centrality(uintptr_t c_handle, uintptr_t c_batch, result_dtype): if result_dtype == np.float64: - c_edge_betweenness_centrality[int, int, double, double]( - ( c_handle)[0], - ( c_graph)[0], - c_betweenness, - normalized, - c_weights, - number_of_sources_in_batch, - c_batch) + c_edge_betweenness_centrality[int, int, double, double](( c_handle)[0], + ( c_graph)[0], + c_betweenness, + normalized, + c_weights, + number_of_sources_in_batch, + c_batch) elif result_dtype == np.float32: - c_edge_betweenness_centrality[int, int, float, float]( - ( c_handle)[0], - ( c_graph)[0], - c_betweenness, - normalized, - c_weights, - number_of_sources_in_batch, - c_batch) + c_edge_betweenness_centrality[int, int, float, float](( c_handle)[0], + ( c_graph)[0], + c_betweenness, + normalized, + c_weights, + number_of_sources_in_batch, + c_batch) else: raise ValueError("result_dtype can only be np.float64 or np.float32") - def batch_edge_betweenness_centrality(input_graph, - normalized, - weights, vertices, result_dtype): + normalized, + weights, vertices, result_dtype): client = get_client() comms = Comms.get_comms() replicated_adjlists = input_graph.batch_adjlists - work_futures = [client.submit(run_mg_work, - (data, input_graph.is_directed()), - normalized, - weights, - vertices, - result_dtype, - comms.sessionId, - workers=[worker]) for + work_futures = [client.submit(run_mg_work, + (data, input_graph.is_directed()), + normalized, + weights, + vertices, + result_dtype, + comms.sessionId, + workers=[worker]) for (worker, data) in replicated_adjlists.items()] dask.distributed.wait(work_futures) df = work_futures[0].result() @@ -206,26 +200,25 @@ def edge_betweenness_centrality(input_graph, normalized, weights, cdef GraphCSRViewDouble graph_double cdef GraphCSRViewFloat graph_float + df = None if not input_graph.adjlist: input_graph.view_adj_list() - if Comms.is_initialized() and input_graph.batch_enabled is True: + if Comms.is_initialized() and input_graph.batch_enabled == True: df = batch_edge_betweenness_centrality(input_graph, normalized, - weights, vertices, - result_dtype) + weights, vertices, + result_dtype) else: df = sg_edge_betweenness_centrality(input_graph, normalized, weights, vertices, result_dtype) if result_dtype == np.float64: graph_double = get_graph_view[GraphCSRViewDouble](input_graph) - graph_double.get_source_indices( - (df['src'].__cuda_array_interface__['data'][0])) + graph_double.get_source_indices((df['src'].__cuda_array_interface__['data'][0])) elif result_dtype == np.float32: graph_float = get_graph_view[GraphCSRViewFloat](input_graph) - graph_float.get_source_indices( - (df['src'].__cuda_array_interface__['data'][0])) + graph_float.get_source_indices((df['src'].__cuda_array_interface__['data'][0])) return df diff --git a/python/cugraph/cugraph/community/ecg.pxd b/python/cugraph/cugraph/community/ecg.pxd index 0f3f11492d6..4f13237eac7 100644 --- a/python/cugraph/cugraph/community/ecg.pxd +++ b/python/cugraph/cugraph/community/ecg.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2021, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -21,9 +21,9 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": - cdef void ecg[VT, ET, WT]( + cdef void ecg[VT,ET,WT]( const handle_t &handle, - const GraphCSRView[VT, ET, WT] &graph, + const GraphCSRView[VT,ET,WT] &graph, WT min_weight, VT ensemble_size, VT* ecg_parts) except + diff --git a/python/cugraph/cugraph/community/ecg_wrapper.pyx b/python/cugraph/cugraph/community/ecg_wrapper.pyx index c61aac1004c..c6d3251b730 100644 --- a/python/cugraph/cugraph/community/ecg_wrapper.pyx +++ b/python/cugraph/cugraph/community/ecg_wrapper.pyx @@ -38,13 +38,9 @@ def ecg(input_graph, min_weight=.05, ensemble_size=16): cdef unique_ptr[handle_t] handle_ptr handle_ptr.reset(new handle_t()) - [offsets, indices] = graph_primtypes_wrapper.datatype_cast( - [ - input_graph.adjlist.offsets, - input_graph.adjlist.indices, - ], [np.int32, np.int64]) - [weights] = graph_primtypes_wrapper.datatype_cast( - [input_graph.adjlist.weights], [np.float32, np.float64]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, + input_graph.adjlist.indices], [np.int32, np.int64]) + [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) @@ -59,38 +55,30 @@ def ecg(input_graph, min_weight=.05, ensemble_size=16): cdef uintptr_t c_partition = df['partition'].__cuda_array_interface__['data'][0] cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int, int, float] graph_float - cdef GraphCSRView[int, int, double] graph_double + cdef GraphCSRView[int,int,float] graph_float + cdef GraphCSRView[int,int,double] graph_double if weights.dtype == np.float32: - graph_float = GraphCSRView[int, int, float]( - c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) + graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, + c_weights, num_verts, num_edges) graph_float.get_vertex_identifiers(c_identifier) - c_ecg[int, int, float](handle_ptr.get()[0], - graph_float, - min_weight, - ensemble_size, - c_partition) + c_ecg[int,int,float](handle_ptr.get()[0], + graph_float, + min_weight, + ensemble_size, + c_partition) else: - graph_double = GraphCSRView[int, int, double]( - c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) + graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, + c_weights, num_verts, num_edges) graph_double.get_vertex_identifiers(c_identifier) - c_ecg[int, int, double](handle_ptr.get()[0], - graph_double, - min_weight, - ensemble_size, - c_partition) + c_ecg[int,int,double](handle_ptr.get()[0], + graph_double, + min_weight, + ensemble_size, + c_partition) return df diff --git a/python/cugraph/cugraph/community/ktruss_subgraph.pxd b/python/cugraph/cugraph/community/ktruss_subgraph.pxd index d267dfb2d6e..d993c31c375 100644 --- a/python/cugraph/cugraph/community/ktruss_subgraph.pxd +++ b/python/cugraph/cugraph/community/ktruss_subgraph.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2021, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -21,6 +21,6 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": - cdef unique_ptr[GraphCOO[VT, ET, WT]] k_truss_subgraph[VT, ET, WT]( - const GraphCOOView[VT, ET, WT] &graph, + cdef unique_ptr[GraphCOO[VT,ET,WT]] k_truss_subgraph[VT,ET,WT]( + const GraphCOOView[VT,ET,WT] &graph, int k) except + diff --git a/python/cugraph/cugraph/community/ktruss_subgraph_wrapper.pyx b/python/cugraph/cugraph/community/ktruss_subgraph_wrapper.pyx index a10de4fe2b8..d3b7a38ba41 100644 --- a/python/cugraph/cugraph/community/ktruss_subgraph_wrapper.pyx +++ b/python/cugraph/cugraph/community/ktruss_subgraph_wrapper.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2021, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -23,25 +23,20 @@ import numpy as np def ktruss_subgraph_float(input_graph, k, use_weights): - cdef GraphCOOViewFloat in_graph = get_graph_view[GraphCOOViewFloat]( - input_graph, use_weights) - return coo_to_df(move(k_truss_subgraph[int, int, float](in_graph, k))) + cdef GraphCOOViewFloat in_graph = get_graph_view[GraphCOOViewFloat](input_graph, use_weights) + return coo_to_df(move(k_truss_subgraph[int,int,float](in_graph, k))) def ktruss_subgraph_double(input_graph, k, use_weights): - cdef GraphCOOViewDouble in_graph = get_graph_view[GraphCOOViewDouble]( - input_graph, use_weights) - return coo_to_df(move(k_truss_subgraph[int, int, double](in_graph, k))) + cdef GraphCOOViewDouble in_graph = get_graph_view[GraphCOOViewDouble](input_graph, use_weights) + return coo_to_df(move(k_truss_subgraph[int,int,double](in_graph, k))) def ktruss_subgraph(input_graph, k, use_weights): [input_graph.edgelist.edgelist_df['src'], - input_graph.edgelist.edgelist_df['dst']] = graph_primtypes_wrapper.datatype_cast( - [ - input_graph.edgelist.edgelist_df['src'], - input_graph.edgelist.edgelist_df['dst'], - ], - [np.int32]) + input_graph.edgelist.edgelist_df['dst']] = graph_primtypes_wrapper.datatype_cast([input_graph.edgelist.edgelist_df['src'], + input_graph.edgelist.edgelist_df['dst']], + [np.int32]) if graph_primtypes_wrapper.weight_type(input_graph) == np.float64 and use_weights: return ktruss_subgraph_double(input_graph, k, use_weights) else: diff --git a/python/cugraph/cugraph/community/leiden.pxd b/python/cugraph/cugraph/community/leiden.pxd index baf3caa6671..871dc826c06 100644 --- a/python/cugraph/cugraph/community/leiden.pxd +++ b/python/cugraph/cugraph/community/leiden.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2021, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -23,9 +23,9 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": - cdef pair[size_t, weight_t] leiden[vertex_t, edge_t, weight_t]( + cdef pair[size_t, weight_t] leiden[vertex_t,edge_t,weight_t]( const handle_t &handle, - const GraphCSRView[vertex_t, edge_t, weight_t] &graph, + const GraphCSRView[vertex_t,edge_t,weight_t] &graph, vertex_t *leiden_parts, size_t max_level, weight_t resolution) except + diff --git a/python/cugraph/cugraph/community/leiden_wrapper.pyx b/python/cugraph/cugraph/community/leiden_wrapper.pyx index 43184c45dfc..1b41134c625 100644 --- a/python/cugraph/cugraph/community/leiden_wrapper.pyx +++ b/python/cugraph/cugraph/community/leiden_wrapper.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2021, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -38,22 +38,20 @@ def leiden(input_graph, max_iter, resolution): weights = None final_modularity = None - [offsets, indices] = graph_primtypes_wrapper.datatype_cast( - [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) if input_graph.adjlist.weights is not None: - [weights] = graph_primtypes_wrapper.datatype_cast( - [input_graph.adjlist.weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) else: weights = cudf.Series(np.full(num_edges, 1.0, dtype=np.float32)) # Create the output dataframe df = cudf.DataFrame() df['vertex'] = cudf.Series(np.zeros(num_verts, dtype=np.int32)) - df['partition'] = cudf.Series(np.zeros(num_verts, dtype=np.int32)) + df['partition'] = cudf.Series(np.zeros(num_verts,dtype=np.int32)) cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] @@ -61,20 +59,16 @@ def leiden(input_graph, max_iter, resolution): cdef uintptr_t c_partition = df['partition'].__cuda_array_interface__['data'][0] cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int, int, float] graph_float - cdef GraphCSRView[int, int, double] graph_double + cdef GraphCSRView[int,int,float] graph_float + cdef GraphCSRView[int,int,double] graph_double cdef float final_modularity_float = 1.0 cdef double final_modularity_double = 1.0 cdef int num_level = 0 if weights.dtype == np.float32: - graph_float = GraphCSRView[int, int, float]( - c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) + graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, + c_weights, num_verts, num_edges) graph_float.get_vertex_identifiers(c_identifier) num_level, final_modularity_float = c_leiden(handle_ptr.get()[0], @@ -85,12 +79,8 @@ def leiden(input_graph, max_iter, resolution): final_modularity = final_modularity_float else: - graph_double = GraphCSRView[int, int, double]( - c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) + graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, + c_weights, num_verts, num_edges) graph_double.get_vertex_identifiers(c_identifier) num_level, final_modularity_double = c_leiden(handle_ptr.get()[0], diff --git a/python/cugraph/cugraph/community/spectral_clustering.pxd b/python/cugraph/cugraph/community/spectral_clustering.pxd index 64cf6f71e3f..346eb50a157 100644 --- a/python/cugraph/cugraph/community/spectral_clustering.pxd +++ b/python/cugraph/cugraph/community/spectral_clustering.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2021, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -21,8 +21,8 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/algorithms.hpp" namespace "cugraph::ext_raft": - cdef void balancedCutClustering[VT, ET, WT]( - const GraphCSRView[VT, ET, WT] &graph, + cdef void balancedCutClustering[VT,ET,WT]( + const GraphCSRView[VT,ET,WT] &graph, const int num_clusters, const int num_eigen_vects, const float evs_tolerance, @@ -31,8 +31,8 @@ cdef extern from "cugraph/algorithms.hpp" namespace "cugraph::ext_raft": const int kmean_max_iter, VT* clustering) except + - cdef void spectralModularityMaximization[VT, ET, WT]( - const GraphCSRView[VT, ET, WT] &graph, + cdef void spectralModularityMaximization[VT,ET,WT]( + const GraphCSRView[VT,ET,WT] &graph, const int n_clusters, const int n_eig_vects, const float evs_tolerance, @@ -41,20 +41,20 @@ cdef extern from "cugraph/algorithms.hpp" namespace "cugraph::ext_raft": const int kmean_max_iter, VT* clustering) except + - cdef void analyzeClustering_modularity[VT, ET, WT]( - const GraphCSRView[VT, ET, WT] &graph, + cdef void analyzeClustering_modularity[VT,ET,WT]( + const GraphCSRView[VT,ET,WT] &graph, const int n_clusters, const VT* clustering, WT* score) except + - cdef void analyzeClustering_edge_cut[VT, ET, WT]( - const GraphCSRView[VT, ET, WT] &graph, + cdef void analyzeClustering_edge_cut[VT,ET,WT]( + const GraphCSRView[VT,ET,WT] &graph, const int n_clusters, const VT* clustering, WT* score) except + - cdef void analyzeClustering_ratio_cut[VT, ET, WT]( - const GraphCSRView[VT, ET, WT] &graph, + cdef void analyzeClustering_ratio_cut[VT,ET,WT]( + const GraphCSRView[VT,ET,WT] &graph, const int n_clusters, const VT* clustering, WT* score) except + diff --git a/python/cugraph/cugraph/community/spectral_clustering_wrapper.pyx b/python/cugraph/cugraph/community/spectral_clustering_wrapper.pyx index d00e0874a16..8a04e2c1017 100644 --- a/python/cugraph/cugraph/community/spectral_clustering_wrapper.pyx +++ b/python/cugraph/cugraph/community/spectral_clustering_wrapper.pyx @@ -16,13 +16,11 @@ # cython: embedsignature = True # cython: language_level = 3 -from cugraph.community.spectral_clustering cimport ( - balancedCutClustering as c_balanced_cut_clustering, - spectralModularityMaximization as c_spectral_modularity_maximization, - analyzeClustering_modularity as c_analyze_clustering_modularity, - analyzeClustering_edge_cut as c_analyze_clustering_edge_cut, - analyzeClustering_ratio_cut as c_analyze_clustering_ratio_cut, -) +from cugraph.community.spectral_clustering cimport balancedCutClustering as c_balanced_cut_clustering +from cugraph.community.spectral_clustering cimport spectralModularityMaximization as c_spectral_modularity_maximization +from cugraph.community.spectral_clustering cimport analyzeClustering_modularity as c_analyze_clustering_modularity +from cugraph.community.spectral_clustering cimport analyzeClustering_edge_cut as c_analyze_clustering_edge_cut +from cugraph.community.spectral_clustering cimport analyzeClustering_ratio_cut as c_analyze_clustering_ratio_cut from cugraph.structure.graph_primtypes cimport * from cugraph.structure import graph_primtypes_wrapper from libc.stdint cimport uintptr_t @@ -45,23 +43,19 @@ def spectralBalancedCutClustering(input_graph, if input_graph.is_directed(): raise ValueError("directed graphs are not supported") else: - raise TypeError( - f"only cugraph.Graph objects are supported, got: {type(input_graph)}" - ) + raise TypeError(f"only cugraph.Graph objects are supported, got: {type(input_graph)}") if not input_graph.adjlist: input_graph.view_adj_list() weights = None - [offsets, indices] = graph_primtypes_wrapper.datatype_cast( - [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) if input_graph.adjlist.weights is not None: - [weights] = graph_primtypes_wrapper.datatype_cast( - [input_graph.adjlist.weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) else: weights = cudf.Series(np.full(num_edges, 1.0, dtype=np.float32)) @@ -76,16 +70,12 @@ def spectralBalancedCutClustering(input_graph, cdef uintptr_t c_cluster = df['cluster'].__cuda_array_interface__['data'][0] cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int, int, float] graph_float - cdef GraphCSRView[int, int, double] graph_double + cdef GraphCSRView[int,int,float] graph_float + cdef GraphCSRView[int,int,double] graph_double if weights.dtype == np.float32: - graph_float = GraphCSRView[int, int, float]( - c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) + graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, + c_weights, num_verts, num_edges) graph_float.get_vertex_identifiers(c_identifier) c_balanced_cut_clustering(graph_float, @@ -97,12 +87,8 @@ def spectralBalancedCutClustering(input_graph, kmean_max_iter, c_cluster) else: - graph_double = GraphCSRView[int, int, double]( - c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) + graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, + c_weights, num_verts, num_edges) graph_double.get_vertex_identifiers(c_identifier) c_balanced_cut_clustering(graph_double, @@ -116,7 +102,6 @@ def spectralBalancedCutClustering(input_graph, return df - def spectralModularityMaximizationClustering(input_graph, num_clusters, num_eigen_vects=2, @@ -131,21 +116,15 @@ def spectralModularityMaximizationClustering(input_graph, if input_graph.is_directed(): raise ValueError("directed graphs are not supported") else: - raise TypeError( - f"only cugraph.Graph objects are supported, got: {type(input_graph)}" - ) + raise TypeError(f"only cugraph.Graph objects are supported, got: {type(input_graph)}") if not input_graph.adjlist: input_graph.view_adj_list() if input_graph.adjlist.weights is None: - raise Exception( - "spectral modularity maximization must be called on a graph with weights" - ) + raise Exception("spectral modularity maximization must be called on a graph with weights") - [offsets, indices] = graph_primtypes_wrapper.datatype_cast( - [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) - [weights] = graph_primtypes_wrapper.datatype_cast( - [input_graph.adjlist.weights], [np.float32, np.float64]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) @@ -161,16 +140,12 @@ def spectralModularityMaximizationClustering(input_graph, cdef uintptr_t c_identifier = df['vertex'].__cuda_array_interface__['data'][0] cdef uintptr_t c_cluster = df['cluster'].__cuda_array_interface__['data'][0] - cdef GraphCSRView[int, int, float] graph_float - cdef GraphCSRView[int, int, double] graph_double + cdef GraphCSRView[int,int,float] graph_float + cdef GraphCSRView[int,int,double] graph_double if weights.dtype == np.float32: - graph_float = GraphCSRView[int, int, float]( - c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) + graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, + c_weights, num_verts, num_edges) graph_float.get_vertex_identifiers(c_identifier) c_spectral_modularity_maximization(graph_float, @@ -182,12 +157,8 @@ def spectralModularityMaximizationClustering(input_graph, kmean_max_iter, c_cluster) else: - graph_double = GraphCSRView[int, int, double]( - c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) + graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, + c_weights, num_verts, num_edges) graph_double.get_vertex_identifiers(c_identifier) c_spectral_modularity_maximization(graph_double, @@ -201,7 +172,6 @@ def spectralModularityMaximizationClustering(input_graph, return df - def analyzeClustering_modularity(input_graph, n_clusters, clustering): """ Call analyzeClustering_modularity_nvgraph @@ -210,28 +180,21 @@ def analyzeClustering_modularity(input_graph, n_clusters, clustering): if input_graph.is_directed(): raise ValueError("directed graphs are not supported") else: - raise TypeError( - f"only cugraph.Graph objects are supported, got: {type(input_graph)}" - ) + raise TypeError(f"only cugraph.Graph objects are supported, got: {type(input_graph)}") if not input_graph.adjlist: input_graph.view_adj_list() - [offsets, indices] = graph_primtypes_wrapper.datatype_cast( - [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) - [weights] = graph_primtypes_wrapper.datatype_cast( - [input_graph.adjlist.weights], [np.float32, np.float64]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) score = None num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) if input_graph.adjlist.weights is None: - raise Exception( - "analyze clustering modularity must be called on a graph with weights" - ) + raise Exception("analyze clustering modularity must be called on a graph with weights") if input_graph.adjlist.weights is not None: - [weights] = graph_primtypes_wrapper.datatype_cast( - [input_graph.adjlist.weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) else: weights = cudf.Series(np.full(num_edges, 1.0, dtype=np.float32)) @@ -240,18 +203,14 @@ def analyzeClustering_modularity(input_graph, n_clusters, clustering): cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] cdef uintptr_t c_cluster = clustering.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int, int, float] graph_float - cdef GraphCSRView[int, int, double] graph_double + cdef GraphCSRView[int,int,float] graph_float + cdef GraphCSRView[int,int,double] graph_double cdef float score_float cdef double score_double if weights.dtype == np.float32: - graph_float = GraphCSRView[int, int, float]( - c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) + graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, + c_weights, num_verts, num_edges) c_analyze_clustering_modularity(graph_float, n_clusters, @@ -260,12 +219,8 @@ def analyzeClustering_modularity(input_graph, n_clusters, clustering): score = score_float else: - graph_double = GraphCSRView[int, int, double]( - c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) + graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, + c_weights, num_verts, num_edges) c_analyze_clustering_modularity(graph_double, n_clusters, @@ -275,7 +230,6 @@ def analyzeClustering_modularity(input_graph, n_clusters, clustering): return score - def analyzeClustering_edge_cut(input_graph, n_clusters, clustering): """ Call analyzeClustering_edge_cut_nvgraph @@ -284,22 +238,18 @@ def analyzeClustering_edge_cut(input_graph, n_clusters, clustering): if input_graph.is_directed(): raise ValueError("directed graphs are not supported") else: - raise TypeError( - f"only cugraph.Graph objects are supported, got: {type(input_graph)}" - ) + raise TypeError(f"only cugraph.Graph objects are supported, got: {type(input_graph)}") if not input_graph.adjlist: input_graph.view_adj_list() - [offsets, indices] = graph_primtypes_wrapper.datatype_cast( - [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) score = None num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) if input_graph.adjlist.weights is not None: - [weights] = graph_primtypes_wrapper.datatype_cast( - [input_graph.adjlist.weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) else: weights = cudf.Series(np.full(num_edges, 1.0, dtype=np.float32)) @@ -308,18 +258,14 @@ def analyzeClustering_edge_cut(input_graph, n_clusters, clustering): cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] cdef uintptr_t c_cluster = clustering.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int, int, float] graph_float - cdef GraphCSRView[int, int, double] graph_double + cdef GraphCSRView[int,int,float] graph_float + cdef GraphCSRView[int,int,double] graph_double cdef float score_float cdef double score_double if weights.dtype == np.float32: - graph_float = GraphCSRView[int, int, float]( - c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) + graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, + c_weights, num_verts, num_edges) c_analyze_clustering_edge_cut(graph_float, n_clusters, @@ -328,12 +274,8 @@ def analyzeClustering_edge_cut(input_graph, n_clusters, clustering): score = score_float else: - graph_double = GraphCSRView[int, int, double]( - c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) + graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, + c_weights, num_verts, num_edges) c_analyze_clustering_edge_cut(graph_double, n_clusters, @@ -343,7 +285,6 @@ def analyzeClustering_edge_cut(input_graph, n_clusters, clustering): return score - def analyzeClustering_ratio_cut(input_graph, n_clusters, clustering): """ Call analyzeClustering_ratio_cut_nvgraph @@ -352,22 +293,18 @@ def analyzeClustering_ratio_cut(input_graph, n_clusters, clustering): if input_graph.is_directed(): raise ValueError("directed graphs are not supported") else: - raise TypeError( - f"only cugraph.Graph objects are supported, got: {type(input_graph)}" - ) + raise TypeError(f"only cugraph.Graph objects are supported, got: {type(input_graph)}") if not input_graph.adjlist: input_graph.view_adj_list() - [offsets, indices] = graph_primtypes_wrapper.datatype_cast( - [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) score = None num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) if input_graph.adjlist.weights is not None: - [weights] = graph_primtypes_wrapper.datatype_cast( - [input_graph.adjlist.weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) else: weights = cudf.Series(np.full(num_edges, 1.0, dtype=np.float32)) @@ -376,18 +313,14 @@ def analyzeClustering_ratio_cut(input_graph, n_clusters, clustering): cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] cdef uintptr_t c_cluster = clustering.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int, int, float] graph_float - cdef GraphCSRView[int, int, double] graph_double + cdef GraphCSRView[int,int,float] graph_float + cdef GraphCSRView[int,int,double] graph_double cdef float score_float cdef double score_double if weights.dtype == np.float32: - graph_float = GraphCSRView[int, int, float]( - c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) + graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, + c_weights, num_verts, num_edges) c_analyze_clustering_ratio_cut(graph_float, n_clusters, @@ -396,12 +329,8 @@ def analyzeClustering_ratio_cut(input_graph, n_clusters, clustering): score = score_float else: - graph_double = GraphCSRView[int, int, double]( - c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) + graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, + c_weights, num_verts, num_edges) c_analyze_clustering_ratio_cut(graph_double, n_clusters, diff --git a/python/cugraph/cugraph/community/subgraph_extraction.pxd b/python/cugraph/cugraph/community/subgraph_extraction.pxd index bc2b789ea71..583e220327d 100644 --- a/python/cugraph/cugraph/community/subgraph_extraction.pxd +++ b/python/cugraph/cugraph/community/subgraph_extraction.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2021, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -22,7 +22,7 @@ from libcpp.memory cimport unique_ptr cdef extern from "cugraph/algorithms.hpp" namespace "cugraph::subgraph": - cdef unique_ptr[GraphCOO[VT, ET, WT]] extract_subgraph_vertex[VT, ET, WT]( - const GraphCOOView[VT, ET, WT] &graph, + cdef unique_ptr[GraphCOO[VT,ET,WT]] extract_subgraph_vertex[VT,ET,WT]( + const GraphCOOView[VT,ET,WT] &graph, const VT *vertices, ET num_vertices) except + diff --git a/python/cugraph/cugraph/community/subgraph_extraction_wrapper.pyx b/python/cugraph/cugraph/community/subgraph_extraction_wrapper.pyx index 5e7b2fba36d..46dc5c07eaf 100644 --- a/python/cugraph/cugraph/community/subgraph_extraction_wrapper.pyx +++ b/python/cugraph/cugraph/community/subgraph_extraction_wrapper.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2021, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -16,9 +16,7 @@ # cython: embedsignature = True # cython: language_level = 3 -from cugraph.community.subgraph_extraction cimport ( - extract_subgraph_vertex as c_extract_subgraph_vertex -) +from cugraph.community.subgraph_extraction cimport extract_subgraph_vertex as c_extract_subgraph_vertex from cugraph.structure.graph_primtypes cimport * from cugraph.structure import graph_primtypes_wrapper from libc.stdint cimport uintptr_t @@ -38,15 +36,10 @@ def subgraph(input_graph, vertices): if not input_graph.edgelist: input_graph.view_edge_list() - [src, dst] = graph_primtypes_wrapper.datatype_cast( - [ - input_graph.edgelist.edgelist_df['src'], - input_graph.edgelist.edgelist_df['dst'] - ], [np.int32]) + [src, dst] = graph_primtypes_wrapper.datatype_cast([input_graph.edgelist.edgelist_df['src'], input_graph.edgelist.edgelist_df['dst']], [np.int32]) if input_graph.edgelist.weights: - [weights] = graph_primtypes_wrapper.datatype_cast( - [input_graph.edgelist.edgelist_df['weights']], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.edgelist.edgelist_df['weights']], [np.float32, np.float64]) if weights.dtype == np.float64: use_float = False @@ -54,10 +47,10 @@ def subgraph(input_graph, vertices): num_edges = len(src) num_input_vertices = len(vertices) - cdef GraphCOOView[int, int, float] in_graph_float - cdef GraphCOOView[int, int, double] in_graph_double - cdef unique_ptr[GraphCOO[int, int, float]] out_graph_float - cdef unique_ptr[GraphCOO[int, int, double]] out_graph_double + cdef GraphCOOView[int,int,float] in_graph_float + cdef GraphCOOView[int,int,double] in_graph_double + cdef unique_ptr[GraphCOO[int,int,float]] out_graph_float + cdef unique_ptr[GraphCOO[int,int,double]] out_graph_double cdef uintptr_t c_src = src.__cuda_array_interface__['data'][0] cdef uintptr_t c_dst = dst.__cuda_array_interface__['data'][0] @@ -70,26 +63,18 @@ def subgraph(input_graph, vertices): cdef uintptr_t c_vertices = vertices.__cuda_array_interface__['data'][0] if use_float: - in_graph_float = GraphCOOView[int, int, float]( - c_src, c_dst, c_weights, num_verts, num_edges) - df = coo_to_df(move(c_extract_subgraph_vertex( - in_graph_float, c_vertices, num_input_vertices))) + in_graph_float = GraphCOOView[int,int,float](c_src, c_dst, c_weights, num_verts, num_edges); + df = coo_to_df(move(c_extract_subgraph_vertex(in_graph_float, c_vertices, num_input_vertices))); else: - in_graph_double = GraphCOOView[int, int, double]( - c_src, c_dst, c_weights, num_verts, num_edges) - df = coo_to_df(move(c_extract_subgraph_vertex( - in_graph_double, c_vertices, num_input_vertices))) + in_graph_double = GraphCOOView[int,int,double](c_src, c_dst, c_weights, num_verts, num_edges); + df = coo_to_df(move(c_extract_subgraph_vertex(in_graph_double, c_vertices, num_input_vertices))); # renumber vertices to match original input vertices_df = cudf.DataFrame() vertices_df['v'] = vertices vertices_df = vertices_df.reset_index(drop=True).reset_index() - df = df.merge(vertices_df, left_on='src', right_on='index', how='left') \ - .drop(columns=['src', 'index']) \ - .rename(columns={'v': 'src'}, copy=False) - df = df.merge(vertices_df, left_on='dst', right_on='index', how='left') \ - .drop(columns=['dst', 'index']) \ - .rename(columns={'v': 'dst'}, copy=False) + df = df.merge(vertices_df, left_on='src', right_on='index', how='left').drop(columns=['src', 'index']).rename(columns={'v': 'src'}, copy=False) + df = df.merge(vertices_df, left_on='dst', right_on='index', how='left').drop(columns=['dst', 'index']).rename(columns={'v': 'dst'}, copy=False) return df diff --git a/python/cugraph/cugraph/components/connectivity.pxd b/python/cugraph/cugraph/components/connectivity.pxd index 92c58f2ce2b..9829ce17325 100644 --- a/python/cugraph/cugraph/components/connectivity.pxd +++ b/python/cugraph/cugraph/components/connectivity.pxd @@ -25,7 +25,7 @@ cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": ctypedef enum cugraph_cc_t: CUGRAPH_STRONG "cugraph::cugraph_cc_t::CUGRAPH_STRONG" - cdef void connected_components[VT, ET, WT]( - const GraphCSRView[VT, ET, WT] &graph, + cdef void connected_components[VT,ET,WT]( + const GraphCSRView[VT,ET,WT] &graph, cugraph_cc_t connect_type, VT *labels) except + diff --git a/python/cugraph/cugraph/components/connectivity_wrapper.pyx b/python/cugraph/cugraph/components/connectivity_wrapper.pyx index 7f854ae5291..2a5888f9c9b 100644 --- a/python/cugraph/cugraph/components/connectivity_wrapper.pyx +++ b/python/cugraph/cugraph/components/connectivity_wrapper.pyx @@ -35,8 +35,7 @@ def strongly_connected_components(input_graph): if not input_graph.adjlist: input_graph.view_adj_list() - [offsets, indices] = graph_primtypes_wrapper.datatype_cast( - [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) @@ -45,15 +44,14 @@ def strongly_connected_components(input_graph): df['vertex'] = cudf.Series(np.zeros(num_verts, dtype=np.int32)) df['labels'] = cudf.Series(np.zeros(num_verts, dtype=np.int32)) - cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] - cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] - cdef uintptr_t c_identifier = df['vertex'].__cuda_array_interface__['data'][0] - cdef uintptr_t c_labels_val = df['labels'].__cuda_array_interface__['data'][0] + cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] + cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] + cdef uintptr_t c_identifier = df['vertex'].__cuda_array_interface__['data'][0]; + cdef uintptr_t c_labels_val = df['labels'].__cuda_array_interface__['data'][0]; - cdef GraphCSRView[int, int, float] g + cdef GraphCSRView[int,int,float] g - g = GraphCSRView[int, int, float]( - c_offsets, c_indices, NULL, num_verts, num_edges) + g = GraphCSRView[int,int,float](c_offsets, c_indices, NULL, num_verts, num_edges) cdef cugraph_cc_t connect_type=CUGRAPH_STRONG connected_components(g, connect_type, c_labels_val) diff --git a/python/cugraph/cugraph/dask/comms/comms.pxd b/python/cugraph/cugraph/dask/comms/comms.pxd index 1fcbd513c98..3f8f8c2ca59 100644 --- a/python/cugraph/cugraph/dask/comms/comms.pxd +++ b/python/cugraph/cugraph/dask/comms/comms.pxd @@ -21,5 +21,5 @@ from pylibraft.common.handle cimport * cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": - cdef void init_subcomms(handle_t &handle, - size_t row_comm_size) + cdef void init_subcomms(handle_t &handle, + size_t row_comm_size) diff --git a/python/cugraph/cugraph/dask/structure/replication.pyx b/python/cugraph/cugraph/dask/structure/replication.pyx index d665d320af4..64f43663517 100644 --- a/python/cugraph/cugraph/dask/structure/replication.pyx +++ b/python/cugraph/cugraph/dask/structure/replication.pyx @@ -38,20 +38,15 @@ def replicate_cudf_dataframe(cudf_dataframe, client=None, comms=None): dask_cudf_df = dask_cudf.from_cudf(cudf_dataframe, npartitions=1) df_length = len(dask_cudf_df) - _df_data = get_mg_batch_data(dask_cudf_df, batch_enabled=True) - df_data = mg_utils.prepare_worker_to_parts(_df_data, client) - - workers_to_futures = { - worker: client.submit(_replicate_cudf_dataframe, - ( - data, - cudf_dataframe.columns.values, - cudf_dataframe.dtypes, - df_length - ), - comms.sessionId, - workers=[worker]) - for worker, data in df_data.worker_to_parts.items()} + _df_data = get_mg_batch_data(dask_cudf_df, batch_enabled=True) + df_data = mg_utils.prepare_worker_to_parts(_df_data, client) + + workers_to_futures = {worker: client.submit(_replicate_cudf_dataframe, + (data, cudf_dataframe.columns.values, cudf_dataframe.dtypes, df_length), + comms.sessionId, + workers=[worker]) for + (worker, data) in + df_data.worker_to_parts.items()} dd.wait(workers_to_futures) return workers_to_futures @@ -77,7 +72,7 @@ def _replicate_cudf_dataframe(input_data, session_id): dtype = dtypes[idx] series = cudf.Series(np.zeros(df_length), dtype=dtype) df_data[column] = series - c_series = series.__cuda_array_interface__['data'][0] + c_series = series.__cuda_array_interface__['data'][0] comms_bcast(c_handle, c_series, df_length, series.dtype) if has_data: @@ -92,8 +87,8 @@ def replicate_cudf_series(cudf_series, client=None, comms=None): raise TypeError("Expected a cudf.Series to replicate") client = mg_utils.get_client() if client is None else client comms = Comms.get_comms() if comms is None else comms - dask_cudf_series = dask_cudf.from_cudf(cudf_series, - npartitions=1) + dask_cudf_series = dask_cudf.from_cudf(cudf_series, + npartitions=1) series_length = len(dask_cudf_series) _series_data = get_mg_batch_data(dask_cudf_series, batch_enabled=True) series_data = mg_utils.prepare_worker_to_parts(_series_data) @@ -103,9 +98,9 @@ def replicate_cudf_series(cudf_series, client=None, comms=None): client.submit(_replicate_cudf_series, (data, series_length, dtype), comms.sessionId, - workers=[worker]) for - (worker, data) in - series_data.worker_to_parts.items()} + workers=[worker]) for + (worker, data) in + series_data.worker_to_parts.items()} dd.wait(workers_to_futures) return workers_to_futures @@ -139,11 +134,11 @@ cdef comms_bcast(uintptr_t handle, uintptr_t value_ptr, size_t count, dtype): - if dtype == np.int32: + if dtype == np.int32: c_utils.comms_bcast(( handle)[0], value_ptr, count) elif dtype == np.float32: c_utils.comms_bcast(( handle)[0], value_ptr, count) elif dtype == np.float64: c_utils.comms_bcast(( handle)[0], value_ptr, count) else: - raise TypeError("Unsupported broadcast type") + raise TypeError("Unsupported broadcast type") \ No newline at end of file diff --git a/python/cugraph/cugraph/generators/rmat.pxd b/python/cugraph/cugraph/generators/rmat.pxd index b6f9f4530e4..7c3a4165e3e 100644 --- a/python/cugraph/cugraph/generators/rmat.pxd +++ b/python/cugraph/cugraph/generators/rmat.pxd @@ -40,8 +40,7 @@ cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": bool clip_and_flip, bool scramble_vertex_ids) except + - cdef vector[pair[unique_ptr[device_buffer], unique_ptr[device_buffer]]] \ - call_generate_rmat_edgelists[vertex_t]( + cdef vector[pair[unique_ptr[device_buffer], unique_ptr[device_buffer]]] call_generate_rmat_edgelists[vertex_t]( const handle_t &handle, size_t n_edgelists, size_t min_scale, diff --git a/python/cugraph/cugraph/generators/rmat_wrapper.pyx b/python/cugraph/cugraph/generators/rmat_wrapper.pyx index 22796fcb883..7f1e7f5a219 100644 --- a/python/cugraph/cugraph/generators/rmat_wrapper.pyx +++ b/python/cugraph/cugraph/generators/rmat_wrapper.pyx @@ -61,28 +61,26 @@ def generate_rmat_edgelist( cdef unique_ptr[graph_generator_t] gg_ret_ptr - if vertex_t == np.dtype("int32"): - gg_ret_ptr = move(call_generate_rmat_edgelist[int]( - deref(handle_), - scale, - num_edges, - a, - b, - c, - seed, - clip_and_flip, - scramble_vertex_ids)) - else: # (vertex_t == np.dtype("int64")) - gg_ret_ptr = move(call_generate_rmat_edgelist[long]( - deref(handle_), - scale, - num_edges, - a, - b, - c, - seed, - clip_and_flip, - scramble_vertex_ids)) + if (vertex_t==np.dtype("int32")): + gg_ret_ptr = move(call_generate_rmat_edgelist[int]( deref(handle_), + scale, + num_edges, + a, + b, + c, + seed, + clip_and_flip, + scramble_vertex_ids)) + else: # (vertex_t == np.dtype("int64")) + gg_ret_ptr = move(call_generate_rmat_edgelist[long]( deref(handle_), + scale, + num_edges, + a, + b, + c, + seed, + clip_and_flip, + scramble_vertex_ids)) gg_ret = move(gg_ret_ptr.get()[0]) @@ -106,7 +104,7 @@ def generate_rmat_edgelists( seed, clip_and_flip, scramble_vertex_ids -): + ): vertex_t = np.dtype("int32") if (2**max_scale) > (2**31 - 1): @@ -130,35 +128,32 @@ def generate_rmat_edgelists( cdef vector[pair[unique_ptr[device_buffer], unique_ptr[device_buffer]]] gg_ret_ptr if (vertex_t==np.dtype("int32")): - gg_ret_ptr = move(call_generate_rmat_edgelists[int]( - deref(handle_), - n_edgelists, - min_scale, - max_scale, - edge_factor, - s_distribution, - e_distribution, - seed, - clip_and_flip, - scramble_vertex_ids)) - else: # (vertex_t == np.dtype("int64")) - gg_ret_ptr = move(call_generate_rmat_edgelists[long]( - deref(handle_), - n_edgelists, - min_scale, - max_scale, - edge_factor, - s_distribution, - e_distribution, - seed, - clip_and_flip, - scramble_vertex_ids)) + gg_ret_ptr = move(call_generate_rmat_edgelists[int]( deref(handle_), + n_edgelists, + min_scale, + max_scale, + edge_factor, + s_distribution, + e_distribution, + seed, + clip_and_flip, + scramble_vertex_ids)) + else: # (vertex_t == np.dtype("int64")) + gg_ret_ptr = move(call_generate_rmat_edgelists[long]( deref(handle_), + n_edgelists, + min_scale, + max_scale, + edge_factor, + s_distribution, + e_distribution, + seed, + clip_and_flip, + scramble_vertex_ids)) list_df = [] for i in range(n_edgelists): set_source = move_device_buffer_to_column(move(gg_ret_ptr[i].first), vertex_t) - set_destination = move_device_buffer_to_column( - move(gg_ret_ptr[i].second), vertex_t) + set_destination = move_device_buffer_to_column(move(gg_ret_ptr[i].second), vertex_t) df = cudf.DataFrame() df['src'] = set_source @@ -166,5 +161,5 @@ def generate_rmat_edgelists( list_df.append(df) - # Return a list of dataframes + #Return a list of dataframes return list_df diff --git a/python/cugraph/cugraph/layout/force_atlas2_wrapper.pyx b/python/cugraph/cugraph/layout/force_atlas2_wrapper.pyx index da6be88a716..73de7415971 100644 --- a/python/cugraph/cugraph/layout/force_atlas2_wrapper.pyx +++ b/python/cugraph/cugraph/layout/force_atlas2_wrapper.pyx @@ -51,7 +51,7 @@ def force_atlas2(input_graph, cdef unique_ptr[handle_t] handle_ptr handle_ptr.reset(new handle_t()) - handle_ = handle_ptr.get() + handle_ = handle_ptr.get(); if not input_graph.edgelist: input_graph.view_edge_list() @@ -59,8 +59,8 @@ def force_atlas2(input_graph, num_verts = input_graph.number_of_vertices() num_edges = len(input_graph.edgelist.edgelist_df['src']) - cdef GraphCOOView[int, int, float] graph_float - cdef GraphCOOView[int, int, double] graph_double + cdef GraphCOOView[int,int,float] graph_float + cdef GraphCOOView[int,int,double] graph_double df = cudf.DataFrame() df['vertex'] = cudf.Series(np.arange(num_verts, dtype=np.int32)) @@ -76,8 +76,7 @@ def force_atlas2(input_graph, if input_graph.edgelist.weights: weights = input_graph.edgelist.edgelist_df["weights"] - [weights] = graph_primtypes_wrapper.datatype_cast( - [weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast([weights], [np.float32, np.float64]) c_weights = weights.__cuda_array_interface__['data'][0] cdef uintptr_t x_start = NULL @@ -98,68 +97,60 @@ def force_atlas2(input_graph, if callback: callback_ptr = callback.get_native_callback() + # We keep np.float32 as results for both cases pos = cuda.device_array( - (num_verts, 2), - order="F", - dtype=np.float32) + (num_verts, 2), + order="F", + dtype=np.float32) pos_ptr = pos.device_ctypes_pointer.value if input_graph.edgelist.weights \ and input_graph.edgelist.edgelist_df['weights'].dtype == np.float64: - graph_double = GraphCOOView[int, int, double]( - c_src_indices, - c_dst_indices, - c_weights, - num_verts, - num_edges) - - c_force_atlas2[int, int, double]( - handle_[0], - graph_double, - pos_ptr, - max_iter, - x_start, - y_start, - outbound_attraction_distribution, - lin_log_mode, - prevent_overlapping, - edge_weight_influence, - jitter_tolerance, - barnes_hut_optimize, - barnes_hut_theta, - scaling_ratio, - strong_gravity_mode, - gravity, - verbose, - callback_ptr) + graph_double = GraphCOOView[int,int, double](c_src_indices, + c_dst_indices, c_weights, num_verts, num_edges) + + c_force_atlas2[int, int, double](handle_[0], + graph_double, + pos_ptr, + max_iter, + x_start, + y_start, + outbound_attraction_distribution, + lin_log_mode, + prevent_overlapping, + edge_weight_influence, + jitter_tolerance, + barnes_hut_optimize, + barnes_hut_theta, + scaling_ratio, + strong_gravity_mode, + gravity, + verbose, + callback_ptr) else: - graph_float = GraphCOOView[int, int, float]( - c_src_indices, - c_dst_indices, - c_weights, - num_verts, - num_edges) - c_force_atlas2[int, int, float]( - handle_[0], - graph_float, - pos_ptr, - max_iter, - x_start, - y_start, - outbound_attraction_distribution, - lin_log_mode, - prevent_overlapping, - edge_weight_influence, - jitter_tolerance, - barnes_hut_optimize, - barnes_hut_theta, - scaling_ratio, - strong_gravity_mode, - gravity, - verbose, - callback_ptr) + graph_float = GraphCOOView[int,int,float](c_src_indices, + c_dst_indices, c_weights, num_verts, + num_edges) + c_force_atlas2[int, int, float](handle_[0], + graph_float, + pos_ptr, + max_iter, + x_start, + y_start, + outbound_attraction_distribution, + lin_log_mode, + prevent_overlapping, + edge_weight_influence, + jitter_tolerance, + barnes_hut_optimize, + barnes_hut_theta, + scaling_ratio, + strong_gravity_mode, + gravity, + verbose, + callback_ptr) pos_df = cudf.DataFrame(pos, columns=['x', 'y']) df['x'] = pos_df['x'] diff --git a/python/cugraph/cugraph/linear_assignment/lap.pxd b/python/cugraph/cugraph/linear_assignment/lap.pxd index 8712cfce7cb..9f65e215891 100644 --- a/python/cugraph/cugraph/linear_assignment/lap.pxd +++ b/python/cugraph/cugraph/linear_assignment/lap.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-2021, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -20,24 +20,24 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": - cdef weight_t hungarian[vertex_t, edge_t, weight_t]( + cdef weight_t hungarian[vertex_t,edge_t,weight_t]( const handle_t &handle, - const GraphCOOView[vertex_t, edge_t, weight_t] &graph, + const GraphCOOView[vertex_t,edge_t,weight_t] &graph, vertex_t num_workers, const vertex_t *workers, vertex_t *assignments, weight_t epsilon) except + - cdef weight_t hungarian[vertex_t, edge_t, weight_t]( + cdef weight_t hungarian[vertex_t,edge_t,weight_t]( const handle_t &handle, - const GraphCOOView[vertex_t, edge_t, weight_t] &graph, + const GraphCOOView[vertex_t,edge_t,weight_t] &graph, vertex_t num_workers, const vertex_t *workers, vertex_t *assignments) except + cdef extern from "cugraph/algorithms.hpp": - cdef weight_t dense_hungarian "cugraph::dense::hungarian" [vertex_t, weight_t]( + cdef weight_t dense_hungarian "cugraph::dense::hungarian" [vertex_t,weight_t]( const handle_t &handle, const weight_t *costs, vertex_t num_rows, @@ -45,7 +45,7 @@ cdef extern from "cugraph/algorithms.hpp": vertex_t *assignments, weight_t epsilon) except + - cdef weight_t dense_hungarian "cugraph::dense::hungarian" [vertex_t, weight_t]( + cdef weight_t dense_hungarian "cugraph::dense::hungarian" [vertex_t,weight_t]( const handle_t &handle, const weight_t *costs, vertex_t num_rows, diff --git a/python/cugraph/cugraph/linear_assignment/lap_wrapper.pyx b/python/cugraph/cugraph/linear_assignment/lap_wrapper.pyx index 2204136a1e7..c173f45fa3f 100644 --- a/python/cugraph/cugraph/linear_assignment/lap_wrapper.pyx +++ b/python/cugraph/cugraph/linear_assignment/lap_wrapper.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-2021, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -36,7 +36,7 @@ def sparse_hungarian(input_graph, workers, epsilon): cdef unique_ptr[handle_t] handle_ptr handle_ptr.reset(new handle_t()) - handle_ = handle_ptr.get() + handle_ = handle_ptr.get(); """ We need a COO of the graph. @@ -52,8 +52,7 @@ def sparse_hungarian(input_graph, workers, epsilon): weights = input_graph.edgelist.edgelist_df["weights"] [src, dst] = graph_primtypes_wrapper.datatype_cast([src, dst], [np.int32]) - [weights] = graph_primtypes_wrapper.datatype_cast( - [weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast([weights], [np.float32, np.float64]) [local_workers] = graph_primtypes_wrapper.datatype_cast([workers], [np.int32]) num_verts = input_graph.number_of_vertices() @@ -63,52 +62,30 @@ def sparse_hungarian(input_graph, workers, epsilon): df['vertex'] = workers df['assignment'] = cudf.Series(np.zeros(len(workers), dtype=np.int32)) - if epsilon is None: + if epsilon == None: epsilon = 1e-6 - cdef uintptr_t c_src = src.__cuda_array_interface__['data'][0] - cdef uintptr_t c_dst = dst.__cuda_array_interface__['data'][0] - cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] - cdef uintptr_t c_workers = local_workers.__cuda_array_interface__['data'][0] + cdef uintptr_t c_src = src.__cuda_array_interface__['data'][0] + cdef uintptr_t c_dst = dst.__cuda_array_interface__['data'][0] + cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] + cdef uintptr_t c_workers = local_workers.__cuda_array_interface__['data'][0] - cdef uintptr_t c_identifier = df['vertex'].__cuda_array_interface__['data'][0] - cdef uintptr_t c_assignment = df['assignment'].__cuda_array_interface__['data'][0] + cdef uintptr_t c_identifier = df['vertex'].__cuda_array_interface__['data'][0]; + cdef uintptr_t c_assignment = df['assignment'].__cuda_array_interface__['data'][0]; cdef float c_epsilon_float = epsilon cdef double c_epsilon_double = epsilon - cdef GraphCOOView[int, int, float] g_float - cdef GraphCOOView[int, int, double] g_double + cdef GraphCOOView[int,int,float] g_float + cdef GraphCOOView[int,int,double] g_double if weights.dtype == np.float32: - g_float = GraphCOOView[int, int, float]( - c_src, - c_dst, - c_weights, - num_verts, - num_edges) - - cost = c_hungarian[int, int, float]( - handle_[0], - g_float, - len(workers), - c_workers, - c_assignment, - c_epsilon_float) + g_float = GraphCOOView[int,int,float](c_src, c_dst, c_weights, num_verts, num_edges) + + cost = c_hungarian[int,int,float](handle_[0], g_float, len(workers), c_workers, c_assignment, c_epsilon_float) else: - g_double = GraphCOOView[int, int, double]( - c_src, - c_dst, - c_weights, - num_verts, - num_edges) - - cost = c_hungarian[int, int, double]( - handle_[0], - g_double, - len(workers), - c_workers, - c_assignment, - c_epsilon_double) + g_double = GraphCOOView[int,int,double](c_src, c_dst, c_weights, num_verts, num_edges) + + cost = c_hungarian[int,int,double](handle_[0], g_double, len(workers), c_workers, c_assignment, c_epsilon_double) return cost, df @@ -122,11 +99,11 @@ def dense_hungarian(costs, num_rows, num_columns, epsilon): cdef unique_ptr[handle_t] handle_ptr handle_ptr.reset(new handle_t()) - handle_ = handle_ptr.get() + handle_ = handle_ptr.get(); assignment = cudf.Series(np.zeros(num_rows, dtype=np.int32)) - if epsilon is None: + if epsilon == None: epsilon = 1e-6 cdef uintptr_t c_costs = costs.__cuda_array_interface__['data'][0] @@ -135,29 +112,12 @@ def dense_hungarian(costs, num_rows, num_columns, epsilon): cdef double c_epsilon_double = epsilon if costs.dtype == np.float32: - cost = c_dense_hungarian[int, float]( - handle_[0], - c_costs, - num_rows, - num_columns, - c_assignment, - c_epsilon_float) + cost = c_dense_hungarian[int,float](handle_[0], c_costs, num_rows, num_columns, c_assignment, c_epsilon_float) elif costs.dtype == np.float64: - cost = c_dense_hungarian[int, double]( - handle_[0], - c_costs, - num_rows, - num_columns, - c_assignment, - c_epsilon_double) + cost = c_dense_hungarian[int,double](handle_[0], c_costs, num_rows, num_columns, c_assignment, c_epsilon_double) elif costs.dtype == np.int32: - cost = c_dense_hungarian[int, double]( - handle_[0], - c_costs, - num_rows, - num_columns, - c_assignment) + cost = c_dense_hungarian[int,double](handle_[0], c_costs, num_rows, num_columns, c_assignment) else: - raise ValueError(f"unsupported type: {costs.dtype}") + raise("unsported type: ", costs.dtype) return cost, assignment diff --git a/python/cugraph/cugraph/link_prediction/jaccard.pxd b/python/cugraph/cugraph/link_prediction/jaccard.pxd index 902849168d7..9e8c82ec3d8 100644 --- a/python/cugraph/cugraph/link_prediction/jaccard.pxd +++ b/python/cugraph/cugraph/link_prediction/jaccard.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2021, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -21,13 +21,13 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": - cdef void jaccard[VT, ET, WT]( - const GraphCSRView[VT, ET, WT] &graph, + cdef void jaccard[VT,ET,WT]( + const GraphCSRView[VT,ET,WT] &graph, const WT *weights, WT *result) except + - cdef void jaccard_list[VT, ET, WT]( - const GraphCSRView[VT, ET, WT] &graph, + cdef void jaccard_list[VT,ET,WT]( + const GraphCSRView[VT,ET,WT] &graph, const WT *weights, ET num_pairs, const VT *first, diff --git a/python/cugraph/cugraph/link_prediction/jaccard_wrapper.pyx b/python/cugraph/cugraph/link_prediction/jaccard_wrapper.pyx index 4b76879bc0e..e66d8bf0b5c 100644 --- a/python/cugraph/cugraph/link_prediction/jaccard_wrapper.pyx +++ b/python/cugraph/cugraph/link_prediction/jaccard_wrapper.pyx @@ -33,21 +33,20 @@ def jaccard(input_graph, weights_arr=None, vertex_pair=None): indices = None if input_graph.adjlist: - [offsets, indices] = graph_primtypes_wrapper.datatype_cast( - [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, + input_graph.adjlist.indices], [np.int32]) elif input_graph.transposedadjlist: - # NOTE: jaccard ONLY operates on an undirected graph, so CSR and CSC - # should be equivalent. The undirected check has already happened, so - # we'll just use the CSC as if it were CSR. - [offsets, indices] = graph_primtypes_wrapper.datatype_cast( - [ - input_graph.transposedadjlist.offsets, - input_graph.transposedadjlist.indices, - ], [np.int32]) + # + # NOTE: jaccard ONLY operates on an undirected graph, so CSR and CSC should be + # equivalent. The undirected check has already happened, so we'll just use + # the CSC as if it were CSR. + # + [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.transposedadjlist.offsets, + input_graph.transposedadjlist.indices], [np.int32]) else: input_graph.view_adj_list() - [offsets, indices] = graph_primtypes_wrapper.datatype_cast( - [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, + input_graph.adjlist.indices], [np.int32]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) @@ -64,14 +63,13 @@ def jaccard(input_graph, weights_arr=None, vertex_pair=None): cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int, int, float] graph_float - cdef GraphCSRView[int, int, double] graph_double + cdef GraphCSRView[int,int,float] graph_float + cdef GraphCSRView[int,int,double] graph_double weight_type = np.float32 if weights_arr is not None: - [weights] = graph_primtypes_wrapper.datatype_cast( - [weights_arr], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast([weights_arr], [np.float32, np.float64]) c_weights = weights.__cuda_array_interface__['data'][0] weight_type = weights.dtype @@ -94,25 +92,23 @@ def jaccard(input_graph, weights_arr=None, vertex_pair=None): c_second_col = second.__cuda_array_interface__['data'][0] if weight_type == np.float32: - graph_float = GraphCSRView[int, int, float]( - c_offsets, c_indices, c_weights, - num_verts, num_edges) - c_jaccard_list[int, int, float](graph_float, - c_weights, - result_size, - c_first_col, - c_second_col, - c_result_col) + graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, + c_weights, num_verts, num_edges) + c_jaccard_list[int,int,float](graph_float, + c_weights, + result_size, + c_first_col, + c_second_col, + c_result_col) else: - graph_double = GraphCSRView[int, int, double]( - c_offsets, c_indices, c_weights, - num_verts, num_edges) - c_jaccard_list[int, int, double](graph_double, - c_weights, - result_size, - c_first_col, - c_second_col, - c_result_col) + graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, + c_weights, num_verts, num_edges) + c_jaccard_list[int,int,double](graph_double, + c_weights, + result_size, + c_first_col, + c_second_col, + c_result_col) return df else: @@ -130,14 +126,14 @@ def jaccard(input_graph, weights_arr=None, vertex_pair=None): nan_as_null=False) c_result_col = df['jaccard_coeff'].__cuda_array_interface__['data'][0] - graph_float = GraphCSRView[int, int, float](c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) - c_jaccard[int, int, float](graph_float, - c_weights, - c_result_col) + graph_float = GraphCSRView[int,int,float](c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) + c_jaccard[int,int,float](graph_float, + c_weights, + c_result_col) graph_float.get_source_indices(c_src_index_col) else: @@ -145,14 +141,14 @@ def jaccard(input_graph, weights_arr=None, vertex_pair=None): nan_as_null=False) c_result_col = df['jaccard_coeff'].__cuda_array_interface__['data'][0] - graph_double = GraphCSRView[int, int, double](c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) - c_jaccard[int, int, double](graph_double, - c_weights, - c_result_col) + graph_double = GraphCSRView[int,int,double](c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) + c_jaccard[int,int,double](graph_double, + c_weights, + c_result_col) graph_double.get_source_indices(c_src_index_col) diff --git a/python/cugraph/cugraph/link_prediction/overlap.pxd b/python/cugraph/cugraph/link_prediction/overlap.pxd index ccb47e630a9..f0654472587 100644 --- a/python/cugraph/cugraph/link_prediction/overlap.pxd +++ b/python/cugraph/cugraph/link_prediction/overlap.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2021, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -21,13 +21,13 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": - cdef void overlap[VT, ET, WT]( - const GraphCSRView[VT, ET, WT] &graph, + cdef void overlap[VT,ET,WT]( + const GraphCSRView[VT,ET,WT] &graph, const WT *weights, WT *result) except + - cdef void overlap_list[VT, ET, WT]( - const GraphCSRView[VT, ET, WT] &graph, + cdef void overlap_list[VT,ET,WT]( + const GraphCSRView[VT,ET,WT] &graph, const WT *weights, ET num_pairs, const VT *first, diff --git a/python/cugraph/cugraph/link_prediction/overlap_wrapper.pyx b/python/cugraph/cugraph/link_prediction/overlap_wrapper.pyx index 18dc46e854e..0f61460a72f 100644 --- a/python/cugraph/cugraph/link_prediction/overlap_wrapper.pyx +++ b/python/cugraph/cugraph/link_prediction/overlap_wrapper.pyx @@ -33,8 +33,7 @@ def overlap(input_graph, weights_arr=None, vertex_pair=None): if not input_graph.adjlist: input_graph.view_adj_list() - [offsets, indices] = graph_primtypes_wrapper.datatype_cast( - [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) @@ -51,14 +50,13 @@ def overlap(input_graph, weights_arr=None, vertex_pair=None): cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int, int, float] graph_float - cdef GraphCSRView[int, int, double] graph_double + cdef GraphCSRView[int,int,float] graph_float + cdef GraphCSRView[int,int,double] graph_double weight_type = np.float32 if weights_arr is not None: - [weights] = graph_primtypes_wrapper.datatype_cast( - [weights_arr], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast([weights_arr], [np.float32, np.float64]) c_weights = weights.__cuda_array_interface__['data'][0] weight_type = weights.dtype @@ -81,31 +79,23 @@ def overlap(input_graph, weights_arr=None, vertex_pair=None): c_second_col = second.__cuda_array_interface__['data'][0] if weight_type == np.float32: - graph_float = GraphCSRView[int, int, float]( - c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) - c_overlap_list[int, int, float](graph_float, - c_weights, - result_size, - c_first_col, - c_second_col, - c_result_col) + graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, + c_weights, num_verts, num_edges) + c_overlap_list[int,int,float](graph_float, + c_weights, + result_size, + c_first_col, + c_second_col, + c_result_col) else: - graph_double = GraphCSRView[int, int, double]( - c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) - c_overlap_list[int, int, double](graph_double, - c_weights, - result_size, - c_first_col, - c_second_col, - c_result_col) + graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, + c_weights, num_verts, num_edges) + c_overlap_list[int,int,double](graph_double, + c_weights, + result_size, + c_first_col, + c_second_col, + c_result_col) return df else: @@ -123,15 +113,14 @@ def overlap(input_graph, weights_arr=None, vertex_pair=None): nan_as_null=False) c_result_col = df['overlap_coeff'].__cuda_array_interface__['data'][0] - graph_float = GraphCSRView[int, int, float]( - c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) - c_overlap[int, int, float](graph_float, - c_weights, - c_result_col) + graph_float = GraphCSRView[int,int,float](c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) + c_overlap[int,int,float](graph_float, + c_weights, + c_result_col) graph_float.get_source_indices(c_src_index_col) else: @@ -139,15 +128,14 @@ def overlap(input_graph, weights_arr=None, vertex_pair=None): nan_as_null=False) c_result_col = df['overlap_coeff'].__cuda_array_interface__['data'][0] - graph_double = GraphCSRView[int, int, double]( - c_offsets, - c_indices, - c_weights, - num_verts, - num_edges) - c_overlap[int, int, double](graph_double, - c_weights, - c_result_col) + graph_double = GraphCSRView[int,int,double](c_offsets, + c_indices, + c_weights, + num_verts, + num_edges) + c_overlap[int,int,double](graph_double, + c_weights, + c_result_col) graph_double.get_source_indices(c_src_index_col) diff --git a/python/cugraph/cugraph/structure/graph_primtypes.pxd b/python/cugraph/cugraph/structure/graph_primtypes.pxd index 7a62ef6c79e..f02f33edb67 100644 --- a/python/cugraph/cugraph/structure/graph_primtypes.pxd +++ b/python/cugraph/cugraph/structure/graph_primtypes.pxd @@ -43,9 +43,9 @@ cdef extern from "cugraph/legacy/graph.hpp" namespace "cugraph::legacy": bool tree PropType has_negative_edges - cdef cppclass GraphViewBase[VT, ET, WT]: + cdef cppclass GraphViewBase[VT,ET,WT]: WT *edge_data - handle_t *handle + handle_t *handle; GraphProperties prop VT number_of_vertices ET number_of_edges @@ -56,116 +56,109 @@ cdef extern from "cugraph/legacy/graph.hpp" namespace "cugraph::legacy": void set_local_data(VT* local_vertices_, ET* local_edges_, VT* local_offsets_) void get_vertex_identifiers(VT *) const - GraphViewBase(WT*, VT, ET) + GraphViewBase(WT*,VT,ET) - cdef cppclass GraphCOOView[VT, ET, WT](GraphViewBase[VT, ET, WT]): + cdef cppclass GraphCOOView[VT,ET,WT](GraphViewBase[VT,ET,WT]): VT *src_indices VT *dst_indices - void degree(ET *, DegreeDirection) const + void degree(ET *,DegreeDirection) const GraphCOOView() GraphCOOView(const VT *, const ET *, const WT *, size_t, size_t) - cdef cppclass GraphCompressedSparseBaseView[VT, ET, WT](GraphViewBase[VT, ET, WT]): + cdef cppclass GraphCompressedSparseBaseView[VT,ET,WT](GraphViewBase[VT,ET,WT]): ET *offsets VT *indices void get_source_indices(VT *) const - void degree(ET *, DegreeDirection) const + void degree(ET *,DegreeDirection) const - GraphCompressedSparseBaseView( - const VT *, const ET *, const WT *, size_t, size_t) + GraphCompressedSparseBaseView(const VT *, const ET *, const WT *, size_t, size_t) - cdef cppclass GraphCSRView[VT, ET, WT](GraphCompressedSparseBaseView[VT, ET, WT]): + cdef cppclass GraphCSRView[VT,ET,WT](GraphCompressedSparseBaseView[VT,ET,WT]): GraphCSRView() GraphCSRView(const VT *, const ET *, const WT *, size_t, size_t) - cdef cppclass GraphCSCView[VT, ET, WT](GraphCompressedSparseBaseView[VT, ET, WT]): + cdef cppclass GraphCSCView[VT,ET,WT](GraphCompressedSparseBaseView[VT,ET,WT]): GraphCSCView() GraphCSCView(const VT *, const ET *, const WT *, size_t, size_t) - cdef cppclass GraphCOOContents[VT, ET, WT]: + cdef cppclass GraphCOOContents[VT,ET,WT]: VT number_of_vertices ET number_of_edges unique_ptr[device_buffer] src_indices unique_ptr[device_buffer] dst_indices unique_ptr[device_buffer] edge_data - cdef cppclass GraphCOO[VT, ET, WT]: + cdef cppclass GraphCOO[VT,ET,WT]: GraphCOO( - VT nv, - ET ne, - bool has_data) except+ - GraphCOOContents[VT, ET, WT] release() - GraphCOOView[VT, ET, WT] view() + VT nv, + ET ne, + bool has_data) except+ + GraphCOOContents[VT,ET,WT] release() + GraphCOOView[VT,ET,WT] view() - cdef cppclass GraphSparseContents[VT, ET, WT]: + cdef cppclass GraphSparseContents[VT,ET,WT]: VT number_of_vertices ET number_of_edges unique_ptr[device_buffer] offsets unique_ptr[device_buffer] indices unique_ptr[device_buffer] edge_data - cdef cppclass GraphCSC[VT, ET, WT]: + cdef cppclass GraphCSC[VT,ET,WT]: GraphCSC( - VT nv, - ET ne, - bool has_data) except+ - GraphSparseContents[VT, ET, WT] release() - GraphCSCView[VT, ET, WT] view() + VT nv, + ET ne, + bool has_data) except+ + GraphSparseContents[VT,ET,WT] release() + GraphCSCView[VT,ET,WT] view() - cdef cppclass GraphCSR[VT, ET, WT]: + cdef cppclass GraphCSR[VT,ET,WT]: GraphCSR( - VT nv, - ET ne, - bool has_data) except+ - GraphSparseContents[VT, ET, WT] release() - GraphCSRView[VT, ET, WT] view() + VT nv, + ET ne, + bool has_data) except+ + GraphSparseContents[VT,ET,WT] release() + GraphCSRView[VT,ET,WT] view() cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": - cdef unique_ptr[GraphCOO[VT, ET, WT]] get_two_hop_neighbors[VT, ET, WT]( + cdef unique_ptr[GraphCOO[VT, ET, WT]] get_two_hop_neighbors[VT,ET,WT]( const GraphCSRView[VT, ET, WT] &graph) except + cdef extern from "" namespace "std" nogil: - cdef unique_ptr[GraphCOO[int, int, float]] move( - unique_ptr[GraphCOO[int, int, float]]) - cdef unique_ptr[GraphCOO[int, int, double]] move( - unique_ptr[GraphCOO[int, int, double]]) - cdef GraphCOOContents[int, int, float] move(GraphCOOContents[int, int, float]) - cdef GraphCOOContents[int, int, double] move(GraphCOOContents[int, int, double]) + cdef unique_ptr[GraphCOO[int,int,float]] move(unique_ptr[GraphCOO[int,int,float]]) + cdef unique_ptr[GraphCOO[int,int,double]] move(unique_ptr[GraphCOO[int,int,double]]) + cdef GraphCOOContents[int,int,float] move(GraphCOOContents[int,int,float]) + cdef GraphCOOContents[int,int,double] move(GraphCOOContents[int,int,double]) cdef device_buffer move(device_buffer) cdef unique_ptr[device_buffer] move(unique_ptr[device_buffer]) - cdef unique_ptr[GraphCSR[int, int, float]] move( - unique_ptr[GraphCSR[int, int, float]]) - cdef unique_ptr[GraphCSR[int, int, double]] move( - unique_ptr[GraphCSR[int, int, double]]) - cdef GraphSparseContents[int, int, float] move( - GraphSparseContents[int, int, float]) - cdef GraphSparseContents[int, int, double] move( - GraphSparseContents[int, int, double]) - -ctypedef unique_ptr[GraphCOO[int, int, float]] GraphCOOPtrFloat -ctypedef unique_ptr[GraphCOO[int, int, double]] GraphCOOPtrDouble + cdef unique_ptr[GraphCSR[int,int,float]] move(unique_ptr[GraphCSR[int,int,float]]) + cdef unique_ptr[GraphCSR[int,int,double]] move(unique_ptr[GraphCSR[int,int,double]]) + cdef GraphSparseContents[int,int,float] move(GraphSparseContents[int,int,float]) + cdef GraphSparseContents[int,int,double] move(GraphSparseContents[int,int,double]) + +ctypedef unique_ptr[GraphCOO[int,int,float]] GraphCOOPtrFloat +ctypedef unique_ptr[GraphCOO[int,int,double]] GraphCOOPtrDouble ctypedef fused GraphCOOPtrType: GraphCOOPtrFloat GraphCOOPtrDouble -ctypedef unique_ptr[GraphCSR[int, int, float]] GraphCSRPtrFloat -ctypedef unique_ptr[GraphCSR[int, int, double]] GraphCSRPtrDouble +ctypedef unique_ptr[GraphCSR[int,int,float]] GraphCSRPtrFloat +ctypedef unique_ptr[GraphCSR[int,int,double]] GraphCSRPtrDouble ctypedef fused GraphCSRPtrType: GraphCSRPtrFloat GraphCSRPtrDouble -ctypedef GraphCOOView[int, int, float] GraphCOOViewFloat -ctypedef GraphCOOView[int, int, double] GraphCOOViewDouble -ctypedef GraphCSRView[int, int, float] GraphCSRViewFloat -ctypedef GraphCSRView[int, int, double] GraphCSRViewDouble +ctypedef GraphCOOView[int,int,float] GraphCOOViewFloat +ctypedef GraphCOOView[int,int,double] GraphCOOViewDouble +ctypedef GraphCSRView[int,int,float] GraphCSRViewFloat +ctypedef GraphCSRView[int,int,double] GraphCSRViewDouble ctypedef fused GraphCOOViewType: GraphCOOViewFloat @@ -181,11 +174,8 @@ ctypedef fused GraphViewType: GraphCSRViewFloat GraphCSRViewDouble -cdef move_device_buffer_to_column( - unique_ptr[device_buffer] device_buffer_unique_ptr, dtype) -cdef move_device_buffer_to_series( - unique_ptr[device_buffer] device_buffer_unique_ptr, dtype, series_name) +cdef move_device_buffer_to_column(unique_ptr[device_buffer] device_buffer_unique_ptr, dtype) +cdef move_device_buffer_to_series(unique_ptr[device_buffer] device_buffer_unique_ptr, dtype, series_name) cdef coo_to_df(GraphCOOPtrType graph) cdef csr_to_series(GraphCSRPtrType graph) -cdef GraphViewType get_graph_view( - input_graph, bool weightless=*, GraphViewType* dummy=*) +cdef GraphViewType get_graph_view(input_graph, bool weightless=*, GraphViewType* dummy=*) diff --git a/python/cugraph/cugraph/structure/graph_primtypes.pyx b/python/cugraph/cugraph/structure/graph_primtypes.pyx index 796d18677f6..fadd0f73a08 100644 --- a/python/cugraph/cugraph/structure/graph_primtypes.pyx +++ b/python/cugraph/cugraph/structure/graph_primtypes.pyx @@ -25,8 +25,8 @@ from cudf.core.buffer import as_buffer import cudf -cdef move_device_buffer_to_column(unique_ptr[device_buffer] device_buffer_unique_ptr, - dtype): +cdef move_device_buffer_to_column( + unique_ptr[device_buffer] device_buffer_unique_ptr, dtype): """ Transfers ownership of device_buffer_unique_ptr to a cuDF buffer which is used to construct a cudf column object, which is then returned. If the @@ -41,8 +41,8 @@ cdef move_device_buffer_to_column(unique_ptr[device_buffer] device_buffer_unique return None -cdef move_device_buffer_to_series(unique_ptr[device_buffer] device_buffer_unique_ptr, - dtype, series_name): +cdef move_device_buffer_to_series( + unique_ptr[device_buffer] device_buffer_unique_ptr, dtype, series_name): """ Transfers ownership of device_buffer_unique_ptr to a cuDF buffer which is used to construct a cudf.Series object with name series_name, which is then @@ -101,18 +101,12 @@ cdef csr_to_series(GraphCSRPtrType graph): return (csr_offsets, csr_indices, csr_weights) -cdef GraphCSRViewType get_csr_graph_view( - input_graph, - bool weighted=True, - GraphCSRViewType* dummy=NULL -): +cdef GraphCSRViewType get_csr_graph_view(input_graph, bool weighted=True, GraphCSRViewType* dummy=NULL): if not input_graph.adjlist: input_graph.view_adj_list() - cdef uintptr_t c_off = \ - input_graph.adjlist.offsets.__cuda_array_interface__['data'][0] - cdef uintptr_t c_ind = \ - input_graph.adjlist.indices.__cuda_array_interface__['data'][0] + cdef uintptr_t c_off = input_graph.adjlist.offsets.__cuda_array_interface__['data'][0] + cdef uintptr_t c_ind = input_graph.adjlist.indices.__cuda_array_interface__['data'][0] cdef uintptr_t c_weights = NULL if input_graph.adjlist.weights is not None and weighted: @@ -122,19 +116,13 @@ cdef GraphCSRViewType get_csr_graph_view( num_edges = input_graph.number_of_edges(directed_edges=True) cdef GraphCSRViewType in_graph if GraphCSRViewType is GraphCSRViewFloat: - in_graph = GraphCSRViewFloat( - c_off, c_ind, c_weights, num_verts, num_edges) + in_graph = GraphCSRViewFloat(c_off, c_ind, c_weights, num_verts, num_edges) elif GraphCSRViewType is GraphCSRViewDouble: - in_graph = GraphCSRViewDouble( - c_off, c_ind, c_weights, num_verts, num_edges) + in_graph = GraphCSRViewDouble(c_off, c_ind, c_weights, num_verts, num_edges) return in_graph -cdef GraphCOOViewType get_coo_graph_view( - input_graph, - bool weighted=True, - GraphCOOViewType* dummy=NULL -): +cdef GraphCOOViewType get_coo_graph_view(input_graph, bool weighted=True, GraphCOOViewType* dummy=NULL): # FIXME: this function assumes columns named "src" and "dst" and can only # be used for SG graphs due to that assumption. if not input_graph.edgelist: @@ -143,32 +131,23 @@ cdef GraphCOOViewType get_coo_graph_view( num_edges = input_graph.number_of_edges(directed_edges=True) num_verts = input_graph.number_of_vertices() - cdef uintptr_t c_src = \ - input_graph.edgelist.edgelist_df['src'].__cuda_array_interface__['data'][0] - cdef uintptr_t c_dst = \ - input_graph.edgelist.edgelist_df['dst'].__cuda_array_interface__['data'][0] + cdef uintptr_t c_src = input_graph.edgelist.edgelist_df['src'].__cuda_array_interface__['data'][0] + cdef uintptr_t c_dst = input_graph.edgelist.edgelist_df['dst'].__cuda_array_interface__['data'][0] cdef uintptr_t c_weights = NULL # FIXME explicit check for None fails, different behavior than get_csr_graph_view if input_graph.edgelist.weights and weighted: - c_weights = \ - input_graph.edgelist.edgelist_df['weights'].__cuda_array_interface__['data'][0] # noqa: E501 + c_weights = input_graph.edgelist.edgelist_df['weights'].__cuda_array_interface__['data'][0] cdef GraphCOOViewType in_graph if GraphCOOViewType is GraphCOOViewFloat: - in_graph = GraphCOOViewFloat( - c_src, c_dst, c_weights, num_verts, num_edges) + in_graph = GraphCOOViewFloat(c_src, c_dst, c_weights, num_verts, num_edges) elif GraphCOOViewType is GraphCOOViewDouble: - in_graph = GraphCOOViewDouble( - c_src, c_dst, c_weights, num_verts, num_edges) + in_graph = GraphCOOViewDouble(c_src, c_dst, c_weights, num_verts, num_edges) return in_graph -cdef GraphViewType get_graph_view( - input_graph, - bool weighted=True, - GraphViewType* dummy=NULL -): +cdef GraphViewType get_graph_view(input_graph, bool weighted = True, GraphViewType* dummy=NULL): if GraphViewType is GraphCOOViewFloat: return get_coo_graph_view[GraphCOOViewFloat](input_graph, weighted, dummy) elif GraphViewType is GraphCOOViewDouble: diff --git a/python/cugraph/cugraph/structure/graph_primtypes_wrapper.pyx b/python/cugraph/cugraph/structure/graph_primtypes_wrapper.pyx index 49df86abd2f..b680be143c9 100644 --- a/python/cugraph/cugraph/structure/graph_primtypes_wrapper.pyx +++ b/python/cugraph/cugraph/structure/graph_primtypes_wrapper.pyx @@ -17,9 +17,7 @@ # cython: language_level = 3 from cugraph.structure.graph_primtypes cimport * -from cugraph.structure.graph_primtypes cimport ( - get_two_hop_neighbors as c_get_two_hop_neighbors -) +from cugraph.structure.graph_primtypes cimport get_two_hop_neighbors as c_get_two_hop_neighbors from cugraph.structure.utils_wrapper import * from libcpp cimport bool import enum @@ -57,16 +55,10 @@ def view_adj_list(input_graph): if input_graph.edgelist is None: raise ValueError('Graph is Empty') - [src, dst] = datatype_cast( - [ - input_graph.edgelist.edgelist_df['src'], - input_graph.edgelist.edgelist_df['dst'], - ], [np.int32]) + [src, dst] = datatype_cast([input_graph.edgelist.edgelist_df['src'], input_graph.edgelist.edgelist_df['dst']], [np.int32]) weights = None if input_graph.edgelist.weights: - [weights] = datatype_cast( - [input_graph.edgelist.edgelist_df['weights']], - [np.float32, np.float64]) + [weights] = datatype_cast([input_graph.edgelist.edgelist_df['weights']], [np.float32, np.float64]) return coo2csr(src, dst, weights) @@ -81,16 +73,10 @@ def view_transposed_adj_list(input_graph): else: input_graph.view_edge_list() - [src, dst] = datatype_cast( - [ - input_graph.edgelist.edgelist_df['src'], - input_graph.edgelist.edgelist_df['dst'] - ], [np.int32]) + [src, dst] = datatype_cast([input_graph.edgelist.edgelist_df['src'], input_graph.edgelist.edgelist_df['dst']], [np.int32]) weights = None if input_graph.edgelist.weights: - [weights] = datatype_cast( - [input_graph.edgelist.edgelist_df['weights']], - [np.float32, np.float64]) + [weights] = datatype_cast([input_graph.edgelist.edgelist_df['weights']], [np.float32, np.float64]) return coo2csr(dst, src, weights) @@ -100,33 +86,24 @@ def view_edge_list(input_graph): if input_graph.adjlist is None: raise RuntimeError('Graph is Empty') - [offsets, indices] = datatype_cast( - [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) [weights] = datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int, int, float] graph - graph = GraphCSRView[int, int, float]( - c_offsets, c_indices, NULL, num_verts, num_edges) + cdef GraphCSRView[int,int,float] graph + graph = GraphCSRView[int,int,float](c_offsets, c_indices, NULL, num_verts, num_edges) - src_indices = cudf.Series(np.zeros(num_edges), dtype=indices.dtype) + src_indices = cudf.Series(np.zeros(num_edges), dtype= indices.dtype) cdef uintptr_t c_src_indices = src_indices.__cuda_array_interface__['data'][0] graph.get_source_indices(c_src_indices) return src_indices, indices, weights -def _degree_coo( - edgelist_df, - src_name, - dst_name, - direction=Direction.ALL, - num_verts=None, - sID=None -): +def _degree_coo(edgelist_df, src_name, dst_name, direction=Direction.ALL, num_verts=None, sID=None): # # Computing the degree of the input graph from COO # @@ -153,15 +130,14 @@ def _degree_coo( vertex_col = cudf.Series(np.zeros(num_verts, dtype=np.int32)) degree_col = cudf.Series(np.zeros(num_verts, dtype=np.int32)) - cdef GraphCOOView[int, int, float] graph + cdef GraphCOOView[int,int,float] graph cdef uintptr_t c_vertex = vertex_col.__cuda_array_interface__['data'][0] cdef uintptr_t c_degree = degree_col.__cuda_array_interface__['data'][0] cdef uintptr_t c_src = src.__cuda_array_interface__['data'][0] cdef uintptr_t c_dst = dst.__cuda_array_interface__['data'][0] - graph = GraphCOOView[int, int, float]( - c_src, c_dst, NULL, num_verts, num_edges) + graph = GraphCOOView[int,int,float](c_src, c_dst, NULL, num_verts, num_edges) cdef size_t handle_size_t if sID is not None: @@ -195,15 +171,14 @@ def _degree_csr(offsets, indices, direction=Direction.ALL): vertex_col = cudf.Series(np.zeros(num_verts, dtype=np.int32)) degree_col = cudf.Series(np.zeros(num_verts, dtype=np.int32)) - cdef GraphCSRView[int, int, float] graph + cdef GraphCSRView[int,int,float] graph cdef uintptr_t c_vertex = vertex_col.__cuda_array_interface__['data'][0] cdef uintptr_t c_degree = degree_col.__cuda_array_interface__['data'][0] cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] - graph = GraphCSRView[int, int, float]( - c_offsets, c_indices, NULL, num_verts, num_edges) + graph = GraphCSRView[int,int,float](c_offsets, c_indices, NULL, num_verts, num_edges) graph.degree( c_degree, dir) graph.get_vertex_identifiers(c_vertex) @@ -254,9 +229,9 @@ def _mg_degree(input_graph, direction=Direction.ALL): def _degree(input_graph, direction=Direction.ALL): # FIXME: this function assumes columns named "src" and "dst" and can only # be used for SG graphs due to that assumption. - transpose_direction = {Direction.ALL: Direction.ALL, - Direction.IN: Direction.OUT, - Direction.OUT: Direction.IN} + transpose_direction = { Direction.ALL: Direction.ALL, + Direction.IN: Direction.OUT, + Direction.OUT: Direction.IN } if input_graph.adjlist is not None: return _degree_csr(input_graph.adjlist.offsets, @@ -287,26 +262,20 @@ def _degrees(input_graph): def get_two_hop_neighbors(input_graph): # FIXME: this function assumes columns named "src" and "dst" and can only # be used for SG graphs due to that assumption. - cdef GraphCSRView[int, int, float] graph + cdef GraphCSRView[int,int,float] graph offsets = None indices = None transposed = False if input_graph.adjlist: - [offsets, indices] = datatype_cast( - [input_graph.adjlist.offsets, input_graph.adjlist.indices], - [np.int32]) + [offsets, indices] = datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) elif input_graph.transposedadjlist: - [offsets, indices] = datatype_cast( - [input_graph.adjlist.offsets, input_graph.adjlist.indices], - [np.int32]) + [offsets, indices] = datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) transposed = True else: input_graph.view_adj_list() - [offsets, indices] = datatype_cast( - [input_graph.adjlist.offsets, input_graph.adjlist.indices], - [np.int32]) + [offsets, indices] = datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] @@ -314,14 +283,13 @@ def get_two_hop_neighbors(input_graph): num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) - graph = GraphCSRView[int, int, float]( - c_offsets, c_indices, NULL, num_verts, num_edges) + graph = GraphCSRView[int,int,float](c_offsets, c_indices, NULL, num_verts, num_edges) df = coo_to_df(move(c_get_two_hop_neighbors(graph))) if not transposed: - df.rename(columns={'src': 'first', 'dst': 'second'}, inplace=True) + df.rename(columns={'src':'first', 'dst':'second'}, inplace=True) else: - df.rename(columns={'dst': 'first', 'src': 'second'}, inplace=True) + df.rename(columns={'dst':'first', 'src':'second'}, inplace=True) return df diff --git a/python/cugraph/cugraph/structure/graph_utilities.pxd b/python/cugraph/cugraph/structure/graph_utilities.pxd index 30e66691e78..74edb61fafa 100644 --- a/python/cugraph/cugraph/structure/graph_utilities.pxd +++ b/python/cugraph/cugraph/structure/graph_utilities.pxd @@ -36,7 +36,7 @@ cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": doubleType "cugraph::cython::numberTypeEnum::doubleType" cdef cppclass graph_container_t: - pass + pass cdef void populate_graph_container( graph_container_t &graph_container, @@ -145,16 +145,14 @@ cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": pair[vertex_t, vertex_t] get_part_local_vertex_range() vertex_t get_part_local_vertex_first() vertex_t get_part_local_vertex_last() - pair[vertex_t, vertex_t] get_part_vertex_partition_range( - size_t vertex_partition_idx) + pair[vertex_t, vertex_t] get_part_vertex_partition_range(size_t vertex_partition_idx) vertex_t get_part_vertex_partition_first(size_t vertex_partition_idx) vertex_t get_part_vertex_partition_last(size_t vertex_partition_idx) vertex_t get_part_vertex_partition_size(size_t vertex_partition_idx) size_t get_part_number_of_matrix_partitions() vertex_t get_part_matrix_partition_major_first(size_t partition_idx) vertex_t get_part_matrix_partition_major_last(size_t partition_idx) - vertex_t get_part_matrix_partition_major_value_start_offset( - size_t partition_idx) + vertex_t get_part_matrix_partition_major_value_start_offset(size_t partition_idx) pair[vertex_t, vertex_t] get_part_matrix_partition_minor_range() vertex_t get_part_matrix_partition_minor_first() vertex_t get_part_matrix_partition_minor_last() @@ -163,8 +161,7 @@ cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": # cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": - cdef unique_ptr[major_minor_weights_t[vertex_t, edge_t, weight_t]] \ - call_shuffle[vertex_t, edge_t, weight_t]( + cdef unique_ptr[major_minor_weights_t[vertex_t, edge_t, weight_t]] call_shuffle[vertex_t, edge_t, weight_t]( const handle_t &handle, vertex_t *edgelist_major_vertices, vertex_t *edgelist_minor_vertices, diff --git a/python/cugraph/cugraph/structure/renumber_wrapper.pyx b/python/cugraph/cugraph/structure/renumber_wrapper.pyx index 56a902022e2..58c64104f65 100644 --- a/python/cugraph/cugraph/structure/renumber_wrapper.pyx +++ b/python/cugraph/cugraph/structure/renumber_wrapper.pyx @@ -38,12 +38,9 @@ from cugraph.structure.graph_primtypes cimport move_device_buffer_to_series cdef renumber_helper(shuffled_vertices_t* ptr_maj_min_w, vertex_t, weights): # extract shuffled result: # - cdef pair[unique_ptr[device_buffer], size_t] pair_s_major = \ - deref(ptr_maj_min_w).get_major_wrap() - cdef pair[unique_ptr[device_buffer], size_t] pair_s_minor = \ - deref(ptr_maj_min_w).get_minor_wrap() - cdef pair[unique_ptr[device_buffer], size_t] pair_s_weights = \ - deref(ptr_maj_min_w).get_weights_wrap() + cdef pair[unique_ptr[device_buffer], size_t] pair_s_major = deref(ptr_maj_min_w).get_major_wrap() + cdef pair[unique_ptr[device_buffer], size_t] pair_s_minor = deref(ptr_maj_min_w).get_minor_wrap() + cdef pair[unique_ptr[device_buffer], size_t] pair_s_weights = deref(ptr_maj_min_w).get_weights_wrap() shuffled_major_series = move_device_buffer_to_series( move(pair_s_major.first), vertex_t, "shuffled_major") @@ -52,10 +49,9 @@ cdef renumber_helper(shuffled_vertices_t* ptr_maj_min_w, vertex_t, weights): move(pair_s_minor.first), vertex_t, "shuffled_minor") shuffled_df = cudf.DataFrame() - # Some workers might have no data therefore ensure the empty column have - # the appropriate vertex_t or weight_t. Failing to do that will create am - # empty column of type object which is not supported by - # '__cuda_array_interface__' + # Some workers might have no data therefore ensure the empty column have the appropriate + # vertex_t or weight_t. Failing to do that will create am empty column of type object + # which is not supported by '__cuda_array_interface__' if shuffled_major_series is None: shuffled_df['major_vertices'] = cudf.Series(dtype=vertex_t) else: @@ -92,12 +88,10 @@ def renumber(input_df, # maybe use cpdef ? # TODO: get handle_t out of handle... handle_ptr = handle_size_t - # FIXME: call_shuffle currently works on major/minor while call_renumber is - # updated to work on source/destination. We'd better update call_shuffle to - # work on source/destination as well to avoid switching between major/minor - # & source/destination. Deferring this work at this moment expecting this - # legacy code path will be replaced with the new pylibcugrpah & C API based - # path. + # FIXME: call_shuffle currently works on major/minor while call_renumber is updated to work on + # source/destination. We'd better update call_shuffle to work on source/destination as well to + # avoid switching between major/minor & source/destination. Deferring this work at this moment + # expecting this legacy code path will be replaced with the new pylibcugrpah & C API based path. if not transposed: major_vertices = input_df[renumbered_src_col_name] @@ -106,7 +100,7 @@ def renumber(input_df, # maybe use cpdef ? major_vertices = input_df[renumbered_dst_col_name] minor_vertices = input_df[renumbered_src_col_name] - cdef uintptr_t c_edge_weights = NULL # set below... + cdef uintptr_t c_edge_weights = NULL # set below... vertex_t = major_vertices.dtype if num_global_edges > (2**31 - 1): @@ -140,8 +134,8 @@ def renumber(input_df, # maybe use cpdef ? cdef uintptr_t shuffled_dst = NULL # FIXME: Fix fails when do_check = True - cdef bool do_check = False # ? for now... - cdef bool mg_flag = is_multi_gpu # run Single-GPU or MNMG + cdef bool do_check = False # ? for now... + cdef bool mg_flag = is_multi_gpu # run Single-GPU or MNMG cdef pair[unique_ptr[device_buffer], size_t] pair_original @@ -178,35 +172,25 @@ def renumber(input_df, # maybe use cpdef ? cdef size_t rank_indx = rank if (vertex_t == np.dtype("int32")): - if edge_t == np.dtype("int32"): - if weight_t == np.dtype("float32"): - if is_multi_gpu: - ptr_shuffled_32_32_32.reset(call_shuffle[int, int, float]( - deref(handle_ptr), - c_major_vertices, - c_minor_vertices, - c_edge_weights, - num_local_edges, - weights is not None).release()) - shuffled_df = renumber_helper( - ptr_shuffled_32_32_32.get(), vertex_t, weights) + if ( edge_t == np.dtype("int32")): + if( weight_t == np.dtype("float32")): + if(is_multi_gpu): + ptr_shuffled_32_32_32.reset(call_shuffle[int, int, float](deref(handle_ptr), + c_major_vertices, + c_minor_vertices, + c_edge_weights, + num_local_edges, + weights is not None).release()) + shuffled_df = renumber_helper(ptr_shuffled_32_32_32.get(), vertex_t, weights) major_vertices = shuffled_df['major_vertices'] minor_vertices = shuffled_df['minor_vertices'] num_local_edges = len(shuffled_df) if not transposed: - major = renumbered_src_col_name - minor = renumbered_dst_col_name + major = renumbered_src_col_name; minor = renumbered_dst_col_name else: - major = renumbered_dst_col_name - minor = renumbered_src_col_name - shuffled_df = shuffled_df.rename( - columns={ - 'major_vertices': major, - 'minor_vertices': minor, - }, - copy=False) - edge_counts_32 = move( - ptr_shuffled_32_32_32.get().get_edge_counts_wrap()) + major = renumbered_dst_col_name; minor = renumbered_src_col_name + shuffled_df = shuffled_df.rename(columns={'major_vertices':major, 'minor_vertices':minor}, copy=False) + edge_counts_32 = move(ptr_shuffled_32_32_32.get().get_edge_counts_wrap()) else: shuffled_df = input_df edge_counts_32 = make_unique[vector[int]](1, num_local_edges) @@ -218,37 +202,32 @@ def renumber(input_df, # maybe use cpdef ? shuffled_src = minor_vertices.__cuda_array_interface__['data'][0] shuffled_dst = major_vertices.__cuda_array_interface__['data'][0] - ptr_renum_tuple_32_32.reset(call_renumber[int, int]( - deref(handle_ptr), - shuffled_src, - shuffled_dst, - deref(edge_counts_32.get()), - transposed, - do_check, - mg_flag).release()) + ptr_renum_tuple_32_32.reset(call_renumber[int, int](deref(handle_ptr), + shuffled_src, + shuffled_dst, + deref(edge_counts_32.get()), + transposed, + do_check, + mg_flag).release()) - # original vertices: see helper - pair_original = ptr_renum_tuple_32_32.get().get_dv_wrap() + pair_original = ptr_renum_tuple_32_32.get().get_dv_wrap() # original vertices: see helper original_series = move_device_buffer_to_series( move(pair_original.first), vertex_t, "original") # extract unique_ptr[partition_offsets]: # - uniq_partition_vector_32 = move( - ptr_renum_tuple_32_32.get().get_partition_offsets_wrap()) + uniq_partition_vector_32 = move(ptr_renum_tuple_32_32.get().get_partition_offsets_wrap()) # create series out of a partition range from rank to rank+1: # if is_multi_gpu: - new_series = cudf.Series( - np.arange(uniq_partition_vector_32.get()[0].at(rank_indx), - uniq_partition_vector_32.get()[0].at(rank_indx+1)), - dtype=vertex_t) + new_series = cudf.Series(np.arange(uniq_partition_vector_32.get()[0].at(rank_indx), + uniq_partition_vector_32.get()[0].at(rank_indx+1)), + dtype=vertex_t) else: - new_series = cudf.Series( - np.arange(0, ptr_renum_tuple_32_32.get().get_num_vertices()), - dtype=vertex_t) + new_series = cudf.Series(np.arange(0, ptr_renum_tuple_32_32.get().get_num_vertices()), + dtype=vertex_t) # create new cudf df # # and add the previous series to it: @@ -257,44 +236,32 @@ def renumber(input_df, # maybe use cpdef ? renumbered_map['original_ids'] = original_series renumbered_map['new_ids'] = new_series - uniq_segment_vector_32 = move( - ptr_renum_tuple_32_32.get().get_segment_offsets_wrap()) - segment_offsets = [None] * ( - deref(uniq_segment_vector_32).size()) + uniq_segment_vector_32 = move(ptr_renum_tuple_32_32.get().get_segment_offsets_wrap()) + segment_offsets = [None] * (deref(uniq_segment_vector_32).size()) for i in range(len(segment_offsets)): - segment_offsets[i] = deref(uniq_segment_vector_32)[i] + segment_offsets[i] = deref(uniq_segment_vector_32)[i] return renumbered_map, segment_offsets, shuffled_df - elif weight_t == np.dtype("float64"): - if is_multi_gpu: - ptr_shuffled_32_32_64.reset(call_shuffle[int, int, double]( - deref(handle_ptr), - c_major_vertices, - c_minor_vertices, - c_edge_weights, - num_local_edges, - weights is not None).release()) - - shuffled_df = renumber_helper( - ptr_shuffled_32_32_64.get(), vertex_t, weights) + elif( weight_t == np.dtype("float64")): + if(is_multi_gpu): + ptr_shuffled_32_32_64.reset(call_shuffle[int, int, double](deref(handle_ptr), + c_major_vertices, + c_minor_vertices, + c_edge_weights, + num_local_edges, + weights is not None).release()) + + shuffled_df = renumber_helper(ptr_shuffled_32_32_64.get(), vertex_t, weights) major_vertices = shuffled_df['major_vertices'] minor_vertices = shuffled_df['minor_vertices'] num_local_edges = len(shuffled_df) if not transposed: - major = renumbered_src_col_name - minor = renumbered_dst_col_name + major = renumbered_src_col_name; minor = renumbered_dst_col_name else: - major = renumbered_dst_col_name - minor = renumbered_src_col_name - shuffled_df = shuffled_df.rename( - columns={ - 'major_vertices': major, - 'minor_vertices': minor, - }, - copy=False) - edge_counts_32 = move( - ptr_shuffled_32_32_64.get().get_edge_counts_wrap()) + major = renumbered_dst_col_name; minor = renumbered_src_col_name + shuffled_df = shuffled_df.rename(columns={'major_vertices':major, 'minor_vertices':minor}, copy=False) + edge_counts_32 = move(ptr_shuffled_32_32_64.get().get_edge_counts_wrap()) else: shuffled_df = input_df edge_counts_32 = make_unique[vector[int]](1, num_local_edges) @@ -306,37 +273,32 @@ def renumber(input_df, # maybe use cpdef ? shuffled_src = minor_vertices.__cuda_array_interface__['data'][0] shuffled_dst = major_vertices.__cuda_array_interface__['data'][0] - ptr_renum_tuple_32_32.reset(call_renumber[int, int]( - deref(handle_ptr), - shuffled_src, - shuffled_dst, - deref(edge_counts_32.get()), - transposed, - do_check, - mg_flag).release()) + ptr_renum_tuple_32_32.reset(call_renumber[int, int](deref(handle_ptr), + shuffled_src, + shuffled_dst, + deref(edge_counts_32.get()), + transposed, + do_check, + mg_flag).release()) - # original vertices: see helper - pair_original = ptr_renum_tuple_32_32.get().get_dv_wrap() + pair_original = ptr_renum_tuple_32_32.get().get_dv_wrap() # original vertices: see helper original_series = move_device_buffer_to_series( move(pair_original.first), vertex_t, "original") # extract unique_ptr[partition_offsets]: # - uniq_partition_vector_32 = move( - ptr_renum_tuple_32_32.get().get_partition_offsets_wrap()) + uniq_partition_vector_32 = move(ptr_renum_tuple_32_32.get().get_partition_offsets_wrap()) # create series out of a partition range from rank to rank+1: # if is_multi_gpu: - new_series = cudf.Series( - np.arange(uniq_partition_vector_32.get()[0].at(rank_indx), - uniq_partition_vector_32.get()[0].at(rank_indx+1)), - dtype=vertex_t) + new_series = cudf.Series(np.arange(uniq_partition_vector_32.get()[0].at(rank_indx), + uniq_partition_vector_32.get()[0].at(rank_indx+1)), + dtype=vertex_t) else: - new_series = cudf.Series( - np.arange(0, ptr_renum_tuple_32_32.get().get_num_vertices()), - dtype=vertex_t) + new_series = cudf.Series(np.arange(0, ptr_renum_tuple_32_32.get().get_num_vertices()), + dtype=vertex_t) # create new cudf df # @@ -346,45 +308,33 @@ def renumber(input_df, # maybe use cpdef ? renumbered_map['original_ids'] = original_series renumbered_map['new_ids'] = new_series - uniq_segment_vector_32 = move( - ptr_renum_tuple_32_32.get().get_segment_offsets_wrap()) - segment_offsets = [None] * ( - deref(uniq_segment_vector_32).size()) + uniq_segment_vector_32 = move(ptr_renum_tuple_32_32.get().get_segment_offsets_wrap()) + segment_offsets = [None] * (deref(uniq_segment_vector_32).size()) for i in range(len(segment_offsets)): - segment_offsets[i] = deref(uniq_segment_vector_32)[i] + segment_offsets[i] = deref(uniq_segment_vector_32)[i] return renumbered_map, segment_offsets, shuffled_df - elif edge_t == np.dtype("int64"): - if weight_t == np.dtype("float32"): - if is_multi_gpu: - ptr_shuffled_32_64_32.reset(call_shuffle[int, long, float]( - deref(handle_ptr), - c_major_vertices, - c_minor_vertices, - c_edge_weights, - num_local_edges, - weights is not None).release()) - - shuffled_df = renumber_helper( - ptr_shuffled_32_64_32.get(), vertex_t, weights) + elif ( edge_t == np.dtype("int64")): + if( weight_t == np.dtype("float32")): + if(is_multi_gpu): + ptr_shuffled_32_64_32.reset(call_shuffle[int, long, float](deref(handle_ptr), + c_major_vertices, + c_minor_vertices, + c_edge_weights, + num_local_edges, + weights is not None).release()) + + shuffled_df = renumber_helper(ptr_shuffled_32_64_32.get(), vertex_t, weights) major_vertices = shuffled_df['major_vertices'] minor_vertices = shuffled_df['minor_vertices'] num_local_edges = len(shuffled_df) if not transposed: - major = renumbered_src_col_name - minor = renumbered_dst_col_name + major = renumbered_src_col_name; minor = renumbered_dst_col_name else: - major = renumbered_dst_col_name - minor = renumbered_src_col_name - shuffled_df = shuffled_df.rename( - columns={ - 'major_vertices': major, - 'minor_vertices': minor, - }, - copy=False) - edge_counts_64 = move( - ptr_shuffled_32_64_32.get().get_edge_counts_wrap()) + major = renumbered_dst_col_name; minor = renumbered_src_col_name + shuffled_df = shuffled_df.rename(columns={'major_vertices':major, 'minor_vertices':minor}, copy=False) + edge_counts_64 = move(ptr_shuffled_32_64_32.get().get_edge_counts_wrap()) else: shuffled_df = input_df edge_counts_64 = make_unique[vector[long]](1, num_local_edges) @@ -396,37 +346,32 @@ def renumber(input_df, # maybe use cpdef ? shuffled_src = minor_vertices.__cuda_array_interface__['data'][0] shuffled_dst = major_vertices.__cuda_array_interface__['data'][0] - ptr_renum_tuple_32_64.reset(call_renumber[int, long]( - deref(handle_ptr), - shuffled_src, - shuffled_dst, - deref(edge_counts_64.get()), - transposed, - do_check, - mg_flag).release()) + ptr_renum_tuple_32_64.reset(call_renumber[int, long](deref(handle_ptr), + shuffled_src, + shuffled_dst, + deref(edge_counts_64.get()), + transposed, + do_check, + mg_flag).release()) - # original vertices: see helper - pair_original = ptr_renum_tuple_32_64.get().get_dv_wrap() + pair_original = ptr_renum_tuple_32_64.get().get_dv_wrap() # original vertices: see helper original_series = move_device_buffer_to_series( move(pair_original.first), vertex_t, "original") # extract unique_ptr[partition_offsets]: # - uniq_partition_vector_32 = move( - ptr_renum_tuple_32_64.get().get_partition_offsets_wrap()) + uniq_partition_vector_32 = move(ptr_renum_tuple_32_64.get().get_partition_offsets_wrap()) # create series out of a partition range from rank to rank+1: # if is_multi_gpu: - new_series = cudf.Series( - np.arange(uniq_partition_vector_32.get()[0].at(rank_indx), - uniq_partition_vector_32.get()[0].at(rank_indx+1)), - dtype=vertex_t) + new_series = cudf.Series(np.arange(uniq_partition_vector_32.get()[0].at(rank_indx), + uniq_partition_vector_32.get()[0].at(rank_indx+1)), + dtype=vertex_t) else: - new_series = cudf.Series( - np.arange(0, ptr_renum_tuple_32_64.get().get_num_vertices()), - dtype=vertex_t) + new_series = cudf.Series(np.arange(0, ptr_renum_tuple_32_64.get().get_num_vertices()), + dtype=vertex_t) # create new cudf df # @@ -436,43 +381,31 @@ def renumber(input_df, # maybe use cpdef ? renumbered_map['original_ids'] = original_series renumbered_map['new_ids'] = new_series - uniq_segment_vector_32 = move( - ptr_renum_tuple_32_64.get().get_segment_offsets_wrap()) - segment_offsets = [None] * ( - deref(uniq_segment_vector_32).size()) + uniq_segment_vector_32 = move(ptr_renum_tuple_32_64.get().get_segment_offsets_wrap()) + segment_offsets = [None] * (deref(uniq_segment_vector_32).size()) for i in range(len(segment_offsets)): - segment_offsets[i] = deref(uniq_segment_vector_32)[i] + segment_offsets[i] = deref(uniq_segment_vector_32)[i] return renumbered_map, segment_offsets, shuffled_df - elif weight_t == np.dtype("float64"): - if is_multi_gpu: - ptr_shuffled_32_64_64.reset(call_shuffle[int, long, double]( - deref(handle_ptr), - c_major_vertices, - c_minor_vertices, - c_edge_weights, - num_local_edges, - weights is not None).release()) - - shuffled_df = renumber_helper( - ptr_shuffled_32_64_64.get(), vertex_t, weights) + elif( weight_t == np.dtype("float64")): + if(is_multi_gpu): + ptr_shuffled_32_64_64.reset(call_shuffle[int, long, double](deref(handle_ptr), + c_major_vertices, + c_minor_vertices, + c_edge_weights, + num_local_edges, + weights is not None).release()) + + shuffled_df = renumber_helper(ptr_shuffled_32_64_64.get(), vertex_t, weights) major_vertices = shuffled_df['major_vertices'] minor_vertices = shuffled_df['minor_vertices'] num_local_edges = len(shuffled_df) if not transposed: - major = renumbered_src_col_name - minor = renumbered_dst_col_name + major = renumbered_src_col_name; minor = renumbered_dst_col_name else: - major = renumbered_dst_col_name - minor = renumbered_src_col_name - shuffled_df = shuffled_df.rename( - columns={ - 'major_vertices': major, - 'minor_vertices': minor, - }, - copy=False) - edge_counts_64 = move( - ptr_shuffled_32_64_64.get().get_edge_counts_wrap()) + major = renumbered_dst_col_name; minor = renumbered_src_col_name + shuffled_df = shuffled_df.rename(columns={'major_vertices':major, 'minor_vertices':minor}, copy=False) + edge_counts_64 = move(ptr_shuffled_32_64_64.get().get_edge_counts_wrap()) else: shuffled_df = input_df edge_counts_64 = make_unique[vector[long]](1, num_local_edges) @@ -484,37 +417,32 @@ def renumber(input_df, # maybe use cpdef ? shuffled_src = minor_vertices.__cuda_array_interface__['data'][0] shuffled_dst = major_vertices.__cuda_array_interface__['data'][0] - ptr_renum_tuple_32_64.reset(call_renumber[int, long]( - deref(handle_ptr), - shuffled_src, - shuffled_dst, - deref(edge_counts_64.get()), - transposed, - do_check, - mg_flag).release()) + ptr_renum_tuple_32_64.reset(call_renumber[int, long](deref(handle_ptr), + shuffled_src, + shuffled_dst, + deref(edge_counts_64.get()), + transposed, + do_check, + mg_flag).release()) - # original vertices: see helper - pair_original = ptr_renum_tuple_32_64.get().get_dv_wrap() + pair_original = ptr_renum_tuple_32_64.get().get_dv_wrap() # original vertices: see helper original_series = move_device_buffer_to_series( move(pair_original.first), vertex_t, "original") # extract unique_ptr[partition_offsets]: # - uniq_partition_vector_32 = move( - ptr_renum_tuple_32_64.get().get_partition_offsets_wrap()) + uniq_partition_vector_32 = move(ptr_renum_tuple_32_64.get().get_partition_offsets_wrap()) # create series out of a partition range from rank to rank+1: # if is_multi_gpu: - new_series = cudf.Series( - np.arange(uniq_partition_vector_32.get()[0].at(rank_indx), - uniq_partition_vector_32.get()[0].at(rank_indx+1)), - dtype=vertex_t) + new_series = cudf.Series(np.arange(uniq_partition_vector_32.get()[0].at(rank_indx), + uniq_partition_vector_32.get()[0].at(rank_indx+1)), + dtype=vertex_t) else: - new_series = cudf.Series( - np.arange(0, ptr_renum_tuple_32_64.get().get_num_vertices()), - dtype=vertex_t) + new_series = cudf.Series(np.arange(0, ptr_renum_tuple_32_64.get().get_num_vertices()), + dtype=vertex_t) # create new cudf df # # and add the previous series to it: @@ -523,46 +451,34 @@ def renumber(input_df, # maybe use cpdef ? renumbered_map['original_ids'] = original_series renumbered_map['new_ids'] = new_series - uniq_segment_vector_32 = move( - ptr_renum_tuple_32_64.get().get_segment_offsets_wrap()) - segment_offsets = [None] * ( - deref(uniq_segment_vector_32).size()) + uniq_segment_vector_32 = move(ptr_renum_tuple_32_64.get().get_segment_offsets_wrap()) + segment_offsets = [None] * (deref(uniq_segment_vector_32).size()) for i in range(len(segment_offsets)): - segment_offsets[i] = deref(uniq_segment_vector_32)[i] + segment_offsets[i] = deref(uniq_segment_vector_32)[i] return renumbered_map, segment_offsets, shuffled_df - elif vertex_t == np.dtype("int64"): - if edge_t == np.dtype("int64"): - if weight_t == np.dtype("float32"): - if is_multi_gpu: - ptr_shuffled_64_64_32.reset(call_shuffle[long, long, float]( - deref(handle_ptr), - c_major_vertices, - c_minor_vertices, - c_edge_weights, - num_local_edges, - weights is not None).release()) - - shuffled_df = renumber_helper( - ptr_shuffled_64_64_32.get(), vertex_t, weights) + elif (vertex_t == np.dtype("int64")): + if ( edge_t == np.dtype("int64")): + if( weight_t == np.dtype("float32")): + if(is_multi_gpu): + ptr_shuffled_64_64_32.reset(call_shuffle[long, long, float](deref(handle_ptr), + c_major_vertices, + c_minor_vertices, + c_edge_weights, + num_local_edges, + weights is not None).release()) + + shuffled_df = renumber_helper(ptr_shuffled_64_64_32.get(), vertex_t, weights) major_vertices = shuffled_df['major_vertices'] minor_vertices = shuffled_df['minor_vertices'] num_local_edges = len(shuffled_df) if not transposed: - major = renumbered_src_col_name - minor = renumbered_dst_col_name + major = renumbered_src_col_name; minor = renumbered_dst_col_name else: - major = renumbered_dst_col_name - minor = renumbered_src_col_name - shuffled_df = shuffled_df.rename( - columns={ - 'major_vertices': major, - 'minor_vertices': minor, - }, - copy=False) - edge_counts_64 = move( - ptr_shuffled_64_64_32.get().get_edge_counts_wrap()) + major = renumbered_dst_col_name; minor = renumbered_src_col_name + shuffled_df = shuffled_df.rename(columns={'major_vertices':major, 'minor_vertices':minor}, copy=False) + edge_counts_64 = move(ptr_shuffled_64_64_32.get().get_edge_counts_wrap()) else: shuffled_df = input_df edge_counts_64 = make_unique[vector[long]](1, num_local_edges) @@ -574,37 +490,32 @@ def renumber(input_df, # maybe use cpdef ? shuffled_src = minor_vertices.__cuda_array_interface__['data'][0] shuffled_dst = major_vertices.__cuda_array_interface__['data'][0] - ptr_renum_tuple_64_64.reset(call_renumber[long, long]( - deref(handle_ptr), - shuffled_src, - shuffled_dst, - deref(edge_counts_64.get()), - transposed, - do_check, - mg_flag).release()) + ptr_renum_tuple_64_64.reset(call_renumber[long, long](deref(handle_ptr), + shuffled_src, + shuffled_dst, + deref(edge_counts_64.get()), + transposed, + do_check, + mg_flag).release()) - # original vertices: see helper - pair_original = ptr_renum_tuple_64_64.get().get_dv_wrap() + pair_original = ptr_renum_tuple_64_64.get().get_dv_wrap() # original vertices: see helper original_series = move_device_buffer_to_series( move(pair_original.first), vertex_t, "original") # extract unique_ptr[partition_offsets]: # - uniq_partition_vector_64 = move( - ptr_renum_tuple_64_64.get().get_partition_offsets_wrap()) + uniq_partition_vector_64 = move(ptr_renum_tuple_64_64.get().get_partition_offsets_wrap()) # create series out of a partition range from rank to rank+1: # if is_multi_gpu: - new_series = cudf.Series( - np.arange(uniq_partition_vector_64.get()[0].at(rank_indx), - uniq_partition_vector_64.get()[0].at(rank_indx+1)), - dtype=vertex_t) + new_series = cudf.Series(np.arange(uniq_partition_vector_64.get()[0].at(rank_indx), + uniq_partition_vector_64.get()[0].at(rank_indx+1)), + dtype=vertex_t) else: - new_series = cudf.Series( - np.arange(0, ptr_renum_tuple_64_64.get().get_num_vertices()), - dtype=vertex_t) + new_series = cudf.Series(np.arange(0, ptr_renum_tuple_64_64.get().get_num_vertices()), + dtype=vertex_t) # create new cudf df # @@ -614,44 +525,32 @@ def renumber(input_df, # maybe use cpdef ? renumbered_map['original_ids'] = original_series renumbered_map['new_ids'] = new_series - uniq_segment_vector_64 = move( - ptr_renum_tuple_64_64.get().get_segment_offsets_wrap()) - segment_offsets = [None] * ( - deref(uniq_segment_vector_64).size()) + uniq_segment_vector_64 = move(ptr_renum_tuple_64_64.get().get_segment_offsets_wrap()) + segment_offsets = [None] * (deref(uniq_segment_vector_64).size()) for i in range(len(segment_offsets)): - segment_offsets[i] = deref(uniq_segment_vector_64)[i] + segment_offsets[i] = deref(uniq_segment_vector_64)[i] return renumbered_map, segment_offsets, shuffled_df - elif weight_t == np.dtype("float64"): - if is_multi_gpu: - ptr_shuffled_64_64_64.reset(call_shuffle[long, long, double]( - deref(handle_ptr), - c_major_vertices, - c_minor_vertices, - c_edge_weights, - num_local_edges, - weights is not None).release()) - - shuffled_df = renumber_helper( - ptr_shuffled_64_64_64.get(), vertex_t, weights) + elif( weight_t == np.dtype("float64")): + if(is_multi_gpu): + ptr_shuffled_64_64_64.reset(call_shuffle[long, long, double](deref(handle_ptr), + c_major_vertices, + c_minor_vertices, + c_edge_weights, + num_local_edges, + weights is not None).release()) + + shuffled_df = renumber_helper(ptr_shuffled_64_64_64.get(), vertex_t, weights) major_vertices = shuffled_df['major_vertices'] minor_vertices = shuffled_df['minor_vertices'] num_local_edges = len(shuffled_df) if not transposed: - major = renumbered_src_col_name - minor = renumbered_dst_col_name + major = renumbered_src_col_name; minor = renumbered_dst_col_name else: - major = renumbered_dst_col_name - minor = renumbered_src_col_name - shuffled_df = shuffled_df.rename( - columns={ - 'major_vertices': major, - 'minor_vertices': minor, - }, - copy=False) - edge_counts_64 = move( - ptr_shuffled_64_64_64.get().get_edge_counts_wrap()) + major = renumbered_dst_col_name; minor = renumbered_src_col_name + shuffled_df = shuffled_df.rename(columns={'major_vertices':major, 'minor_vertices':minor}, copy=False) + edge_counts_64 = move(ptr_shuffled_64_64_64.get().get_edge_counts_wrap()) else: shuffled_df = input_df edge_counts_64 = make_unique[vector[long]](1, num_local_edges) @@ -663,37 +562,32 @@ def renumber(input_df, # maybe use cpdef ? shuffled_src = minor_vertices.__cuda_array_interface__['data'][0] shuffled_dst = major_vertices.__cuda_array_interface__['data'][0] - ptr_renum_tuple_64_64.reset(call_renumber[long, long]( - deref(handle_ptr), - shuffled_src, - shuffled_dst, - deref(edge_counts_64.get()), - transposed, - do_check, - mg_flag).release()) + ptr_renum_tuple_64_64.reset(call_renumber[long, long](deref(handle_ptr), + shuffled_src, + shuffled_dst, + deref(edge_counts_64.get()), + transposed, + do_check, + mg_flag).release()) - # original vertices: see helper - pair_original = ptr_renum_tuple_64_64.get().get_dv_wrap() + pair_original = ptr_renum_tuple_64_64.get().get_dv_wrap() # original vertices: see helper original_series = move_device_buffer_to_series( move(pair_original.first), vertex_t, "original") # extract unique_ptr[partition_offsets]: # - uniq_partition_vector_64 = move( - ptr_renum_tuple_64_64.get().get_partition_offsets_wrap()) + uniq_partition_vector_64 = move(ptr_renum_tuple_64_64.get().get_partition_offsets_wrap()) # create series out of a partition range from rank to rank+1: # if is_multi_gpu: - new_series = cudf.Series( - np.arange(uniq_partition_vector_64.get()[0].at(rank_indx), - uniq_partition_vector_64.get()[0].at(rank_indx+1)), - dtype=vertex_t) + new_series = cudf.Series(np.arange(uniq_partition_vector_64.get()[0].at(rank_indx), + uniq_partition_vector_64.get()[0].at(rank_indx+1)), + dtype=vertex_t) else: - new_series = cudf.Series( - np.arange(0, ptr_renum_tuple_64_64.get().get_num_vertices()), - dtype=vertex_t) + new_series = cudf.Series(np.arange(0, ptr_renum_tuple_64_64.get().get_num_vertices()), + dtype=vertex_t) # create new cudf df # @@ -703,11 +597,9 @@ def renumber(input_df, # maybe use cpdef ? renumbered_map['original_ids'] = original_series renumbered_map['new_ids'] = new_series - uniq_segment_vector_64 = move( - ptr_renum_tuple_64_64.get().get_segment_offsets_wrap()) - segment_offsets = [None] * ( - deref(uniq_segment_vector_64).size()) + uniq_segment_vector_64 = move(ptr_renum_tuple_64_64.get().get_segment_offsets_wrap()) + segment_offsets = [None] * (deref(uniq_segment_vector_64).size()) for i in range(len(segment_offsets)): - segment_offsets[i] = deref(uniq_segment_vector_64)[i] + segment_offsets[i] = deref(uniq_segment_vector_64)[i] return renumbered_map, segment_offsets, shuffled_df diff --git a/python/cugraph/cugraph/structure/utils.pxd b/python/cugraph/cugraph/structure/utils.pxd index 2089b8ea0f5..687109215bd 100644 --- a/python/cugraph/cugraph/structure/utils.pxd +++ b/python/cugraph/cugraph/structure/utils.pxd @@ -22,10 +22,10 @@ from libcpp.memory cimport unique_ptr cdef extern from "cugraph/legacy/functions.hpp" namespace "cugraph": - cdef unique_ptr[GraphCSR[VT, ET, WT]] coo_to_csr[VT, ET, WT]( - const GraphCOOView[VT, ET, WT] &graph) except + + cdef unique_ptr[GraphCSR[VT,ET,WT]] coo_to_csr[VT,ET,WT]( + const GraphCOOView[VT,ET,WT] &graph) except + cdef void comms_bcast[value_t]( - const handle_t &handle, - value_t *dst, - size_t size) except + + const handle_t &handle, + value_t *dst, + size_t size) except + diff --git a/python/cugraph/cugraph/structure/utils_wrapper.pyx b/python/cugraph/cugraph/structure/utils_wrapper.pyx index ddf7fb2a485..d8b14669789 100644 --- a/python/cugraph/cugraph/structure/utils_wrapper.pyx +++ b/python/cugraph/cugraph/structure/utils_wrapper.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-2021, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -43,10 +43,9 @@ def create_csr_float(source_col, dest_col, weights): if weights is not None: c_weights = weights.__cuda_array_interface__['data'][0] - cdef GraphCOOView[int, int, float] in_graph - in_graph = GraphCOOView[int, int, float]( - c_src, c_dst, c_weights, num_verts, num_edges) - return csr_to_series(move(c_utils.coo_to_csr[int, int, float](in_graph))) + cdef GraphCOOView[int,int,float] in_graph + in_graph = GraphCOOView[int,int,float](c_src, c_dst, c_weights, num_verts, num_edges) + return csr_to_series(move(c_utils.coo_to_csr[int,int,float](in_graph))) def create_csr_double(source_col, dest_col, weights): @@ -60,16 +59,14 @@ def create_csr_double(source_col, dest_col, weights): if weights is not None: c_weights = weights.__cuda_array_interface__['data'][0] - cdef GraphCOOView[int, int, double] in_graph - in_graph = GraphCOOView[int, int, double]( - c_src, c_dst, c_weights, num_verts, num_edges) - return csr_to_series(move(c_utils.coo_to_csr[int, int, double](in_graph))) + cdef GraphCOOView[int,int,double] in_graph + in_graph = GraphCOOView[int,int,double](c_src, c_dst, c_weights, num_verts, num_edges) + return csr_to_series(move(c_utils.coo_to_csr[int,int,double](in_graph))) def coo2csr(source_col, dest_col, weights=None): if len(source_col) != len(dest_col): - raise Exception( - "source_col and dest_col should have the same number of elements") + raise Exception("source_col and dest_col should have the same number of elements") if source_col.dtype != dest_col.dtype: raise Exception("source_col and dest_col should be the same type") @@ -78,11 +75,7 @@ def coo2csr(source_col, dest_col, weights=None): raise Exception("source_col and dest_col must be type np.int32") if len(source_col) == 0: - return ( - cudf.Series(np.zeros(1, dtype=np.int32)), - cudf.Series(np.zeros(1, dtype=np.int32)), - weights, - ) + return cudf.Series(np.zeros(1, dtype=np.int32)), cudf.Series(np.zeros(1, dtype=np.int32)), weights if weight_type(weights) == np.float64: return create_csr_double(source_col, dest_col, weights) diff --git a/python/cugraph/cugraph/tree/minimum_spanning_tree.pxd b/python/cugraph/cugraph/tree/minimum_spanning_tree.pxd index 5cf89f89bd0..32c76ede554 100644 --- a/python/cugraph/cugraph/tree/minimum_spanning_tree.pxd +++ b/python/cugraph/cugraph/tree/minimum_spanning_tree.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2021, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -21,6 +21,5 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": - cdef unique_ptr[GraphCOO[VT, ET, WT]] minimum_spanning_tree[VT, ET, WT]( - const handle_t &handle, - const GraphCSRView[VT, ET, WT] &graph) except + + cdef unique_ptr[GraphCOO[VT,ET,WT]] minimum_spanning_tree[VT,ET,WT](const handle_t &handle, + const GraphCSRView[VT,ET,WT] &graph) except + diff --git a/python/cugraph/cugraph/tree/minimum_spanning_tree_wrapper.pyx b/python/cugraph/cugraph/tree/minimum_spanning_tree_wrapper.pyx index d34aebcc8c5..7e51a07a5c2 100644 --- a/python/cugraph/cugraph/tree/minimum_spanning_tree_wrapper.pyx +++ b/python/cugraph/cugraph/tree/minimum_spanning_tree_wrapper.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-2021, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -28,70 +28,62 @@ import cudf import numpy as np import cupy as cp - def mst_float(num_verts, num_edges, offsets, indices, weights): cdef unique_ptr[handle_t] handle_ptr handle_ptr.reset(new handle_t()) - handle_ = handle_ptr.get() + handle_ = handle_ptr.get(); cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int, int, float] graph_float - graph_float = GraphCSRView[int, int, float]( - c_offsets, c_indices, c_weights, num_verts, num_edges) - return coo_to_df(move(c_mst[int, int, float](handle_[0], graph_float))) + cdef GraphCSRView[int,int,float] graph_float + graph_float = GraphCSRView[int,int,float](c_offsets, c_indices, c_weights, num_verts, num_edges) + return coo_to_df(move(c_mst[int,int,float](handle_[0], graph_float))) def mst_double(num_verts, num_edges, offsets, indices, weights): cdef unique_ptr[handle_t] handle_ptr handle_ptr.reset(new handle_t()) - handle_ = handle_ptr.get() + handle_ = handle_ptr.get(); cdef uintptr_t c_offsets = offsets.__cuda_array_interface__['data'][0] cdef uintptr_t c_indices = indices.__cuda_array_interface__['data'][0] cdef uintptr_t c_weights = weights.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int, int, double] graph_double - graph_double = GraphCSRView[int, int, double]( - c_offsets, c_indices, c_weights, num_verts, num_edges) - return coo_to_df(move(c_mst[int, int, double](handle_[0], graph_double))) + cdef GraphCSRView[int,int,double] graph_double + graph_double = GraphCSRView[int,int,double](c_offsets, c_indices, c_weights, num_verts, num_edges) + return coo_to_df(move(c_mst[int,int,double](handle_[0], graph_double))) def minimum_spanning_tree(input_graph): if not input_graph.adjlist: input_graph.view_adj_list() - [offsets, indices] = graph_primtypes_wrapper.datatype_cast( - [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) if input_graph.adjlist.weights is not None: - [weights] = graph_primtypes_wrapper.datatype_cast( - [input_graph.adjlist.weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) else: weights = cudf.Series(cp.full(num_edges, 1.0, dtype=np.float32)) if graph_primtypes_wrapper.weight_type(input_graph) == np.float32: - df = mst_float(num_verts, num_edges, offsets, indices, weights) - return df + df = mst_float(num_verts, num_edges, offsets, indices, weights) + return df else: return mst_double(num_verts, num_edges, offsets, indices, weights) - def maximum_spanning_tree(input_graph): if not input_graph.adjlist: input_graph.view_adj_list() - [offsets, indices] = graph_primtypes_wrapper.datatype_cast( - [input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) + [offsets, indices] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.offsets, input_graph.adjlist.indices], [np.int32]) num_verts = input_graph.number_of_vertices() num_edges = input_graph.number_of_edges(directed_edges=True) if input_graph.adjlist.weights is not None: - [weights] = graph_primtypes_wrapper.datatype_cast( - [input_graph.adjlist.weights], [np.float32, np.float64]) + [weights] = graph_primtypes_wrapper.datatype_cast([input_graph.adjlist.weights], [np.float32, np.float64]) else: weights = cudf.Series(cp.full(num_edges, 1.0, dtype=np.float32)) if graph_primtypes_wrapper.weight_type(input_graph) == np.float32: - df = mst_float(num_verts, num_edges, offsets, indices, weights) - return df + df = mst_float(num_verts, num_edges, offsets, indices, weights) + return df else: return mst_double(num_verts, num_edges, offsets, indices, weights) diff --git a/python/cugraph/cugraph/utilities/path_retrieval.pxd b/python/cugraph/cugraph/utilities/path_retrieval.pxd index 2396f461518..dcbbef5127d 100644 --- a/python/cugraph/cugraph/utilities/path_retrieval.pxd +++ b/python/cugraph/cugraph/utilities/path_retrieval.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022, NVIDIA CORPORATION. +# Copyright (c) 2021, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -20,11 +20,10 @@ from cugraph.structure.graph_primtypes cimport * cdef extern from "cugraph/utilities/path_retrieval.hpp" namespace "cugraph": - cdef void get_traversed_cost[vertex_t, weight_t]( - const handle_t &handle, - const vertex_t *vertices, - const vertex_t *preds, - const weight_t *info_weights, - weight_t *out, - vertex_t stop_vertex, - vertex_t num_vertices) except + + cdef void get_traversed_cost[vertex_t, weight_t](const handle_t &handle, + const vertex_t *vertices, + const vertex_t *preds, + const weight_t *info_weights, + weight_t *out, + vertex_t stop_vertex, + vertex_t num_vertices) except + diff --git a/python/cugraph/cugraph/utilities/path_retrieval_wrapper.pyx b/python/cugraph/cugraph/utilities/path_retrieval_wrapper.pyx index 062a63e1d0a..98d11ad07df 100644 --- a/python/cugraph/cugraph/utilities/path_retrieval_wrapper.pyx +++ b/python/cugraph/cugraph/utilities/path_retrieval_wrapper.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022, NVIDIA CORPORATION. +# Copyright (c) 2021, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -38,7 +38,7 @@ def get_traversed_cost(input_df, stop_vertex): cdef unique_ptr[handle_t] handle_ptr handle_ptr.reset(new handle_t()) - handle_ = handle_ptr.get() + handle_ = handle_ptr.get(); cdef uintptr_t vertices = NULL cdef uintptr_t preds = NULL @@ -51,8 +51,7 @@ def get_traversed_cost(input_df, stop_vertex): out = df['info'].__cuda_array_interface__['data'][0] if weight_t == np.float32: - c_get_traversed_cost( - handle_[0], + c_get_traversed_cost(handle_[0], vertices, preds, info_weights, @@ -60,8 +59,7 @@ def get_traversed_cost(input_df, stop_vertex): stop_vertex, num_verts) elif weight_t == np.float64: - c_get_traversed_cost( - handle_[0], + c_get_traversed_cost(handle_[0], vertices, preds, info_weights, diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/algorithms.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/algorithms.pxd index 3de813d62f6..be377257d46 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/algorithms.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/algorithms.pxd @@ -135,7 +135,7 @@ cdef extern from "cugraph_c/algorithms.h": cugraph_random_walk_result_get_path_sizes( cugraph_random_walk_result_t* result ) - + cdef size_t \ cugraph_random_walk_result_get_max_path_length( cugraph_random_walk_result_t* result @@ -160,6 +160,7 @@ cdef extern from "cugraph_c/algorithms.h": cugraph_error_t** error ) + ########################################################################### # sampling ctypedef struct cugraph_sample_result_t: @@ -221,7 +222,7 @@ cdef extern from "cugraph_c/algorithms.h": cugraph_random_walk_result_t** result, cugraph_error_t** error ) - + # biased random walks cdef cugraph_error_code_t \ cugraph_based_random_walks( diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/centrality_algorithms.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/centrality_algorithms.pxd index 9981d04e0f8..8e8b1c8e923 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/centrality_algorithms.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/centrality_algorithms.pxd @@ -56,8 +56,8 @@ cdef extern from "cugraph_c/centrality_algorithms.h": cugraph_pagerank( const cugraph_resource_handle_t* handle, cugraph_graph_t* graph, - const cugraph_type_erased_device_array_view_t* precomputed_vertex_out_weight_vertices, # noqa: E501 - const cugraph_type_erased_device_array_view_t* precomputed_vertex_out_weight_sums, # noqa: E501 + const cugraph_type_erased_device_array_view_t* precomputed_vertex_out_weight_vertices, + const cugraph_type_erased_device_array_view_t* precomputed_vertex_out_weight_sums, const cugraph_type_erased_device_array_view_t* initial_guess_vertices, const cugraph_type_erased_device_array_view_t* initial_guess_values, double alpha, @@ -72,8 +72,8 @@ cdef extern from "cugraph_c/centrality_algorithms.h": cugraph_personalized_pagerank( const cugraph_resource_handle_t* handle, cugraph_graph_t* graph, - const cugraph_type_erased_device_array_view_t* precomputed_vertex_out_weight_vertices, # noqa: E501 - const cugraph_type_erased_device_array_view_t* precomputed_vertex_out_weight_sums, # noqa: E501 + const cugraph_type_erased_device_array_view_t* precomputed_vertex_out_weight_vertices, + const cugraph_type_erased_device_array_view_t* precomputed_vertex_out_weight_sums, const cugraph_type_erased_device_array_view_t* initial_guess_vertices, const cugraph_type_erased_device_array_view_t* initial_guess_values, const cugraph_type_erased_device_array_view_t* personalization_vertices, @@ -98,7 +98,7 @@ cdef extern from "cugraph_c/centrality_algorithms.h": cugraph_centrality_result_t** result, cugraph_error_t** error ) - + ########################################################################### # katz centrality cdef cugraph_error_code_t \ @@ -124,17 +124,17 @@ cdef extern from "cugraph_c/centrality_algorithms.h": cugraph_hits_result_get_vertices( cugraph_hits_result_t* result ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_hits_result_get_hubs( cugraph_hits_result_t* result ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_hits_result_get_authorities( cugraph_hits_result_t* result ) - + cdef void \ cugraph_hits_result_free( cugraph_hits_result_t* result diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/community_algorithms.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/community_algorithms.pxd index 4dbfba55fa6..90ae44cbead 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/community_algorithms.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/community_algorithms.pxd @@ -45,17 +45,17 @@ cdef extern from "cugraph_c/community_algorithms.h": cugraph_triangle_count_result_get_vertices( cugraph_triangle_count_result_t* result ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_triangle_count_result_get_counts( cugraph_triangle_count_result_t* result ) - + cdef void \ cugraph_triangle_count_result_free( cugraph_triangle_count_result_t* result ) - + cdef cugraph_error_code_t \ cugraph_triangle_count( const cugraph_resource_handle_t* handle, @@ -80,10 +80,10 @@ cdef extern from "cugraph_c/community_algorithms.h": cugraph_heirarchical_clustering_result_get_clusters( cugraph_heirarchical_clustering_result_t* result ) - + cdef double cugraph_heirarchical_clustering_result_get_modularity( cugraph_heirarchical_clustering_result_t* result - ) + ) cdef void \ cugraph_heirarchical_clustering_result_free( @@ -100,7 +100,7 @@ cdef extern from "cugraph_c/community_algorithms.h": cugraph_heirarchical_clustering_result_t** result, cugraph_error_t** error ) - + # extract_ego cdef cugraph_error_code_t \ cugraph_extract_ego( diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/core_algorithms.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/core_algorithms.pxd index 8d5d7c346cd..4d3509e8b7f 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/core_algorithms.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/core_algorithms.pxd @@ -36,7 +36,7 @@ cdef extern from "cugraph_c/core_algorithms.h": # core number ctypedef struct cugraph_core_result_t: pass - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_core_result_get_vertices( cugraph_core_result_t* result @@ -46,7 +46,7 @@ cdef extern from "cugraph_c/core_algorithms.h": cugraph_core_result_get_core_numbers( cugraph_core_result_t* result ) - + cdef void \ cugraph_core_result_free( cugraph_core_result_t* result @@ -66,7 +66,7 @@ cdef extern from "cugraph_c/core_algorithms.h": cugraph_core_result_t** result, cugraph_error_t** error ) - + ########################################################################### # k-core ctypedef struct cugraph_k_core_result_t: @@ -76,22 +76,22 @@ cdef extern from "cugraph_c/core_algorithms.h": cugraph_k_core_result_get_src_vertices( cugraph_k_core_result_t* result ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_k_core_result_get_dst_vertices( cugraph_k_core_result_t* result ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_k_core_result_get_weights( cugraph_k_core_result_t* result ) - + cdef void \ cugraph_k_core_result_free( cugraph_k_core_result_t* result ) - + cdef cugraph_error_code_t \ cugraph_core_result_create( const cugraph_resource_handle_t* handle, @@ -100,7 +100,7 @@ cdef extern from "cugraph_c/core_algorithms.h": cugraph_core_result_t** core_result, cugraph_error_t** error ) - + cdef cugraph_error_code_t \ cugraph_k_core( const cugraph_resource_handle_t* handle, diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/error.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/error.pxd index 7dee4a5eb74..4b20daa1135 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/error.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/error.pxd @@ -26,7 +26,7 @@ cdef extern from "cugraph_c/error.h": CUGRAPH_UNSUPPORTED_TYPE_COMBINATION ctypedef struct cugraph_error_t: - pass + pass const char* \ cugraph_error_message( diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/graph.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/graph.pxd index 39ec4e766da..590c5679264 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/graph.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/graph.pxd @@ -38,20 +38,19 @@ cdef extern from "cugraph_c/graph.h": bool_t is_multigraph cdef cugraph_error_code_t \ - cugraph_sg_graph_create( - const cugraph_resource_handle_t* handle, - const cugraph_graph_properties_t* properties, - const cugraph_type_erased_device_array_view_t* src, - const cugraph_type_erased_device_array_view_t* dst, - const cugraph_type_erased_device_array_view_t* weights, - const cugraph_type_erased_device_array_view_t* edge_ids, - const cugraph_type_erased_device_array_view_t* edge_types, - bool_t store_transposed, - bool_t renumber, - bool_t check, - cugraph_graph_t** graph, - cugraph_error_t** error - ) + cugraph_sg_graph_create( + const cugraph_resource_handle_t* handle, + const cugraph_graph_properties_t* properties, + const cugraph_type_erased_device_array_view_t* src, + const cugraph_type_erased_device_array_view_t* dst, + const cugraph_type_erased_device_array_view_t* weights, + const cugraph_type_erased_device_array_view_t* edge_ids, + const cugraph_type_erased_device_array_view_t* edge_types, + bool_t store_transposed, + bool_t renumber, + bool_t check, + cugraph_graph_t** graph, + cugraph_error_t** error) # This may get renamed to cugraph_graph_free() cdef void \ @@ -80,7 +79,7 @@ cdef extern from "cugraph_c/graph.h": cugraph_mg_graph_free( cugraph_graph_t* graph ) - + cdef cugraph_error_code_t \ cugraph_sg_graph_create_from_csr( const cugraph_resource_handle_t* handle, @@ -96,12 +95,12 @@ cdef extern from "cugraph_c/graph.h": cugraph_graph_t** graph, cugraph_error_t** error ) - + cdef void \ cugraph_sg_graph_free( cugraph_graph_t* graph ) - + cdef cugraph_error_code_t \ cugraph_mg_graph_create( const cugraph_resource_handle_t* handle, @@ -117,7 +116,7 @@ cdef extern from "cugraph_c/graph.h": cugraph_graph_t** graph, cugraph_error_t** error ) - + cdef void \ cugraph_mg_graph_free( cugraph_graph_t* graph diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/graph_functions.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/graph_functions.pxd index eab1e5cf09d..f18e9848182 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/graph_functions.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/graph_functions.pxd @@ -36,13 +36,13 @@ from pylibcugraph._cugraph_c.array cimport ( ) cdef extern from "cugraph_c/graph_functions.h": - # """ - # ctypedef struct cugraph_similarity_result_t: - # pass - # """ + #""" + #ctypedef struct cugraph_similarity_result_t: + # pass + #""" ctypedef struct cugraph_vertex_pairs_t: pass - + from pylibcugraph._cugraph_c.error cimport ( cugraph_error_code_t, @@ -61,22 +61,22 @@ cdef extern from "cugraph_c/graph_functions.h": # vertex_pairs ctypedef struct cugraph_vertex_pairs_t: pass - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_vertex_pairs_get_first( cugraph_vertex_pairs_t* vertex_pairs ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_vertex_pairs_get_second( cugraph_vertex_pairs_t* vertex_pairs ) - + cdef void \ cugraph_vertex_pairs_free( cugraph_vertex_pairs_t* vertex_pairs ) - + cdef cugraph_error_code_t \ cugraph_create_vertex_pairs( const cugraph_resource_handle_t* handle, @@ -86,21 +86,21 @@ cdef extern from "cugraph_c/graph_functions.h": cugraph_vertex_pairs_t** vertex_pairs, cugraph_error_t** error ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_vertex_pairs_get_first( cugraph_vertex_pairs_t* vertex_pairs ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_vertex_pairs_get_second( cugraph_vertex_pairs_t* vertex_pairs ) - + cdef void cugraph_vertex_pairs_free( cugraph_vertex_pairs_t* vertex_pairs - ) - + ) + cdef cugraph_error_code_t cugraph_two_hop_neighbors( const cugraph_resource_handle_t* handle, const cugraph_graph_t* graph, @@ -117,7 +117,7 @@ cdef extern from "cugraph_c/graph_functions.h": cugraph_vertex_pairs_t** result, cugraph_error_t** error ) - + ########################################################################### # induced_subgraph ctypedef struct cugraph_induced_subgraph_result_t: @@ -127,27 +127,27 @@ cdef extern from "cugraph_c/graph_functions.h": cugraph_induced_subgraph_get_sources( cugraph_induced_subgraph_result_t* induced_subgraph ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_induced_subgraph_get_destinations( cugraph_induced_subgraph_result_t* induced_subgraph ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_induced_subgraph_get_edge_weights( cugraph_induced_subgraph_result_t* induced_subgraph ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_induced_subgraph_get_subgraph_offsets( cugraph_induced_subgraph_result_t* induced_subgraph ) - + cdef void \ cugraph_induced_subgraph_result_free( cugraph_induced_subgraph_result_t* induced_subgraph ) - + cdef cugraph_error_code_t \ cugraph_extract_induced_subgraph( const cugraph_resource_handle_t* handle, diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/labeling_algorithms.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/labeling_algorithms.pxd index e1072d4c24c..7c911235a54 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/labeling_algorithms.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/labeling_algorithms.pxd @@ -41,17 +41,17 @@ cdef extern from "cugraph_c/labeling_algorithms.h": cugraph_labeling_result_get_vertices( cugraph_labeling_result_t* result ) - + cdef cugraph_type_erased_device_array_view_t* \ cugraph_labeling_result_get_labels( cugraph_labeling_result_t* result ) - + cdef void \ cugraph_labeling_result_free( cugraph_labeling_result_t* result ) - + cdef cugraph_error_code_t \ cugraph_weakly_connected_components( const cugraph_resource_handle_t* handle, @@ -60,3 +60,4 @@ cdef extern from "cugraph_c/labeling_algorithms.h": cugraph_labeling_result_t** result, cugraph_error_t** error ) + \ No newline at end of file diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/resource_handle.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/resource_handle.pxd index df688a08760..633107a1acb 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/resource_handle.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/resource_handle.pxd @@ -36,14 +36,17 @@ cdef extern from "cugraph_c/resource_handle.h": pass # FIXME: the void* raft_handle arg will change in a future release - cdef cugraph_resource_handle_t* cugraph_create_resource_handle( - void* raft_handle - ) - - cdef int cugraph_resource_handle_get_rank( - const cugraph_resource_handle_t* handle - ) - - cdef void cugraph_free_resource_handle( - cugraph_resource_handle_t* p_handle - ) + cdef cugraph_resource_handle_t* \ + cugraph_create_resource_handle( + void* raft_handle + ) + + cdef int \ + cugraph_resource_handle_get_rank( + const cugraph_resource_handle_t* handle + ) + + cdef void \ + cugraph_free_resource_handle( + cugraph_resource_handle_t* p_handle + ) diff --git a/python/pylibcugraph/pylibcugraph/_cugraph_c/similarity_algorithms.pxd b/python/pylibcugraph/pylibcugraph/_cugraph_c/similarity_algorithms.pxd index 6f20096a428..0d98bb8e14a 100644 --- a/python/pylibcugraph/pylibcugraph/_cugraph_c/similarity_algorithms.pxd +++ b/python/pylibcugraph/pylibcugraph/_cugraph_c/similarity_algorithms.pxd @@ -36,21 +36,21 @@ from pylibcugraph._cugraph_c.graph_functions cimport ( cdef extern from "cugraph_c/similarity_algorithms.h": ########################################################################### - # """ + #""" ctypedef struct cugraph_similarity_result_t: pass - # """ + #""" cdef cugraph_type_erased_device_array_view_t* \ cugraph_similarity_result_get_similarity( cugraph_similarity_result_t* result ) - + cdef void \ cugraph_similarity_result_free( cugraph_similarity_result_t* result ) - + ########################################################################### # jaccard coefficients cdef cugraph_error_code_t \ diff --git a/python/pylibcugraph/pylibcugraph/bfs.pyx b/python/pylibcugraph/pylibcugraph/bfs.pyx index 0eb3da99918..6886e6b059a 100644 --- a/python/pylibcugraph/pylibcugraph/bfs.pyx +++ b/python/pylibcugraph/pylibcugraph/bfs.pyx @@ -56,9 +56,8 @@ from pylibcugraph.graphs cimport ( _GPUGraph, ) - -def bfs(ResourceHandle handle, _GPUGraph graph, - sources, bool_t direction_optimizing, int32_t depth_limit, +def bfs(ResourceHandle handle, _GPUGraph graph, + sources, bool_t direction_optimizing, int32_t depth_limit, bool_t compute_predecessors, bool_t do_expensive_check): """ Performs a Breadth-first search starting from the provided sources. @@ -109,10 +108,10 @@ def bfs(ResourceHandle handle, _GPUGraph graph, weights = G.edgelist.edgelist_df['weights'] sg = SGGraph( - resource_handle = handle, - graph_properties = GraphProperties(is_multigraph=G.is_multigraph()), - src_array = srcs, - dst_array = dsts, + resource_handle = handle, + graph_properties = GraphProperties(is_multigraph=G.is_multigraph()), + src_array = srcs, + dst_array = dsts, weight_array = weights, store_transposed=False, renumber=False, @@ -120,7 +119,7 @@ def bfs(ResourceHandle handle, _GPUGraph graph, ) res = pylibcugraph_bfs( - handle, + handle, sg, cudf.Series([0], dtype='int32'), False, @@ -130,7 +129,7 @@ def bfs(ResourceHandle handle, _GPUGraph graph, ) distances, predecessors, vertices = res - + final_results = cudf.DataFrame({ 'distance': cudf.Series(distances), 'vertex': cudf.Series(vertices), @@ -164,7 +163,7 @@ def bfs(ResourceHandle handle, _GPUGraph graph, cai_sources_ptr, len(sources), get_c_type_from_numpy_type(sources.dtype)) - + cdef cugraph_paths_result_t* result_ptr error_code = cugraph_bfs( @@ -186,7 +185,7 @@ def bfs(ResourceHandle handle, _GPUGraph graph, cdef cugraph_type_erased_device_array_view_t* predecessors_ptr = \ cugraph_paths_result_get_predecessors(result_ptr) - + cdef cugraph_type_erased_device_array_view_t* vertices_ptr = \ cugraph_paths_result_get_vertices(result_ptr) @@ -194,7 +193,7 @@ def bfs(ResourceHandle handle, _GPUGraph graph, cupy_distances = copy_to_cupy_array(c_resource_handle_ptr, distances_ptr) cupy_predecessors = copy_to_cupy_array(c_resource_handle_ptr, predecessors_ptr) cupy_vertices = copy_to_cupy_array(c_resource_handle_ptr, vertices_ptr) - + # deallocate the no-longer needed result struct cugraph_paths_result_free(result_ptr) diff --git a/python/pylibcugraph/pylibcugraph/components/_connectivity.pxd b/python/pylibcugraph/pylibcugraph/components/_connectivity.pxd index ff9fb17e12c..b1915ee108b 100644 --- a/python/pylibcugraph/pylibcugraph/components/_connectivity.pxd +++ b/python/pylibcugraph/pylibcugraph/components/_connectivity.pxd @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2021, NVIDIA CORPORATION. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -27,8 +27,8 @@ cdef extern from "cugraph/algorithms.hpp" namespace "cugraph": CUGRAPH_STRONG "cugraph::cugraph_cc_t::CUGRAPH_STRONG" NUM_CONNECTIVITY_TYPES "cugraph::cugraph_cc_t::NUM_CONNECTIVITY_TYPES" - cdef void connected_components[VT, ET, WT]( - const GraphCSRView[VT, ET, WT] &graph, + cdef void connected_components[VT,ET,WT]( + const GraphCSRView[VT,ET,WT] &graph, cugraph_cc_t connect_type, VT *labels) except + @@ -37,3 +37,4 @@ cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": const handle_t &handle, const graph_container_t &g, vertex_t *identifiers) except + + diff --git a/python/pylibcugraph/pylibcugraph/components/_connectivity.pyx b/python/pylibcugraph/pylibcugraph/components/_connectivity.pyx index c3d63a1b4d9..02e7549d1c5 100644 --- a/python/pylibcugraph/pylibcugraph/components/_connectivity.pyx +++ b/python/pylibcugraph/pylibcugraph/components/_connectivity.pyx @@ -39,9 +39,7 @@ def _ensure_arg_types(**kwargs): raise TypeError(f"{arg_name} array must have a dtype of int32") -def strongly_connected_components( - offsets, indices, weights, num_verts, num_edges, labels -): +def strongly_connected_components(offsets, indices, weights, num_verts, num_edges, labels): """ Generate the Strongly Connected Components and attach a component label to each vertex. @@ -124,10 +122,10 @@ def strongly_connected_components( cdef uintptr_t c_edge_weights = NULL cdef uintptr_t c_labels = labels.__cuda_array_interface__['data'][0] - cdef GraphCSRView[int, int, float] g + cdef GraphCSRView[int,int,float] g - g = GraphCSRView[int, int, float]( - c_offsets, c_indices, NULL, num_verts, num_edges) + g = GraphCSRView[int,int,float](c_offsets, c_indices, NULL, num_verts, num_edges) cdef cugraph_cc_t connect_type=CUGRAPH_STRONG connected_components(g, connect_type, c_labels) + diff --git a/python/pylibcugraph/pylibcugraph/core_number.pyx b/python/pylibcugraph/pylibcugraph/core_number.pyx index ccc49a35850..7d0c42f7dd0 100644 --- a/python/pylibcugraph/pylibcugraph/core_number.pyx +++ b/python/pylibcugraph/pylibcugraph/core_number.pyx @@ -31,7 +31,7 @@ from pylibcugraph._cugraph_c.array cimport ( from pylibcugraph._cugraph_c.graph cimport ( cugraph_graph_t, ) -from pylibcugraph._cugraph_c.core_algorithms cimport ( +from pylibcugraph._cugraph_c.core_algorithms cimport ( cugraph_core_result_t, cugraph_core_number, cugraph_k_core_degree_type_t, @@ -51,7 +51,6 @@ from pylibcugraph.utils cimport ( get_c_type_from_numpy_type, ) - def core_number(ResourceHandle resource_handle, _GPUGraph graph, degree_type, @@ -64,17 +63,17 @@ def core_number(ResourceHandle resource_handle, resource_handle: ResourceHandle Handle to the underlying device and host resource needed for referencing data and running algorithms. - + graph : SGGraph or MGGraph The input graph, for either Single or Multi-GPU operations. - + degree_type: str This option determines if the core number computation should be based on input, output, or both directed edges, with valid values being "incoming", "outgoing", and "bidirectional" respectively. This option is currently ignored in this release, and setting it will result in a warning. - + do_expensive_check: bool If True, performs more extensive tests on the inputs to ensure validity, at the expense of increased run time. diff --git a/python/pylibcugraph/pylibcugraph/egonet.pyx b/python/pylibcugraph/pylibcugraph/egonet.pyx index 862e22f103c..639e4c386a7 100644 --- a/python/pylibcugraph/pylibcugraph/egonet.pyx +++ b/python/pylibcugraph/pylibcugraph/egonet.pyx @@ -73,7 +73,7 @@ def ego_graph(ResourceHandle resource_handle, graph : SGGraph or MGGraph The input graph. - + source_vertices : cudf.Series The centered nodes from which the induced subgraph will be extracted @@ -124,8 +124,10 @@ def ego_graph(ResourceHandle resource_handle, cdef cugraph_error_code_t error_code cdef cugraph_error_t* error_ptr - cdef cugraph_type_erased_device_array_view_t* source_vertices_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj(source_vertices) + cdef cugraph_type_erased_device_array_view_t* \ + source_vertices_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj( + source_vertices) error_code = cugraph_extract_ego(c_resource_handle_ptr, c_graph_ptr, @@ -162,4 +164,4 @@ def ego_graph(ResourceHandle resource_handle, cugraph_induced_subgraph_result_free(result_ptr) return (cupy_sources, cupy_destinations, - cupy_edge_weights, cupy_subgraph_offsets) + cupy_edge_weights, cupy_subgraph_offsets) diff --git a/python/pylibcugraph/pylibcugraph/eigenvector_centrality.pyx b/python/pylibcugraph/pylibcugraph/eigenvector_centrality.pyx index 20014e80546..88612c242e2 100644 --- a/python/pylibcugraph/pylibcugraph/eigenvector_centrality.pyx +++ b/python/pylibcugraph/pylibcugraph/eigenvector_centrality.pyx @@ -127,7 +127,7 @@ def eigenvector_centrality(ResourceHandle resource_handle, cugraph_centrality_result_get_vertices(result_ptr) cdef cugraph_type_erased_device_array_view_t* values_ptr = \ cugraph_centrality_result_get_values(result_ptr) - + cupy_vertices = copy_to_cupy_array(c_resource_handle_ptr, vertices_ptr) cupy_values = copy_to_cupy_array(c_resource_handle_ptr, values_ptr) diff --git a/python/pylibcugraph/pylibcugraph/graph_properties.pxd b/python/pylibcugraph/pylibcugraph/graph_properties.pxd index 628da39846a..491c343480d 100644 --- a/python/pylibcugraph/pylibcugraph/graph_properties.pxd +++ b/python/pylibcugraph/pylibcugraph/graph_properties.pxd @@ -14,7 +14,9 @@ # Have cython use python 3 syntax # cython: language_level = 3 -from pylibcugraph._cugraph_c.graph cimport cugraph_graph_properties_t +from pylibcugraph._cugraph_c.graph cimport ( + cugraph_graph_properties_t, +) cdef class GraphProperties: diff --git a/python/pylibcugraph/pylibcugraph/graph_properties.pyx b/python/pylibcugraph/pylibcugraph/graph_properties.pyx index c0f3565045e..ad1431900f6 100644 --- a/python/pylibcugraph/pylibcugraph/graph_properties.pyx +++ b/python/pylibcugraph/pylibcugraph/graph_properties.pyx @@ -26,7 +26,7 @@ cdef class GraphProperties: def __getnewargs_ex__(self): is_symmetric = self.c_graph_properties.is_symmetric is_multigraph = self.c_graph_properties.is_multigraph - return ((), {"is_symmetric": is_symmetric, "is_multigraph": is_multigraph}) + return ((),{"is_symmetric":is_symmetric, "is_multigraph":is_multigraph}) def __getstate__(self): return () diff --git a/python/pylibcugraph/pylibcugraph/graphs.pxd b/python/pylibcugraph/pylibcugraph/graphs.pxd index 62a3ef999a6..e468738f529 100644 --- a/python/pylibcugraph/pylibcugraph/graphs.pxd +++ b/python/pylibcugraph/pylibcugraph/graphs.pxd @@ -28,4 +28,5 @@ cdef class SGGraph(_GPUGraph): pass cdef class MGGraph(_GPUGraph): - pass + pass + diff --git a/python/pylibcugraph/pylibcugraph/graphs.pyx b/python/pylibcugraph/pylibcugraph/graphs.pyx index 70a0c3954a0..7640f5cdee5 100644 --- a/python/pylibcugraph/pylibcugraph/graphs.pyx +++ b/python/pylibcugraph/pylibcugraph/graphs.pyx @@ -74,7 +74,7 @@ cdef class SGGraph(_GPUGraph): Object defining intended properties for the graph. src_or_offset_array : device array type - Device array containing either the vertex identifiers of the source of + Device array containing either the vertex identifiers of the source of each directed edge if represented in COO format or the offset if CSR format. In the case of a COO, the order of the array corresponds to the ordering of the dst_or_index_array, where the ith item in @@ -106,22 +106,22 @@ cdef class SGGraph(_GPUGraph): do_expensive_check : bool If True, performs more extensive tests on the inputs to ensure validitity, at the expense of increased run time. - + edge_id_array : device array type Device array containing the edge ids of each directed edge. Must match the ordering of the src/dst arrays. Optional (may be null). If provided, edge_type_array must also be provided. - + edge_type_array : device array type Device array containing the edge types of each directed edge. Must match the ordering of the src/dst/edge_id arrays. Optional (may be null). If provided, edge_id_array must be provided. - + input_array_format: str, optional (default='COO') Input representation used to construct a graph COO: arrays represent src_array and dst_array CSR: arrays represent offset_array and index_array - + Examples --------- >>> import pylibcugraph, cupy, numpy @@ -168,8 +168,7 @@ cdef class SGGraph(_GPUGraph): if edge_type_array is not None: assert_CAI_type(edge_type_array, "edge_type_array") - # FIXME: assert that src_or_offset_array and dst_or_index_array have - # the same type + # FIXME: assert that src_or_offset_array and dst_or_index_array have the same type cdef cugraph_error_t* error_ptr cdef cugraph_error_code_t error_code @@ -211,7 +210,7 @@ cdef class SGGraph(_GPUGraph): &error_ptr) assert_success(error_code, error_ptr, - "cugraph_sg_graph_create()") + "cugraph_sg_graph_create()") elif input_array_format == "CSR": error_code = cugraph_sg_graph_create_from_csr( @@ -229,12 +228,11 @@ cdef class SGGraph(_GPUGraph): &error_ptr) assert_success(error_code, error_ptr, - "cugraph_sg_graph_create_from_csr()") - + "cugraph_sg_graph_create_from_csr()") + else: - raise ValueError( - "invalid 'input_array_format'. Only 'COO' and 'CSR' format " - "are supported." + raise ValueError("invalid 'input_array_format'. Only " + "'COO' and 'CSR' format are supported." ) cugraph_type_erased_device_array_view_free(srcs_or_offsets_view_ptr) @@ -285,10 +283,10 @@ cdef class MGGraph(_GPUGraph): store_transposed : bool Set to True if the graph should be transposed. This is required for some algorithms, such as pagerank. - + num_edges : int Number of edges - + do_expensive_check : bool If True, performs more extensive tests on the inputs to ensure validitity, at the expense of increased run time. @@ -297,7 +295,7 @@ cdef class MGGraph(_GPUGraph): Device array containing the edge ids of each directed edge. Must match the ordering of the src/dst arrays. Optional (may be null). If provided, edge_type_array must also be provided. - + edge_type_array : device array type Device array containing the edge types of each directed edge. Must match the ordering of the src/dst/edge_id arrays. Optional (may be @@ -333,7 +331,7 @@ cdef class MGGraph(_GPUGraph): if edge_id_array is not None: assert_CAI_type(edge_id_array, "edge_id_array") if edge_type_array is not None: - assert_CAI_type(edge_type_array, "edge_type_array") + assert_CAI_type(edge_type_array, "edge_type_array") # FIXME: assert that src_array and dst_array have the same type diff --git a/python/pylibcugraph/pylibcugraph/hits.pyx b/python/pylibcugraph/pylibcugraph/hits.pyx index 0615a1cf77c..7c472f54866 100644 --- a/python/pylibcugraph/pylibcugraph/hits.pyx +++ b/python/pylibcugraph/pylibcugraph/hits.pyx @@ -55,16 +55,14 @@ from pylibcugraph.utils cimport ( ) -def hits( - ResourceHandle resource_handle, - _GPUGraph graph, - double tol, - size_t max_iter, - initial_hubs_guess_vertices, - initial_hubs_guess_values, - bool_t normalized, - bool_t do_expensive_check -): +def hits(ResourceHandle resource_handle, + _GPUGraph graph, + double tol, + size_t max_iter, + initial_hubs_guess_vertices, + initial_hubs_guess_values, + bool_t normalized, + bool_t do_expensive_check): """ Compute HITS hubs and authorities values for each vertex @@ -80,7 +78,7 @@ def hits( graph : SGGraph or MGGraph The input graph, for either Single or Multi-GPU operations. - + tol : float, optional (default=1.0e-5) Set the tolerance the approximation, this parameter should be a small magnitude value. This parameter is not currently supported. @@ -106,7 +104,7 @@ def hits( A tuple of device arrays, where the third item in the tuple is a device array containing the vertex identifiers, the first and second items are device arrays containing respectively the hubs and authorities values for the corresponding - vertices + vertices Examples -------- @@ -117,32 +115,30 @@ def hits( cdef uintptr_t cai_initial_hubs_guess_vertices_ptr = NULL cdef uintptr_t cai_initial_hubs_guess_values_ptr = NULL - cdef cugraph_type_erased_device_array_view_t* \ - initial_hubs_guess_vertices_view_ptr = NULL - cdef cugraph_type_erased_device_array_view_t* \ - initial_hubs_guess_values_view_ptr = NULL + cdef cugraph_type_erased_device_array_view_t* initial_hubs_guess_vertices_view_ptr = NULL + cdef cugraph_type_erased_device_array_view_t* initial_hubs_guess_values_view_ptr = NULL - # FIXME: Add check ensuring that both initial_hubs_guess_vertices + # FIXME: Add check ensuring that both initial_hubs_guess_vertices # and initial_hubs_guess_values are passed when calling only pylibcugraph HITS. # This is already True for cugraph HITS - - if initial_hubs_guess_vertices is not None: + + if initial_hubs_guess_vertices is not None: assert_CAI_type(initial_hubs_guess_vertices, "initial_hubs_guess_vertices") - + cai_initial_hubs_guess_vertices_ptr = \ - initial_hubs_guess_vertices.__cuda_array_interface__["data"][0] + initial_hubs_guess_vertices.__cuda_array_interface__["data"][0] initial_hubs_guess_vertices_view_ptr = \ cugraph_type_erased_device_array_view_create( cai_initial_hubs_guess_vertices_ptr, len(initial_hubs_guess_vertices), get_c_type_from_numpy_type(initial_hubs_guess_vertices.dtype)) - + if initial_hubs_guess_values is not None: assert_CAI_type(initial_hubs_guess_values, "initial_hubs_guess_values") cai_initial_hubs_guess_values_ptr = \ - initial_hubs_guess_values.__cuda_array_interface__["data"][0] + initial_hubs_guess_values.__cuda_array_interface__["data"][0] initial_hubs_guess_values_view_ptr = \ cugraph_type_erased_device_array_view_create( @@ -183,13 +179,13 @@ def hits( cupy_hubs = copy_to_cupy_array(c_resource_handle_ptr, hubs_ptr) cupy_authorities = copy_to_cupy_array(c_resource_handle_ptr, authorities_ptr) - + cugraph_hits_result_free(result_ptr) if initial_hubs_guess_vertices is not None: cugraph_type_erased_device_array_view_free( initial_hubs_guess_vertices_view_ptr) - + if initial_hubs_guess_values is not None: cugraph_type_erased_device_array_view_free( initial_hubs_guess_values_view_ptr) diff --git a/python/pylibcugraph/pylibcugraph/jaccard_coefficients.pyx b/python/pylibcugraph/pylibcugraph/jaccard_coefficients.pyx index ee0e2da4f28..805ee821eab 100644 --- a/python/pylibcugraph/pylibcugraph/jaccard_coefficients.pyx +++ b/python/pylibcugraph/pylibcugraph/jaccard_coefficients.pyx @@ -57,17 +57,15 @@ from pylibcugraph.utils cimport ( ) -def EXPERIMENTAL__jaccard_coefficients( - ResourceHandle resource_handle, - _GPUGraph graph, - first, - second, - bool_t use_weight, - bool_t do_expensive_check -): +def EXPERIMENTAL__jaccard_coefficients(ResourceHandle resource_handle, + _GPUGraph graph, + first, + second, + bool_t use_weight, + bool_t do_expensive_check): """ Compute the Jaccard coefficients for the specified vertex_pairs. - + Note that Jaccard similarity must run on a symmetric graph. Parameters @@ -78,13 +76,13 @@ def EXPERIMENTAL__jaccard_coefficients( graph : SGGraph or MGGraph The input graph, for either Single or Multi-GPU operations. - + first : Source of the vertex pair. - + second : Destination of the vertex pair. - + use_weight : bool, optional (default=False) Currently not supported @@ -114,12 +112,16 @@ def EXPERIMENTAL__jaccard_coefficients( cdef cugraph_error_t* error_ptr # 'first' is a required parameter - cdef cugraph_type_erased_device_array_view_t* first_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj(first) + cdef cugraph_type_erased_device_array_view_t* \ + first_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj( + first) # 'second' is a required parameter - cdef cugraph_type_erased_device_array_view_t* second_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj(second) + cdef cugraph_type_erased_device_array_view_t* \ + second_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj( + second) error_code = cugraph_create_vertex_pairs(c_resource_handle_ptr, c_graph_ptr, diff --git a/python/pylibcugraph/pylibcugraph/k_core.pyx b/python/pylibcugraph/pylibcugraph/k_core.pyx index 010a9270b5b..50344469b11 100644 --- a/python/pylibcugraph/pylibcugraph/k_core.pyx +++ b/python/pylibcugraph/pylibcugraph/k_core.pyx @@ -31,7 +31,7 @@ from pylibcugraph._cugraph_c.array cimport ( from pylibcugraph._cugraph_c.graph cimport ( cugraph_graph_t, ) -from pylibcugraph._cugraph_c.core_algorithms cimport ( +from pylibcugraph._cugraph_c.core_algorithms cimport ( cugraph_core_result_t, cugraph_k_core_result_t, cugraph_core_result_create, @@ -55,7 +55,6 @@ from pylibcugraph.utils cimport ( create_cugraph_type_erased_device_array_view_from_py_obj, ) - def k_core(ResourceHandle resource_handle, _GPUGraph graph, size_t k, @@ -73,21 +72,21 @@ def k_core(ResourceHandle resource_handle, resource_handle: ResourceHandle Handle to the underlying device and host resource needed for referencing data and running algorithms. - + graph : SGGraph or MGGraph The input graph, for either Single or Multi-GPU operations. - + k : size_t (default=None) Order of the core. This value must not be negative. If set to None the main core is returned. - + degree_type: str This option determines if the core number computation should be based on input, output, or both directed edges, with valid values being "incoming", "outgoing", and "bidirectional" respectively. This option is currently ignored in this release, and setting it will result in a warning. - + core_result : device array type Precomputed core number of the nodes of the graph G If set to None, the core numbers of the nodes are calculated @@ -116,17 +115,22 @@ def k_core(ResourceHandle resource_handle, cdef cugraph_error_code_t error_code cdef cugraph_error_t* error_ptr + degree_type_map = { "incoming": cugraph_k_core_degree_type_t.K_CORE_DEGREE_TYPE_IN, "outgoing": cugraph_k_core_degree_type_t.K_CORE_DEGREE_TYPE_OUT, "bidirectional": cugraph_k_core_degree_type_t.K_CORE_DEGREE_TYPE_INOUT} - cdef cugraph_type_erased_device_array_view_t* vertices_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj(core_result["vertex"]) - - cdef cugraph_type_erased_device_array_view_t* core_numbers_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj(core_result["values"]) - + cdef cugraph_type_erased_device_array_view_t* \ + vertices_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj( + core_result["vertex"]) + + cdef cugraph_type_erased_device_array_view_t* \ + core_numbers_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj( + core_result["values"]) + # Create a core_number result error_code = cugraph_core_result_create(c_resource_handle_ptr, vertices_view_ptr, @@ -135,6 +139,7 @@ def k_core(ResourceHandle resource_handle, &error_ptr) assert_success(error_code, error_ptr, "cugraph_core_result_create") + # compute k_core error_code = cugraph_k_core(c_resource_handle_ptr, c_graph_ptr, @@ -146,6 +151,7 @@ def k_core(ResourceHandle resource_handle, &error_ptr) assert_success(error_code, error_ptr, "cugraph_k_core_number") + cdef cugraph_type_erased_device_array_view_t* src_vertices_ptr = \ cugraph_k_core_result_get_src_vertices(k_core_result_ptr) cdef cugraph_type_erased_device_array_view_t* dst_vertices_ptr = \ diff --git a/python/pylibcugraph/pylibcugraph/katz_centrality.pyx b/python/pylibcugraph/pylibcugraph/katz_centrality.pyx index 8652f651d0a..0f08e690f92 100644 --- a/python/pylibcugraph/pylibcugraph/katz_centrality.pyx +++ b/python/pylibcugraph/pylibcugraph/katz_centrality.pyx @@ -97,7 +97,7 @@ def katz_centrality(ResourceHandle resource_handle, do_expensive_check : bool_t A flag to run expensive checks for input arguments if True. - + Returns ------- @@ -114,9 +114,9 @@ def katz_centrality(ResourceHandle resource_handle, cdef cugraph_error_code_t error_code cdef cugraph_error_t* error_ptr - cdef uintptr_t cai_betas_ptr + cdef uintptr_t cai_betas_ptr cdef cugraph_type_erased_device_array_view_t* betas_ptr - + if betas is not None: cai_betas_ptr = betas.__cuda_array_interface__["data"][0] betas_ptr = \ @@ -145,7 +145,7 @@ def katz_centrality(ResourceHandle resource_handle, cugraph_centrality_result_get_vertices(result_ptr) cdef cugraph_type_erased_device_array_view_t* values_ptr = \ cugraph_centrality_result_get_values(result_ptr) - + cupy_vertices = copy_to_cupy_array(c_resource_handle_ptr, vertices_ptr) cupy_values = copy_to_cupy_array(c_resource_handle_ptr, values_ptr) diff --git a/python/pylibcugraph/pylibcugraph/node2vec.pyx b/python/pylibcugraph/pylibcugraph/node2vec.pyx index 2ef962ae0c6..a550070e7a7 100644 --- a/python/pylibcugraph/pylibcugraph/node2vec.pyx +++ b/python/pylibcugraph/pylibcugraph/node2vec.pyx @@ -55,15 +55,13 @@ from pylibcugraph.utils cimport ( ) -def node2vec( - ResourceHandle resource_handle, - _GPUGraph graph, - seed_array, - size_t max_depth, - bool_t compress_result, - double p, - double q -): +def node2vec(ResourceHandle resource_handle, + _GPUGraph graph, + seed_array, + size_t max_depth, + bool_t compress_result, + double p, + double q): """ Computes random walks under node2vec sampling procedure. @@ -174,8 +172,8 @@ def node2vec( cupy_paths = copy_to_cupy_array(c_resource_handle_ptr, paths_ptr) cupy_weights = copy_to_cupy_array(c_resource_handle_ptr, weights_ptr) cupy_path_sizes = copy_to_cupy_array(c_resource_handle_ptr, - path_sizes_ptr) - + path_sizes_ptr) + cugraph_random_walk_result_free(result_ptr) cugraph_type_erased_device_array_view_free(seed_view_ptr) diff --git a/python/pylibcugraph/pylibcugraph/overlap_coefficients.pyx b/python/pylibcugraph/pylibcugraph/overlap_coefficients.pyx index 8eea14ec48d..6af71116469 100644 --- a/python/pylibcugraph/pylibcugraph/overlap_coefficients.pyx +++ b/python/pylibcugraph/pylibcugraph/overlap_coefficients.pyx @@ -57,17 +57,15 @@ from pylibcugraph.utils cimport ( ) -def EXPERIMENTAL__overlap_coefficients( - ResourceHandle resource_handle, - _GPUGraph graph, - first, - second, - bool_t use_weight, - bool_t do_expensive_check -): +def EXPERIMENTAL__overlap_coefficients(ResourceHandle resource_handle, + _GPUGraph graph, + first, + second, + bool_t use_weight, + bool_t do_expensive_check): """ Compute the Overlap coefficients for the specified vertex_pairs. - + Note that Overlap similarity must run on a symmetric graph. @@ -79,13 +77,13 @@ def EXPERIMENTAL__overlap_coefficients( graph : SGGraph or MGGraph The input graph, for either Single or Multi-GPU operations. - + first : Source of the vertex pair. - + second : Destination of the vertex pair. - + use_weight : bool, optional (default=False) Currently not supported @@ -115,12 +113,16 @@ def EXPERIMENTAL__overlap_coefficients( cdef cugraph_error_t* error_ptr # 'first' is a required parameter - cdef cugraph_type_erased_device_array_view_t* first_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj(first) + cdef cugraph_type_erased_device_array_view_t* \ + first_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj( + first) # 'second' is a required parameter - cdef cugraph_type_erased_device_array_view_t* second_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj(second) + cdef cugraph_type_erased_device_array_view_t* \ + second_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj( + second) error_code = cugraph_create_vertex_pairs(c_resource_handle_ptr, c_graph_ptr, diff --git a/python/pylibcugraph/pylibcugraph/pagerank.pyx b/python/pylibcugraph/pylibcugraph/pagerank.pyx index 1a01efd146c..7d8f7807ead 100644 --- a/python/pylibcugraph/pylibcugraph/pagerank.pyx +++ b/python/pylibcugraph/pylibcugraph/pagerank.pyx @@ -55,18 +55,16 @@ from pylibcugraph.utils cimport ( ) -def pagerank( - ResourceHandle resource_handle, - _GPUGraph graph, - precomputed_vertex_out_weight_vertices, - precomputed_vertex_out_weight_sums, - initial_guess_vertices, - initial_guess_values, - double alpha, - double epsilon, - size_t max_iterations, - bool_t do_expensive_check -): +def pagerank(ResourceHandle resource_handle, + _GPUGraph graph, + precomputed_vertex_out_weight_vertices, + precomputed_vertex_out_weight_sums, + initial_guess_vertices, + initial_guess_values, + double alpha, + double epsilon, + size_t max_iterations, + bool_t do_expensive_check): """ Find the PageRank score for every vertex in a graph by computing an approximation of the Pagerank eigenvector using the power method. The @@ -168,11 +166,15 @@ def pagerank( raise RuntimeError("pagerank requires the numpy package, which could " "not be imported") - cdef cugraph_type_erased_device_array_view_t* initial_guess_vertices_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj(initial_guess_vertices) + cdef cugraph_type_erased_device_array_view_t* \ + initial_guess_vertices_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj( + initial_guess_vertices) - cdef cugraph_type_erased_device_array_view_t* initial_guess_values_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj(initial_guess_values) + cdef cugraph_type_erased_device_array_view_t* \ + initial_guess_values_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj( + initial_guess_values) cdef cugraph_resource_handle_t* c_resource_handle_ptr = \ resource_handle.c_resource_handle_ptr @@ -180,15 +182,15 @@ def pagerank( cdef cugraph_type_erased_device_array_view_t* \ precomputed_vertex_out_weight_vertices_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - precomputed_vertex_out_weight_vertices) + create_cugraph_type_erased_device_array_view_from_py_obj( + precomputed_vertex_out_weight_vertices) # FIXME: assert that precomputed_vertex_out_weight_sums # type == weight type cdef cugraph_type_erased_device_array_view_t* \ precomputed_vertex_out_weight_sums_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - precomputed_vertex_out_weight_sums) + create_cugraph_type_erased_device_array_view_from_py_obj( + precomputed_vertex_out_weight_sums) cdef cugraph_centrality_result_t* result_ptr cdef cugraph_error_code_t error_code @@ -225,10 +227,8 @@ def pagerank( if initial_guess_values is not None: cugraph_type_erased_device_array_view_free(initial_guess_values_view_ptr) if precomputed_vertex_out_weight_vertices is not None: - cugraph_type_erased_device_array_view_free( - precomputed_vertex_out_weight_vertices_view_ptr) + cugraph_type_erased_device_array_view_free(precomputed_vertex_out_weight_vertices_view_ptr) if precomputed_vertex_out_weight_sums is not None: - cugraph_type_erased_device_array_view_free( - precomputed_vertex_out_weight_sums_view_ptr) + cugraph_type_erased_device_array_view_free(precomputed_vertex_out_weight_sums_view_ptr) return (cupy_vertices, cupy_pageranks) diff --git a/python/pylibcugraph/pylibcugraph/personalized_pagerank.pyx b/python/pylibcugraph/pylibcugraph/personalized_pagerank.pyx index 1fe29ab30aa..89b57f139a1 100644 --- a/python/pylibcugraph/pylibcugraph/personalized_pagerank.pyx +++ b/python/pylibcugraph/pylibcugraph/personalized_pagerank.pyx @@ -90,19 +90,19 @@ def personalized_pagerank(ResourceHandle resource_handle, precomputed_vertex_out_weight_sums : device array type Corresponding precomputed sum of outgoing vertices weight (a performance optimization) - + initial_guess_vertices : device array type Subset of vertices of graph for initial guess for pagerank values (a performance optimization) - + initial_guess_values : device array type Pagerank values for vertices (a performance optimization) - + personalization_vertices : device array type Subset of vertices of graph for personalization (a performance optimization) - + personalization_values : device array type Personalization values for vertices (a performance optimization) @@ -184,13 +184,13 @@ def personalized_pagerank(ResourceHandle resource_handle, cdef cugraph_type_erased_device_array_view_t* \ initial_guess_vertices_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - initial_guess_vertices) + create_cugraph_type_erased_device_array_view_from_py_obj( + initial_guess_vertices) cdef cugraph_type_erased_device_array_view_t* \ initial_guess_values_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - initial_guess_values) + create_cugraph_type_erased_device_array_view_from_py_obj( + initial_guess_values) cdef cugraph_resource_handle_t* c_resource_handle_ptr = \ resource_handle.c_resource_handle_ptr @@ -198,45 +198,44 @@ def personalized_pagerank(ResourceHandle resource_handle, cdef cugraph_type_erased_device_array_view_t* \ precomputed_vertex_out_weight_vertices_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - precomputed_vertex_out_weight_vertices) + create_cugraph_type_erased_device_array_view_from_py_obj( + precomputed_vertex_out_weight_vertices) # FIXME: assert that precomputed_vertex_out_weight_sums # type == weight type cdef cugraph_type_erased_device_array_view_t* \ precomputed_vertex_out_weight_sums_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - precomputed_vertex_out_weight_sums) - + create_cugraph_type_erased_device_array_view_from_py_obj( + precomputed_vertex_out_weight_sums) + cdef cugraph_type_erased_device_array_view_t* \ personalization_vertices_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - personalization_vertices) - + create_cugraph_type_erased_device_array_view_from_py_obj( + personalization_vertices) + cdef cugraph_type_erased_device_array_view_t* \ personalization_values_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj( - personalization_values) + create_cugraph_type_erased_device_array_view_from_py_obj( + personalization_values) cdef cugraph_centrality_result_t* result_ptr cdef cugraph_error_code_t error_code cdef cugraph_error_t* error_ptr - error_code = cugraph_personalized_pagerank( - c_resource_handle_ptr, - c_graph_ptr, - precomputed_vertex_out_weight_vertices_view_ptr, - precomputed_vertex_out_weight_sums_view_ptr, - initial_guess_vertices_view_ptr, - initial_guess_values_view_ptr, - personalization_vertices_view_ptr, - personalization_values_view_ptr, - alpha, - epsilon, - max_iterations, - do_expensive_check, - &result_ptr, - &error_ptr) + error_code = cugraph_personalized_pagerank(c_resource_handle_ptr, + c_graph_ptr, + precomputed_vertex_out_weight_vertices_view_ptr, + precomputed_vertex_out_weight_sums_view_ptr, + initial_guess_vertices_view_ptr, + initial_guess_values_view_ptr, + personalization_vertices_view_ptr, + personalization_values_view_ptr, + alpha, + epsilon, + max_iterations, + do_expensive_check, + &result_ptr, + &error_ptr) assert_success(error_code, error_ptr, "cugraph_personalized_pagerank") # Extract individual device array pointers from result and copy to cupy @@ -256,11 +255,9 @@ def personalized_pagerank(ResourceHandle resource_handle, if initial_guess_values is not None: cugraph_type_erased_device_array_view_free(initial_guess_values_view_ptr) if precomputed_vertex_out_weight_vertices is not None: - cugraph_type_erased_device_array_view_free( - precomputed_vertex_out_weight_vertices_view_ptr) + cugraph_type_erased_device_array_view_free(precomputed_vertex_out_weight_vertices_view_ptr) if precomputed_vertex_out_weight_sums is not None: - cugraph_type_erased_device_array_view_free( - precomputed_vertex_out_weight_sums_view_ptr) + cugraph_type_erased_device_array_view_free(precomputed_vertex_out_weight_sums_view_ptr) if personalization_vertices is not None: cugraph_type_erased_device_array_view_free(personalization_vertices_view_ptr) if personalization_values is not None: diff --git a/python/pylibcugraph/pylibcugraph/resource_handle.pyx b/python/pylibcugraph/pylibcugraph/resource_handle.pyx index b5a97495138..75f03e67d91 100644 --- a/python/pylibcugraph/pylibcugraph/resource_handle.pyx +++ b/python/pylibcugraph/pylibcugraph/resource_handle.pyx @@ -18,7 +18,7 @@ from pylibcugraph._cugraph_c.resource_handle cimport ( cugraph_create_resource_handle, cugraph_free_resource_handle, ) -# from cugraph.dask.traversal cimport mg_bfs as c_bfs +#from cugraph.dask.traversal cimport mg_bfs as c_bfs from pylibcugraph cimport resource_handle as c_resource_handle diff --git a/python/pylibcugraph/pylibcugraph/sorensen_coefficients.pyx b/python/pylibcugraph/pylibcugraph/sorensen_coefficients.pyx index 1b72baf0a26..12647baccb2 100644 --- a/python/pylibcugraph/pylibcugraph/sorensen_coefficients.pyx +++ b/python/pylibcugraph/pylibcugraph/sorensen_coefficients.pyx @@ -57,17 +57,15 @@ from pylibcugraph.utils cimport ( ) -def EXPERIMENTAL__sorensen_coefficients( - ResourceHandle resource_handle, - _GPUGraph graph, - first, - second, - bool_t use_weight, - bool_t do_expensive_check -): +def EXPERIMENTAL__sorensen_coefficients(ResourceHandle resource_handle, + _GPUGraph graph, + first, + second, + bool_t use_weight, + bool_t do_expensive_check): """ Compute the Sorensen coefficients for the specified vertex_pairs. - + Note that Sorensen similarity must run on a symmetric graph. Parameters @@ -78,13 +76,13 @@ def EXPERIMENTAL__sorensen_coefficients( graph : SGGraph or MGGraph The input graph, for either Single or Multi-GPU operations. - + first : Source of the vertex pair. - + second : Destination of the vertex pair. - + use_weight : bool, optional (default=False) Currently not supported @@ -114,12 +112,16 @@ def EXPERIMENTAL__sorensen_coefficients( cdef cugraph_error_t* error_ptr # 'first' is a required parameter - cdef cugraph_type_erased_device_array_view_t* first_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj(first) + cdef cugraph_type_erased_device_array_view_t* \ + first_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj( + first) # 'second' is a required parameter - cdef cugraph_type_erased_device_array_view_t* second_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj(second) + cdef cugraph_type_erased_device_array_view_t* \ + second_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj( + second) error_code = cugraph_create_vertex_pairs(c_resource_handle_ptr, c_graph_ptr, @@ -130,12 +132,12 @@ def EXPERIMENTAL__sorensen_coefficients( assert_success(error_code, error_ptr, "vertex_pairs") error_code = cugraph_sorensen_coefficients(c_resource_handle_ptr, - c_graph_ptr, - vertex_pairs_ptr, - use_weight, - do_expensive_check, - &result_ptr, - &error_ptr) + c_graph_ptr, + vertex_pairs_ptr, + use_weight, + do_expensive_check, + &result_ptr, + &error_ptr) assert_success(error_code, error_ptr, "cugraph_sorensen_coefficients") # Extract individual device array pointers from result and copy to cupy diff --git a/python/pylibcugraph/pylibcugraph/sssp.pyx b/python/pylibcugraph/pylibcugraph/sssp.pyx index 4d55eb224e3..b2cd829cb2e 100644 --- a/python/pylibcugraph/pylibcugraph/sssp.pyx +++ b/python/pylibcugraph/pylibcugraph/sssp.pyx @@ -49,14 +49,12 @@ from pylibcugraph.utils cimport ( ) -def sssp( - ResourceHandle resource_handle, - _GPUGraph graph, - size_t source, - double cutoff, - bool_t compute_predecessors, - bool_t do_expensive_check -): +def sssp(ResourceHandle resource_handle, + _GPUGraph graph, + size_t source, + double cutoff, + bool_t compute_predecessors, + bool_t do_expensive_check): """ Compute the distance and predecessors for shortest paths from the specified source to all the vertices in the graph. The returned distances array will diff --git a/python/pylibcugraph/pylibcugraph/structure/graph_primtypes.pxd b/python/pylibcugraph/pylibcugraph/structure/graph_primtypes.pxd index ad88589d7ab..32b700dc513 100644 --- a/python/pylibcugraph/pylibcugraph/structure/graph_primtypes.pxd +++ b/python/pylibcugraph/pylibcugraph/structure/graph_primtypes.pxd @@ -39,9 +39,9 @@ cdef extern from "cugraph/legacy/graph.hpp" namespace "cugraph::legacy": bool tree PropType has_negative_edges - cdef cppclass GraphViewBase[VT, ET, WT]: + cdef cppclass GraphViewBase[VT,ET,WT]: WT *edge_data - handle_t *handle + handle_t *handle; GraphProperties prop VT number_of_vertices ET number_of_edges @@ -52,31 +52,30 @@ cdef extern from "cugraph/legacy/graph.hpp" namespace "cugraph::legacy": void set_local_data(VT* local_vertices_, ET* local_edges_, VT* local_offsets_) void get_vertex_identifiers(VT *) const - GraphViewBase(WT*, VT, ET) + GraphViewBase(WT*,VT,ET) - cdef cppclass GraphCOOView[VT, ET, WT](GraphViewBase[VT, ET, WT]): + cdef cppclass GraphCOOView[VT,ET,WT](GraphViewBase[VT,ET,WT]): VT *src_indices VT *dst_indices - void degree(ET *, DegreeDirection) const + void degree(ET *,DegreeDirection) const GraphCOOView() GraphCOOView(const VT *, const ET *, const WT *, size_t, size_t) - cdef cppclass GraphCompressedSparseBaseView[VT, ET, WT](GraphViewBase[VT, ET, WT]): + cdef cppclass GraphCompressedSparseBaseView[VT,ET,WT](GraphViewBase[VT,ET,WT]): ET *offsets VT *indices void get_source_indices(VT *) const - void degree(ET *, DegreeDirection) const + void degree(ET *,DegreeDirection) const - GraphCompressedSparseBaseView( - const VT *, const ET *, const WT *, size_t, size_t) + GraphCompressedSparseBaseView(const VT *, const ET *, const WT *, size_t, size_t) - cdef cppclass GraphCSRView[VT, ET, WT](GraphCompressedSparseBaseView[VT, ET, WT]): + cdef cppclass GraphCSRView[VT,ET,WT](GraphCompressedSparseBaseView[VT,ET,WT]): GraphCSRView() GraphCSRView(const VT *, const ET *, const WT *, size_t, size_t) - cdef cppclass GraphCSCView[VT, ET, WT](GraphCompressedSparseBaseView[VT, ET, WT]): + cdef cppclass GraphCSCView[VT,ET,WT](GraphCompressedSparseBaseView[VT,ET,WT]): GraphCSCView() GraphCSCView(const VT *, const ET *, const WT *, size_t, size_t) diff --git a/python/pylibcugraph/pylibcugraph/structure/graph_utilities.pxd b/python/pylibcugraph/pylibcugraph/structure/graph_utilities.pxd index 5d0c2326c10..d9532cd4190 100644 --- a/python/pylibcugraph/pylibcugraph/structure/graph_utilities.pxd +++ b/python/pylibcugraph/pylibcugraph/structure/graph_utilities.pxd @@ -30,7 +30,7 @@ cdef extern from "cugraph/utilities/cython.hpp" namespace "cugraph::cython": doubleType "cugraph::cython::numberTypeEnum::doubleType" cdef cppclass graph_container_t: - pass + pass cdef void populate_graph_container( graph_container_t &graph_container, diff --git a/python/pylibcugraph/pylibcugraph/testing/type_utils.pyx b/python/pylibcugraph/pylibcugraph/testing/type_utils.pyx index 8f6b5eb32f8..253551eba11 100644 --- a/python/pylibcugraph/pylibcugraph/testing/type_utils.pyx +++ b/python/pylibcugraph/pylibcugraph/testing/type_utils.pyx @@ -47,7 +47,7 @@ from pylibcugraph._cugraph_c.array cimport ( def create_sampling_result(ResourceHandle resource_handle, - device_sources, + device_sources, device_destinations, device_indices): """ diff --git a/python/pylibcugraph/pylibcugraph/triangle_count.pyx b/python/pylibcugraph/pylibcugraph/triangle_count.pyx index 00d55f544c8..e26b2a291cf 100644 --- a/python/pylibcugraph/pylibcugraph/triangle_count.pyx +++ b/python/pylibcugraph/pylibcugraph/triangle_count.pyx @@ -74,11 +74,11 @@ def triangle_count(ResourceHandle resource_handle, start_list: device array type Device array containing the list of vertices for triangle counting. If 'None' the entire set of vertices in the graph is processed - + do_expensive_check: bool If True, performs more extensive tests on the inputs to ensure validitity, at the expense of increased run time. - + Returns ------- A tuple of device arrays, where the first item in the tuple is a device @@ -112,7 +112,7 @@ def triangle_count(ResourceHandle resource_handle, get_c_type_from_numpy_type(start_list.dtype)) else: start_ptr = NULL - + error_code = cugraph_triangle_count(c_resource_handle_ptr, c_graph_ptr, start_ptr, @@ -133,5 +133,5 @@ def triangle_count(ResourceHandle resource_handle, if start_list is not None: cugraph_type_erased_device_array_view_free(start_ptr) - + return (cupy_vertices, cupy_counts) diff --git a/python/pylibcugraph/pylibcugraph/two_hop_neighbors.pyx b/python/pylibcugraph/pylibcugraph/two_hop_neighbors.pyx index 3a25286240e..649f7980747 100644 --- a/python/pylibcugraph/pylibcugraph/two_hop_neighbors.pyx +++ b/python/pylibcugraph/pylibcugraph/two_hop_neighbors.pyx @@ -69,7 +69,7 @@ def get_two_hop_neighbors(ResourceHandle resource_handle, graph : SGGraph or MGGraph The input graph, for either Single or Multi-GPU operations. - + start_vertices : Optional array of starting vertices If None use all, if specified compute two-hop neighbors for these starting vertices @@ -90,8 +90,10 @@ def get_two_hop_neighbors(ResourceHandle resource_handle, cdef cugraph_type_erased_device_array_view_t* start_vertices_ptr - cdef cugraph_type_erased_device_array_view_t* start_vertices_view_ptr = \ - create_cugraph_type_erased_device_array_view_from_py_obj(start_vertices) + cdef cugraph_type_erased_device_array_view_t* \ + start_vertices_view_ptr = \ + create_cugraph_type_erased_device_array_view_from_py_obj( + start_vertices) error_code = cugraph_two_hop_neighbors(c_resource_handle_ptr, c_graph_ptr, @@ -103,16 +105,16 @@ def get_two_hop_neighbors(ResourceHandle resource_handle, cdef cugraph_type_erased_device_array_view_t* first_ptr = \ cugraph_vertex_pairs_get_first(result_ptr) - + cdef cugraph_type_erased_device_array_view_t* second_ptr = \ cugraph_vertex_pairs_get_second(result_ptr) - + cupy_first = copy_to_cupy_array(c_resource_handle_ptr, first_ptr) cupy_second = copy_to_cupy_array(c_resource_handle_ptr, second_ptr) # Free all pointers cugraph_vertex_pairs_free(result_ptr) if start_vertices is not None: - cugraph_type_erased_device_array_view_free(start_vertices_view_ptr) + cugraph_type_erased_device_array_view_free(start_vertices_view_ptr) return cupy_first, cupy_second diff --git a/python/pylibcugraph/pylibcugraph/uniform_neighbor_sample.pyx b/python/pylibcugraph/pylibcugraph/uniform_neighbor_sample.pyx index 1b5c9d550c4..0d86053a679 100644 --- a/python/pylibcugraph/pylibcugraph/uniform_neighbor_sample.pyx +++ b/python/pylibcugraph/pylibcugraph/uniform_neighbor_sample.pyx @@ -62,7 +62,6 @@ from pylibcugraph.internal_types.sampling_result cimport ( SamplingResult, ) - def uniform_neighbor_sample(ResourceHandle resource_handle, _GPUGraph input_graph, start_list, diff --git a/python/pylibcugraph/pylibcugraph/utils.pxd b/python/pylibcugraph/pylibcugraph/utils.pxd index 44f51f09a93..7fc140e9aed 100644 --- a/python/pylibcugraph/pylibcugraph/utils.pxd +++ b/python/pylibcugraph/pylibcugraph/utils.pxd @@ -44,12 +44,12 @@ cdef get_c_weight_type_from_numpy_edge_ids_type(numpy_type) cdef get_numpy_edge_ids_type_from_c_weight_type(data_type_id_t c_type) cdef copy_to_cupy_array( - cugraph_resource_handle_t* c_resource_handle_ptr, - cugraph_type_erased_device_array_view_t* device_array_view_ptr) + cugraph_resource_handle_t* c_resource_handle_ptr, + cugraph_type_erased_device_array_view_t* device_array_view_ptr) cdef copy_to_cupy_array_ids( - cugraph_resource_handle_t* c_resource_handle_ptr, - cugraph_type_erased_device_array_view_t* device_array_view_ptr) + cugraph_resource_handle_t* c_resource_handle_ptr, + cugraph_type_erased_device_array_view_t* device_array_view_ptr) cdef cugraph_type_erased_device_array_view_t* \ create_cugraph_type_erased_device_array_view_from_py_obj(python_obj) diff --git a/python/pylibcugraph/pylibcugraph/utils.pyx b/python/pylibcugraph/pylibcugraph/utils.pyx index baab68788a3..a9fc8fce711 100644 --- a/python/pylibcugraph/pylibcugraph/utils.pyx +++ b/python/pylibcugraph/pylibcugraph/utils.pyx @@ -68,7 +68,7 @@ cdef assert_success(cugraph_error_code_t code, raise ValueError(error_msg) elif code == cugraph_error_code_t.CUGRAPH_NOT_IMPLEMENTED: code_str = "CUGRAPH_NOT_IMPLEMENTED" - error_msg = f"non-success value returned from {api_name}: {code_str} "\ + error_msg = f"non-success value returned from {api_name}: {code_str}\ "\ f"{c_error}" raise NotImplementedError(error_msg) elif code == cugraph_error_code_t.CUGRAPH_UNSUPPORTED_TYPE_COMBINATION: @@ -133,10 +133,8 @@ cdef get_c_type_from_numpy_type(numpy_type): elif numpy_type == numpy.float64: return data_type_id_t.FLOAT64 else: - raise RuntimeError( - "Internal error: got invalid data type enum value from Numpy: " - f"{numpy_type}" - ) + raise RuntimeError("Internal error: got invalid data type enum value " + f"from Numpy: {numpy_type}") cdef get_c_weight_type_from_numpy_edge_ids_type(numpy_type): if numpy_type == numpy.int32: @@ -152,9 +150,8 @@ cdef get_numpy_edge_ids_type_from_c_weight_type(data_type_id_t c_weight_type): cdef copy_to_cupy_array( - cugraph_resource_handle_t* c_resource_handle_ptr, - cugraph_type_erased_device_array_view_t* device_array_view_ptr -): + cugraph_resource_handle_t* c_resource_handle_ptr, + cugraph_type_erased_device_array_view_t* device_array_view_ptr): """ Copy the contents from a device array view as returned by various cugraph_* APIs to a new cupy device array, typically intended to be used as a return @@ -189,9 +186,8 @@ cdef copy_to_cupy_array( return cupy_array cdef copy_to_cupy_array_ids( - cugraph_resource_handle_t* c_resource_handle_ptr, - cugraph_type_erased_device_array_view_t* device_array_view_ptr -): + cugraph_resource_handle_t* c_resource_handle_ptr, + cugraph_type_erased_device_array_view_t* device_array_view_ptr): """ Copy the contents from a device array view as returned by various cugraph_* APIs to a new cupy device array, typically intended to be used as a return @@ -211,9 +207,7 @@ cdef copy_to_cupy_array_ids( cdef cugraph_type_erased_device_array_view_t* cupy_array_view_ptr = \ cugraph_type_erased_device_array_view_create( - cupy_array_ptr, - array_size, - get_c_type_from_numpy_type(cupy_array.dtype)) + cupy_array_ptr, array_size, get_c_type_from_numpy_type(cupy_array.dtype)) cdef cugraph_error_t* error_ptr error_code = cugraph_type_erased_device_array_view_copy( @@ -229,21 +223,21 @@ cdef copy_to_cupy_array_ids( return cupy_array cdef cugraph_type_erased_device_array_view_t* \ - create_cugraph_type_erased_device_array_view_from_py_obj(python_obj): - cdef uintptr_t cai_ptr = NULL - cdef cugraph_type_erased_device_array_view_t* view_ptr = NULL - if python_obj is not None: - cai_ptr = python_obj.__cuda_array_interface__["data"][0] - view_ptr = cugraph_type_erased_device_array_view_create( - cai_ptr, - len(python_obj), - get_c_type_from_numpy_type(python_obj.dtype)) - - return view_ptr + create_cugraph_type_erased_device_array_view_from_py_obj(python_obj): + cdef uintptr_t cai_ptr = NULL + cdef cugraph_type_erased_device_array_view_t* view_ptr = NULL + if python_obj is not None: + cai_ptr = python_obj.__cuda_array_interface__["data"][0] + view_ptr = cugraph_type_erased_device_array_view_create( + cai_ptr, + len(python_obj), + get_c_type_from_numpy_type(python_obj.dtype)) + + return view_ptr cdef create_cupy_array_view_for_device_ptr( - cugraph_type_erased_device_array_view_t* device_array_view_ptr, - owning_py_object): + cugraph_type_erased_device_array_view_t* device_array_view_ptr, + owning_py_object): if device_array_view_ptr == NULL: raise ValueError("device_array_view_ptr cannot be NULL") diff --git a/python/pylibcugraph/pylibcugraph/weakly_connected_components.pyx b/python/pylibcugraph/pylibcugraph/weakly_connected_components.pyx index 26f991403b2..abd78aa8c10 100644 --- a/python/pylibcugraph/pylibcugraph/weakly_connected_components.pyx +++ b/python/pylibcugraph/pylibcugraph/weakly_connected_components.pyx @@ -65,7 +65,8 @@ def _ensure_args(graph, offsets, indices, weights): else: invalid_input = [i for p in [offsets, indices] if p is None] input_type = "csr_arrays" - + + if len(invalid_input) != 0: raise TypeError("Invalid input combination: Must set either 'graph' or " "a combination of 'offsets', 'indices' and 'weights', not both") @@ -74,7 +75,7 @@ def _ensure_args(graph, offsets, indices, weights): assert_CAI_type(offsets, "offsets") assert_CAI_type(indices, "indices") assert_CAI_type(weights, "weights", True) - + return input_type @@ -98,7 +99,7 @@ def weakly_connected_components(ResourceHandle resource_handle, graph : SGGraph or MGGraph The input graph. - + offsets : object supporting a __cuda_array_interface__ interface Array containing the offsets values of a Compressed Sparse Row matrix that represents the graph. @@ -136,7 +137,7 @@ def weakly_connected_components(ResourceHandle resource_handle, ... store_transposed=False, renumber=True, do_expensive_check=False) >>> (vertices, labels) = weakly_connected_components( ... resource_handle, G, None, None, None, None, False) - + >>> vertices [0, 1, 2] >>> labels @@ -181,20 +182,18 @@ def weakly_connected_components(ResourceHandle resource_handle, resource_handle = ResourceHandle() graph_props = GraphProperties( - is_symmetric=True, - is_multigraph=False, - ) + is_symmetric=True, is_multigraph=False) graph = SGGraph( - resource_handle, - graph_props, - offsets, - indices, - weights, - store_transposed=False, - renumber=False, - do_expensive_check=True, - input_array_format="CSR", - ) + resource_handle, + graph_props, + offsets, + indices, + weights, + store_transposed=False, + renumber=False, + do_expensive_check=True, + input_array_format="CSR" + ) cdef cugraph_resource_handle_t* c_resource_handle_ptr = \ resource_handle.c_resource_handle_ptr From 999132a21adbd780a5dbf8912bbd21f2d88b969a Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Fri, 9 Dec 2022 14:02:27 -0600 Subject: [PATCH 5/8] Revert "Apply clang-format to tests and libcugraph_etl." This reverts commit 9825b90c70d1c4ddf525b41c5d402e4bcaf9a5b1. --- .pre-commit-config.yaml | 12 ++--- .../include/hash/concurrent_unordered_map.cuh | 4 +- cpp/libcugraph_etl/src/renumbering.cu | 4 +- cpp/tests/c_api/betweenness_centrality_test.c | 4 +- cpp/tests/c_api/bfs_test.c | 6 +-- cpp/tests/c_api/core_number_test.c | 3 +- .../c_api/create_sg_graph_envelope_test.c | 4 +- cpp/tests/c_api/edge_betweenness_centrality.c | 14 ++--- cpp/tests/c_api/egonet_test.c | 12 ++--- cpp/tests/c_api/hits_test.c | 12 +---- .../c_api/mg_betweenness_centrality_test.c | 4 +- cpp/tests/c_api/mg_core_number_test.c | 3 +- cpp/tests/c_api/mg_create_graph_test.c | 2 +- .../c_api/mg_edge_betweenness_centrality.c | 16 +++--- cpp/tests/c_api/mg_egonet_test.c | 18 +++---- .../c_api/mg_eigenvector_centrality_test.c | 14 +++-- cpp/tests/c_api/mg_induced_subgraph_test.c | 23 ++++---- cpp/tests/c_api/mg_katz_test.c | 6 +-- cpp/tests/c_api/mg_pagerank_test.c | 21 +++----- cpp/tests/c_api/mg_random_walks_test.c | 9 ++-- cpp/tests/c_api/mg_similarity_test.c | 12 +++-- cpp/tests/c_api/mg_sssp_test.c | 52 +++++++++---------- .../mg_strongly_connected_components_test.c | 3 +- cpp/tests/c_api/mg_triangle_count_test.c | 2 +- cpp/tests/c_api/node2vec_test.c | 41 +++++---------- cpp/tests/c_api/random_walks_test.c | 12 ++--- cpp/tests/c_api/sg_random_walks_test.c | 9 ++-- cpp/tests/c_api/sssp_test.c | 30 +++++------ .../strongly_connected_components_test.c | 3 +- cpp/tests/c_api/triangle_count_test.c | 3 +- 30 files changed, 167 insertions(+), 191 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 24136489a7f..5c158d15551 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,12 +32,12 @@ repos: - id: yesqa additional_dependencies: - flake8==6.0.0 - - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v11.1.0 - hooks: - - id: clang-format - types_or: [c, c++, cuda] - args: ["-fallback-style=none", "-style=file", "-i"] +# - repo: https://github.com/pre-commit/mirrors-clang-format +# rev: v11.1.0 +# hooks: +# - id: clang-format +# types_or: [c, c++, cuda] +# args: ["-fallback-style=none", "-style=file", "-i"] - repo: local hooks: - id: copyright-check diff --git a/cpp/libcugraph_etl/include/hash/concurrent_unordered_map.cuh b/cpp/libcugraph_etl/include/hash/concurrent_unordered_map.cuh index c50e4a0da9c..c48ee2fb792 100644 --- a/cpp/libcugraph_etl/include/hash/concurrent_unordered_map.cuh +++ b/cpp/libcugraph_etl/include/hash/concurrent_unordered_map.cuh @@ -14,9 +14,9 @@ * limitations under the License. */ -/* + /* * FIXME: This file is copied from cudf because CuCollections doesnt support concurrent - * insert/find for 8 byte key-value pair size. The plan is to migrate to + * insert/find for 8 byte key-value pair size. The plan is to migrate to * using the cuco when the feature is supported. At that point this file can be deleted. */ #pragma once diff --git a/cpp/libcugraph_etl/src/renumbering.cu b/cpp/libcugraph_etl/src/renumbering.cu index 683c7823f7c..89c8bd3d792 100644 --- a/cpp/libcugraph_etl/src/renumbering.cu +++ b/cpp/libcugraph_etl/src/renumbering.cu @@ -793,8 +793,8 @@ struct renumber_functor { cudaStream_t exec_strm = handle.get_stream(); - auto mr = rmm::mr::new_delete_resource(); - size_t hist_size = sizeof(accum_type) * 32; + auto mr = rmm::mr::new_delete_resource(); + size_t hist_size = sizeof(accum_type) * 32; accum_type* hist_insert_counter = static_cast(mr.allocate(hist_size)); *hist_insert_counter = 0; diff --git a/cpp/tests/c_api/betweenness_centrality_test.c b/cpp/tests/c_api/betweenness_centrality_test.c index f201d631544..5056fc09bc5 100644 --- a/cpp/tests/c_api/betweenness_centrality_test.c +++ b/cpp/tests/c_api/betweenness_centrality_test.c @@ -55,9 +55,7 @@ int generic_betweenness_centrality_test(vertex_t* h_src, ret_code = cugraph_betweenness_centrality( p_handle, p_graph, num_vertices_to_sample, NULL, FALSE, FALSE, FALSE, &p_result, &ret_error); #if 1 - TEST_ASSERT(test_ret_value, - ret_code != CUGRAPH_SUCCESS, - "cugraph_betweenness_centrality should have failed"); + TEST_ASSERT(test_ret_value, ret_code != CUGRAPH_SUCCESS, "cugraph_betweenness_centrality should have failed"); #else TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, cugraph_error_message(ret_error)); TEST_ASSERT( diff --git a/cpp/tests/c_api/bfs_test.c b/cpp/tests/c_api/bfs_test.c index 8feb426a853..e4eb4513f23 100644 --- a/cpp/tests/c_api/bfs_test.c +++ b/cpp/tests/c_api/bfs_test.c @@ -123,9 +123,9 @@ int test_bfs_exceptions() size_t depth_limit = 1; size_t num_seeds = 1; - vertex_t src[] = {0, 1, 1, 2, 2, 2, 3, 4}; - vertex_t dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; - weight_t wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; + vertex_t src[] = {0, 1, 1, 2, 2, 2, 3, 4}; + vertex_t dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; + weight_t wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; int64_t seeds[] = {0}; int test_ret_value = 0; diff --git a/cpp/tests/c_api/core_number_test.c b/cpp/tests/c_api/core_number_test.c index 0228bde5b1c..c5837fd692b 100644 --- a/cpp/tests/c_api/core_number_test.c +++ b/cpp/tests/c_api/core_number_test.c @@ -52,8 +52,7 @@ int generic_core_number_test(vertex_t* h_src, TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "create_test_graph failed."); TEST_ALWAYS_ASSERT(ret_code == CUGRAPH_SUCCESS, cugraph_error_message(ret_error)); - ret_code = - cugraph_core_number(p_handle, p_graph, K_CORE_DEGREE_TYPE_IN, FALSE, &p_result, &ret_error); + ret_code = cugraph_core_number(p_handle, p_graph, K_CORE_DEGREE_TYPE_IN, FALSE, &p_result, &ret_error); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "cugraph_core_number failed."); TEST_ALWAYS_ASSERT(ret_code == CUGRAPH_SUCCESS, cugraph_error_message(ret_error)); diff --git a/cpp/tests/c_api/create_sg_graph_envelope_test.c b/cpp/tests/c_api/create_sg_graph_envelope_test.c index c33839310a5..14a5ac3cf1c 100644 --- a/cpp/tests/c_api/create_sg_graph_envelope_test.c +++ b/cpp/tests/c_api/create_sg_graph_envelope_test.c @@ -29,8 +29,8 @@ int test_create_sg_graph_simple() typedef float weight_t; cugraph_error_code_t ret_code = CUGRAPH_SUCCESS; - size_t num_edges = 8; - size_t num_vertices = 6; + size_t num_edges = 8; + size_t num_vertices = 6; vertex_t h_src[] = {0, 1, 1, 2, 2, 2, 3, 4}; vertex_t h_dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; diff --git a/cpp/tests/c_api/edge_betweenness_centrality.c b/cpp/tests/c_api/edge_betweenness_centrality.c index 658ce5f2288..75dbe464654 100644 --- a/cpp/tests/c_api/edge_betweenness_centrality.c +++ b/cpp/tests/c_api/edge_betweenness_centrality.c @@ -26,13 +26,13 @@ typedef int32_t edge_t; typedef float weight_t; int generic_edge_betweenness_centrality_test(vertex_t* h_src, - vertex_t* h_dst, - weight_t* h_wgt, - weight_t* h_result, - size_t num_vertices, - size_t num_edges, - bool_t store_transposed, - size_t num_vertices_to_sample) + vertex_t* h_dst, + weight_t* h_wgt, + weight_t* h_result, + size_t num_vertices, + size_t num_edges, + bool_t store_transposed, + size_t num_vertices_to_sample) { int test_ret_value = 0; diff --git a/cpp/tests/c_api/egonet_test.c b/cpp/tests/c_api/egonet_test.c index 3315373fdcb..fac9815c150 100644 --- a/cpp/tests/c_api/egonet_test.c +++ b/cpp/tests/c_api/egonet_test.c @@ -128,17 +128,15 @@ int generic_egonet_test(vertex_t* h_src, weight_t M[num_vertices][num_vertices]; for (int i = 0; (i < num_seeds) && (test_ret_value == 0); ++i) { - for (int r = 0; r < num_vertices; ++r) - for (int c = 0; c < num_vertices; ++c) + for (int r = 0 ; r < num_vertices ; ++r) + for (int c = 0 ; c < num_vertices ; ++c) M[r][c] = 0; - for (size_t e = h_expected_offsets[i]; e < h_expected_offsets[i + 1]; ++e) + for (size_t e = h_expected_offsets[i] ; e < h_expected_offsets[i+1] ; ++e) M[h_expected_src[e]][h_expected_dst[e]] = 1; - for (size_t e = h_result_offsets[i]; (e < h_result_offsets[i + 1]) && (test_ret_value == 0); - ++e) { - TEST_ASSERT( - test_ret_value, (M[h_result_src[e]][h_result_dst[e]] > 0), "found different edges"); + for (size_t e = h_result_offsets[i] ; (e < h_result_offsets[i+1]) && (test_ret_value == 0) ; ++e) { + TEST_ASSERT(test_ret_value, (M[h_result_src[e]][h_result_dst[e]] > 0), "found different edges"); } } diff --git a/cpp/tests/c_api/hits_test.c b/cpp/tests/c_api/hits_test.c index e8d4b98b7ab..c275d883d11 100644 --- a/cpp/tests/c_api/hits_test.c +++ b/cpp/tests/c_api/hits_test.c @@ -53,16 +53,8 @@ int generic_hits_test(vertex_t* h_src, p_handle = cugraph_create_resource_handle(NULL); TEST_ASSERT(test_ret_value, p_handle != NULL, "resource handle creation failed."); - ret_code = create_test_graph(p_handle, - h_src, - h_dst, - h_wgt, - num_edges, - store_transposed, - renumber, - FALSE, - &p_graph, - &ret_error); + ret_code = create_test_graph( + p_handle, h_src, h_dst, h_wgt, num_edges, store_transposed, renumber, FALSE, &p_graph, &ret_error); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "create_test_graph failed."); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, cugraph_error_message(ret_error)); diff --git a/cpp/tests/c_api/mg_betweenness_centrality_test.c b/cpp/tests/c_api/mg_betweenness_centrality_test.c index d48139177ad..c9a714c4bf4 100644 --- a/cpp/tests/c_api/mg_betweenness_centrality_test.c +++ b/cpp/tests/c_api/mg_betweenness_centrality_test.c @@ -51,9 +51,7 @@ int generic_betweenness_centrality_test(const cugraph_resource_handle_t* handle, ret_code = cugraph_betweenness_centrality( handle, p_graph, num_vertices_to_sample, NULL, FALSE, FALSE, FALSE, &p_result, &ret_error); #if 1 - TEST_ASSERT(test_ret_value, - ret_code != CUGRAPH_SUCCESS, - "cugraph_betweenness_centrality should have failed"); + TEST_ASSERT(test_ret_value, ret_code != CUGRAPH_SUCCESS, "cugraph_betweenness_centrality should have failed"); #else TEST_ASSERT( test_ret_value, ret_code == CUGRAPH_SUCCESS, "cugraph_betweenness_centrality failed."); diff --git a/cpp/tests/c_api/mg_core_number_test.c b/cpp/tests/c_api/mg_core_number_test.c index 8e53cb855d6..6b34effe183 100644 --- a/cpp/tests/c_api/mg_core_number_test.c +++ b/cpp/tests/c_api/mg_core_number_test.c @@ -48,8 +48,7 @@ int generic_core_number_test(const cugraph_resource_handle_t* p_handle, TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "create_test_graph failed."); TEST_ALWAYS_ASSERT(ret_code == CUGRAPH_SUCCESS, cugraph_error_message(ret_error)); - ret_code = - cugraph_core_number(p_handle, p_graph, K_CORE_DEGREE_TYPE_IN, FALSE, &p_result, &ret_error); + ret_code = cugraph_core_number(p_handle, p_graph, K_CORE_DEGREE_TYPE_IN, FALSE, &p_result, &ret_error); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "cugraph_core_number failed."); TEST_ALWAYS_ASSERT(ret_code == CUGRAPH_SUCCESS, cugraph_error_message(ret_error)); diff --git a/cpp/tests/c_api/mg_create_graph_test.c b/cpp/tests/c_api/mg_create_graph_test.c index 67534f16fa3..cc98dd982e0 100644 --- a/cpp/tests/c_api/mg_create_graph_test.c +++ b/cpp/tests/c_api/mg_create_graph_test.c @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "c_test_utils.h" /* RUN_TEST */ +#include "c_test_utils.h" /* RUN_TEST */ #include "mg_test_utils.h" /* RUN_TEST */ #include diff --git a/cpp/tests/c_api/mg_edge_betweenness_centrality.c b/cpp/tests/c_api/mg_edge_betweenness_centrality.c index 9431b3f5908..24e109f2f49 100644 --- a/cpp/tests/c_api/mg_edge_betweenness_centrality.c +++ b/cpp/tests/c_api/mg_edge_betweenness_centrality.c @@ -26,14 +26,14 @@ typedef int32_t edge_t; typedef float weight_t; int generic_edge_betweenness_centrality_test(const cugraph_resource_handle_t* handle, - vertex_t* h_src, - vertex_t* h_dst, - weight_t* h_wgt, - weight_t* h_result, - size_t num_vertices, - size_t num_edges, - bool_t store_transposed, - size_t num_vertices_to_sample) + vertex_t* h_src, + vertex_t* h_dst, + weight_t* h_wgt, + weight_t* h_result, + size_t num_vertices, + size_t num_edges, + bool_t store_transposed, + size_t num_vertices_to_sample) { int test_ret_value = 0; diff --git a/cpp/tests/c_api/mg_egonet_test.c b/cpp/tests/c_api/mg_egonet_test.c index 4b8a4ae3533..8f0dda42a57 100644 --- a/cpp/tests/c_api/mg_egonet_test.c +++ b/cpp/tests/c_api/mg_egonet_test.c @@ -68,7 +68,9 @@ int generic_egonet_test(const cugraph_resource_handle_t* resource_handle, TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "create_test_graph failed."); TEST_ALWAYS_ASSERT(ret_code == CUGRAPH_SUCCESS, cugraph_error_message(ret_error)); - if (rank != 0) { num_seeds = 0; } + if (rank != 0) { + num_seeds = 0; + } ret_code = cugraph_type_erased_device_array_create(resource_handle, num_seeds, INT32, &seeds, &ret_error); @@ -132,17 +134,15 @@ int generic_egonet_test(const cugraph_resource_handle_t* resource_handle, weight_t M[num_vertices][num_vertices]; for (int i = 0; (i < num_seeds) && (test_ret_value == 0); ++i) { - for (int r = 0; r < num_vertices; ++r) - for (int c = 0; c < num_vertices; ++c) + for (int r = 0 ; r < num_vertices ; ++r) + for (int c = 0 ; c < num_vertices ; ++c) M[r][c] = 0; - for (size_t e = h_expected_offsets[i]; e < h_expected_offsets[i + 1]; ++e) + for (size_t e = h_expected_offsets[i] ; e < h_expected_offsets[i+1] ; ++e) M[h_expected_src[e]][h_expected_dst[e]] = 1; - for (size_t e = h_result_offsets[i]; (e < h_result_offsets[i + 1]) && (test_ret_value == 0); - ++e) { - TEST_ASSERT( - test_ret_value, (M[h_result_src[e]][h_result_dst[e]] > 0), "found different edges"); + for (size_t e = h_result_offsets[i] ; (e < h_result_offsets[i+1]) && (test_ret_value == 0) ; ++e) { + TEST_ASSERT(test_ret_value, (M[h_result_src[e]][h_result_dst[e]] > 0), "found different edges"); } } @@ -159,7 +159,7 @@ int generic_egonet_test(const cugraph_resource_handle_t* resource_handle, return test_ret_value; } -int test_egonet(const cugraph_resource_handle_t* resource_handle) +int test_egonet(const cugraph_resource_handle_t *resource_handle) { size_t num_edges = 9; size_t num_vertices = 6; diff --git a/cpp/tests/c_api/mg_eigenvector_centrality_test.c b/cpp/tests/c_api/mg_eigenvector_centrality_test.c index 3cb5fec46ef..56a5c3911a2 100644 --- a/cpp/tests/c_api/mg_eigenvector_centrality_test.c +++ b/cpp/tests/c_api/mg_eigenvector_centrality_test.c @@ -101,12 +101,20 @@ int test_eigenvector_centrality(const cugraph_resource_handle_t* handle) 0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f, 0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; weight_t h_result[] = {0.236374, 0.292046, 0.458369, 0.605472, 0.190544, 0.495814}; - double epsilon = 1e-6; + double epsilon = 1e-6; size_t max_iterations = 200; // Eigenvector centrality wants store_transposed = TRUE - return generic_eigenvector_centrality_test( - handle, h_src, h_dst, h_wgt, h_result, num_vertices, num_edges, TRUE, epsilon, max_iterations); + return generic_eigenvector_centrality_test(handle, + h_src, + h_dst, + h_wgt, + h_result, + num_vertices, + num_edges, + TRUE, + epsilon, + max_iterations); } /******************************************************************************/ diff --git a/cpp/tests/c_api/mg_induced_subgraph_test.c b/cpp/tests/c_api/mg_induced_subgraph_test.c index 448c7c5126b..6d902cc7bae 100644 --- a/cpp/tests/c_api/mg_induced_subgraph_test.c +++ b/cpp/tests/c_api/mg_induced_subgraph_test.c @@ -57,9 +57,9 @@ int generic_induced_subgraph_test(const cugraph_resource_handle_t* handle, cugraph_induced_subgraph_result_t* result = NULL; - data_type_id_t vertex_tid = INT32; - data_type_id_t size_t_tid = SIZE_T; - size_t num_subgraph_vertices = h_subgraph_offsets[num_subgraph_offsets - 1]; + data_type_id_t vertex_tid = INT32; + data_type_id_t size_t_tid = SIZE_T; + size_t num_subgraph_vertices = h_subgraph_offsets[num_subgraph_offsets-1]; ret_code = create_mg_test_graph( handle, h_src, h_dst, h_wgt, num_edges, store_transposed, FALSE, &graph, &ret_error); @@ -69,7 +69,7 @@ int generic_induced_subgraph_test(const cugraph_resource_handle_t* handle, if (cugraph_resource_handle_get_rank(handle) != 0) { num_subgraph_vertices = 0; - for (int i = 0; i < num_subgraph_offsets; ++i) { + for (int i = 0 ; i < num_subgraph_offsets ; ++i) { h_subgraph_offsets[i] = 0; } } @@ -78,8 +78,11 @@ int generic_induced_subgraph_test(const cugraph_resource_handle_t* handle, handle, num_subgraph_offsets, size_t_tid, &subgraph_offsets, &ret_error); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "subgraph_offsets create failed."); - ret_code = cugraph_type_erased_device_array_create( - handle, num_subgraph_vertices, vertex_tid, &subgraph_vertices, &ret_error); + ret_code = cugraph_type_erased_device_array_create(handle, + num_subgraph_vertices, + vertex_tid, + &subgraph_vertices, + &ret_error); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "subgraph_offsets create failed."); subgraph_offsets_view = cugraph_type_erased_device_array_view(subgraph_offsets); @@ -99,7 +102,7 @@ int generic_induced_subgraph_test(const cugraph_resource_handle_t* handle, graph, subgraph_offsets_view, subgraph_vertices_view, - // FALSE, + //FALSE, TRUE, &result, &ret_error); @@ -112,9 +115,9 @@ int generic_induced_subgraph_test(const cugraph_resource_handle_t* handle, cugraph_type_erased_device_array_view_t* extracted_wgt; cugraph_type_erased_device_array_view_t* extracted_graph_offsets; - extracted_src = cugraph_induced_subgraph_get_sources(result); - extracted_dst = cugraph_induced_subgraph_get_destinations(result); - extracted_wgt = cugraph_induced_subgraph_get_edge_weights(result); + extracted_src = cugraph_induced_subgraph_get_sources(result); + extracted_dst = cugraph_induced_subgraph_get_destinations(result); + extracted_wgt = cugraph_induced_subgraph_get_edge_weights(result); extracted_graph_offsets = cugraph_induced_subgraph_get_subgraph_offsets(result); size_t extracted_size = cugraph_type_erased_device_array_view_size(extracted_src); diff --git a/cpp/tests/c_api/mg_katz_test.c b/cpp/tests/c_api/mg_katz_test.c index 0f7e95bd69d..ca2de1bb194 100644 --- a/cpp/tests/c_api/mg_katz_test.c +++ b/cpp/tests/c_api/mg_katz_test.c @@ -43,8 +43,8 @@ int generic_katz_test(const cugraph_resource_handle_t* handle, cugraph_error_code_t ret_code = CUGRAPH_SUCCESS; cugraph_error_t* ret_error; - cugraph_graph_t* p_graph = NULL; - cugraph_centrality_result_t* p_result = NULL; + cugraph_graph_t* p_graph = NULL; + cugraph_centrality_result_t* p_result = NULL; cugraph_type_erased_device_array_view_t* betas_view = NULL; ret_code = create_mg_test_graph( @@ -71,7 +71,7 @@ int generic_katz_test(const cugraph_resource_handle_t* handle, cugraph_type_erased_device_array_view_t* vertices; cugraph_type_erased_device_array_view_t* centralities; - vertices = cugraph_centrality_result_get_vertices(p_result); + vertices = cugraph_centrality_result_get_vertices(p_result); centralities = cugraph_centrality_result_get_values(p_result); vertex_t h_vertices[num_vertices]; diff --git a/cpp/tests/c_api/mg_pagerank_test.c b/cpp/tests/c_api/mg_pagerank_test.c index e005b53d709..8ac0c3070f5 100644 --- a/cpp/tests/c_api/mg_pagerank_test.c +++ b/cpp/tests/c_api/mg_pagerank_test.c @@ -50,18 +50,8 @@ int generic_pagerank_test(const cugraph_resource_handle_t* handle, TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "create_mg_test_graph failed."); - ret_code = cugraph_pagerank(handle, - p_graph, - NULL, - NULL, - NULL, - NULL, - alpha, - epsilon, - max_iterations, - FALSE, - &p_result, - &ret_error); + ret_code = cugraph_pagerank( + handle, p_graph, NULL, NULL, NULL, NULL, alpha, epsilon, max_iterations, FALSE, &p_result, &ret_error); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "cugraph_pagerank failed."); // NOTE: Because we get back vertex ids and pageranks, we can simply compare @@ -100,7 +90,7 @@ int generic_pagerank_test(const cugraph_resource_handle_t* handle, return test_ret_value; } -int generic_personalized_pagerank_test(const cugraph_resource_handle_t* handle, +int generic_personalized_pagerank_test(const cugraph_resource_handle_t *handle, vertex_t* h_src, vertex_t* h_dst, weight_t* h_wgt, @@ -136,7 +126,9 @@ int generic_personalized_pagerank_test(const cugraph_resource_handle_t* handle, TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "create_test_graph failed."); TEST_ALWAYS_ASSERT(ret_code == CUGRAPH_SUCCESS, cugraph_error_message(ret_error)); - if (cugraph_resource_handle_get_rank(handle) != 0) { num_personalization_vertices = 0; } + if (cugraph_resource_handle_get_rank(handle) != 0) { + num_personalization_vertices = 0; + } ret_code = cugraph_type_erased_device_array_create( handle, num_personalization_vertices, vertex_tid, &personalization_vertices, &ret_error); @@ -209,6 +201,7 @@ int generic_personalized_pagerank_test(const cugraph_resource_handle_t* handle, return test_ret_value; } + int test_pagerank(const cugraph_resource_handle_t* handle) { size_t num_edges = 8; diff --git a/cpp/tests/c_api/mg_random_walks_test.c b/cpp/tests/c_api/mg_random_walks_test.c index 63ca7cfc167..753f7c8a89b 100644 --- a/cpp/tests/c_api/mg_random_walks_test.c +++ b/cpp/tests/c_api/mg_random_walks_test.c @@ -121,10 +121,11 @@ int generic_uniform_random_walks_test(const cugraph_resource_handle_t* handle, "uniform_random_walks found no edge when an edge exists"); } } else { - TEST_ASSERT(test_ret_value, - M[h_result_verts[src_index]][h_result_verts[dst_index]] == - h_result_wgts[i * max_depth + j], - "uniform_random_walks got edge that doesn't exist"); + TEST_ASSERT( + test_ret_value, + M[h_result_verts[src_index]][h_result_verts[dst_index]] == + h_result_wgts[i * max_depth + j], + "uniform_random_walks got edge that doesn't exist"); } } } diff --git a/cpp/tests/c_api/mg_similarity_test.c b/cpp/tests/c_api/mg_similarity_test.c index e94b62b3ffd..5f6c8881127 100644 --- a/cpp/tests/c_api/mg_similarity_test.c +++ b/cpp/tests/c_api/mg_similarity_test.c @@ -42,7 +42,7 @@ int generic_similarity_test(const cugraph_resource_handle_t* handle, bool_t use_weight, similarity_t test_type) { - int test_ret_value = 0; + int test_ret_value = 0; data_type_id_t vertex_tid = INT32; cugraph_error_code_t ret_code = CUGRAPH_SUCCESS; @@ -62,7 +62,9 @@ int generic_similarity_test(const cugraph_resource_handle_t* handle, TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "create_test_graph failed."); TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, cugraph_error_message(ret_error)); - if (cugraph_resource_handle_get_rank(handle) != 0) { num_pairs = 0; } + if (cugraph_resource_handle_get_rank(handle) != 0) { + num_pairs = 0; + } ret_code = cugraph_type_erased_device_array_create(handle, num_pairs, vertex_tid, &v1, &ret_error); @@ -326,9 +328,9 @@ int main(int argc, char** argv) result |= RUN_MG_TEST(test_jaccard, handle); result |= RUN_MG_TEST(test_sorensen, handle); result |= RUN_MG_TEST(test_overlap, handle); - // result |= RUN_MG_TEST(test_weighted_jaccard, handle); - // result |= RUN_MG_TEST(test_weighted_sorensen, handle); - // result |= RUN_MG_TEST(test_weighted_overlap, handle); + //result |= RUN_MG_TEST(test_weighted_jaccard, handle); + //result |= RUN_MG_TEST(test_weighted_sorensen, handle); + //result |= RUN_MG_TEST(test_weighted_overlap, handle); cugraph_free_resource_handle(handle); } diff --git a/cpp/tests/c_api/mg_sssp_test.c b/cpp/tests/c_api/mg_sssp_test.c index 3cfab05550c..6392addc397 100644 --- a/cpp/tests/c_api/mg_sssp_test.c +++ b/cpp/tests/c_api/mg_sssp_test.c @@ -101,16 +101,16 @@ int generic_sssp_test(const cugraph_resource_handle_t* p_handle, } int generic_sssp_test_double(const cugraph_resource_handle_t* p_handle, - vertex_t* h_src, - vertex_t* h_dst, - double* h_wgt, - vertex_t source, - double const* expected_distances, - vertex_t const* expected_predecessors, - size_t num_vertices, - size_t num_edges, - double cutoff, - bool_t store_transposed) + vertex_t* h_src, + vertex_t* h_dst, + double* h_wgt, + vertex_t source, + double const* expected_distances, + vertex_t const* expected_predecessors, + size_t num_vertices, + size_t num_edges, + double cutoff, + bool_t store_transposed) { int test_ret_value = 0; @@ -180,8 +180,8 @@ int test_sssp(const cugraph_resource_handle_t* p_handle) vertex_t src[] = {0, 1, 1, 2, 2, 2, 3, 4}; vertex_t dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; - float wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; - float expected_distances[] = {0.0f, 0.1f, FLT_MAX, 2.2f, 1.2f, 4.4f}; + float wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; + float expected_distances[] = {0.0f, 0.1f, FLT_MAX, 2.2f, 1.2f, 4.4f}; vertex_t expected_predecessors[] = {-1, 0, -1, 1, 1, 4}; // Bfs wants store_transposed = FALSE @@ -205,8 +205,8 @@ int test_sssp_with_transpose(const cugraph_resource_handle_t* p_handle) vertex_t src[] = {0, 1, 1, 2, 2, 2, 3, 4}; vertex_t dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; - float wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; - float expected_distances[] = {0.0f, 0.1f, FLT_MAX, 2.2f, 1.2f, 4.4f}; + float wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; + float expected_distances[] = {0.0f, 0.1f, FLT_MAX, 2.2f, 1.2f, 4.4f}; vertex_t expected_predecessors[] = {-1, 0, -1, 1, 1, 4}; // Bfs wants store_transposed = FALSE @@ -231,23 +231,23 @@ int test_sssp_with_transpose_double(const cugraph_resource_handle_t* p_handle) vertex_t src[] = {0, 1, 1, 2, 2, 2, 3, 4}; vertex_t dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; - double wgt[] = {0.1d, 2.1d, 1.1d, 5.1d, 3.1d, 4.1d, 7.2d, 3.2d}; - double expected_distances[] = {0.0d, 0.1d, DBL_MAX, 2.2d, 1.2d, 4.4d}; + double wgt[] = {0.1d, 2.1d, 1.1d, 5.1d, 3.1d, 4.1d, 7.2d, 3.2d}; + double expected_distances[] = {0.0d, 0.1d, DBL_MAX, 2.2d, 1.2d, 4.4d}; vertex_t expected_predecessors[] = {-1, 0, -1, 1, 1, 4}; // Bfs wants store_transposed = FALSE // This call will force cugraph_sssp to transpose the graph return generic_sssp_test_double(p_handle, - src, - dst, - wgt, - 0, - expected_distances, - expected_predecessors, - num_vertices, - num_edges, - 10, - TRUE); + src, + dst, + wgt, + 0, + expected_distances, + expected_predecessors, + num_vertices, + num_edges, + 10, + TRUE); } /******************************************************************************/ diff --git a/cpp/tests/c_api/mg_strongly_connected_components_test.c b/cpp/tests/c_api/mg_strongly_connected_components_test.c index 894b6996303..f7659b8023a 100644 --- a/cpp/tests/c_api/mg_strongly_connected_components_test.c +++ b/cpp/tests/c_api/mg_strongly_connected_components_test.c @@ -48,8 +48,7 @@ int generic_scc_test(const cugraph_resource_handle_t* handle, TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "create_mg_test_graph failed."); ret_code = cugraph_strongly_connected_components(handle, p_graph, FALSE, &p_result, &ret_error); - TEST_ASSERT( - test_ret_value, ret_code == CUGRAPH_NOT_IMPLEMENTED, "SCC should not be implemented, but is"); + TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_NOT_IMPLEMENTED, "SCC should not be implemented, but is"); #if 0 // FIXME: Actual implementation will be something like this diff --git a/cpp/tests/c_api/mg_triangle_count_test.c b/cpp/tests/c_api/mg_triangle_count_test.c index a5f7c61b3c4..9b367f81b51 100644 --- a/cpp/tests/c_api/mg_triangle_count_test.c +++ b/cpp/tests/c_api/mg_triangle_count_test.c @@ -95,7 +95,7 @@ int generic_triangle_count_test(const cugraph_resource_handle_t* handle, TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "copy_to_host failed."); for (int i = 0; (i < num_local_results) && (test_ret_value == 0); ++i) { - for (int j = 0; j < num_results; ++j) { + for (int j = 0 ; j < num_results ; ++j) { if (h_vertices[i] == h_verts[j]) { TEST_ASSERT(test_ret_value, h_counts[i] == h_result[j], "counts results don't match"); } diff --git a/cpp/tests/c_api/node2vec_test.c b/cpp/tests/c_api/node2vec_test.c index 574ed02e5a4..701d4923fe1 100644 --- a/cpp/tests/c_api/node2vec_test.c +++ b/cpp/tests/c_api/node2vec_test.c @@ -205,36 +205,21 @@ int test_node2vec_short_sparse() int test_node2vec_karate() { - size_t num_edges = 156; + size_t num_edges = 156; size_t num_vertices = 34; - vertex_t src[] = {1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 17, 19, 21, 31, 2, 3, 7, 13, - 17, 19, 21, 30, 3, 7, 8, 9, 13, 27, 28, 32, 7, 12, 13, 6, 10, 6, 10, 16, - 16, 30, 32, 33, 33, 33, 32, 33, 32, 33, 32, 33, 33, 32, 33, 32, 33, 25, 27, 29, - 32, 33, 25, 27, 31, 31, 29, 33, 33, 31, 33, 32, 33, 32, 33, 32, 33, 33, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, - 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 8, - 8, 8, 9, 13, 14, 14, 15, 15, 18, 18, 19, 20, 20, 22, 22, 23, 23, 23, 23, 23, - 24, 24, 24, 25, 26, 26, 27, 28, 28, 29, 29, 30, 30, 31, 31, 32}; - vertex_t dst[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, - 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, - 6, 8, 8, 8, 9, 13, 14, 14, 15, 15, 18, 18, 19, 20, 20, 22, 22, 23, 23, 23, - 23, 23, 24, 24, 24, 25, 26, 26, 27, 28, 28, 29, 29, 30, 30, 31, 31, 32, 1, 2, - 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 17, 19, 21, 31, 2, 3, 7, 13, 17, 19, - 21, 30, 3, 7, 8, 9, 13, 27, 28, 32, 7, 12, 13, 6, 10, 6, 10, 16, 16, 30, - 32, 33, 33, 33, 32, 33, 32, 33, 32, 33, 33, 32, 33, 32, 33, 25, 27, 29, 32, 33, - 25, 27, 31, 31, 29, 33, 33, 31, 33, 32, 33, 32, 33, 32, 33, 33}; - weight_t wgt[] = { - 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, - 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, - 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, - 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, - 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, - 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, - 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, - 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, - 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, - 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}; + vertex_t src[] = {1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 17, 19, 21, 31, 2, + 3, 7, 13, 17, 19, 21, 30, 3, 7, 8, 9, 13, 27, 28, 32, 7, 12, + 13, 6, 10, 6, 10, 16, 16, 30, 32, 33, 33, 33, 32, 33, 32, + 33, 32, 33, 33, 32, 33, 32, 33, 25, 27, 29, 32, 33, 25, 27, + 31, 31, 29, 33, 33, 31, 33, 32, 33, 32, 33, 32, 33, 33, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, + 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, + 8, 8, 8, 9, 13, 14, 14, 15, 15, 18, 18, 19, 20, 20, 22, 22, + 23, 23, 23, 23, 23, 24, 24, 24, 25, 26, 26, 27, 28, 28, 29, + 29, 30, 30, 31, 31, 32}; + vertex_t dst[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,4,4,5,5,5,6,8,8,8,9,13,14,14,15,15,18,18,19,20,20,22,22,23,23,23,23,23,24,24,24,25,26,26,27,28,28,29,29,30,30,31,31,32,1,2,3,4,5,6,7,8,10,11,12,13,17,19,21,31,2,3,7,13,17,19,21,30,3,7,8,9,13,27,28,32,7,12,13,6,10,6,10,16,16,30,32,33,33,33,32,33,32,33,32,33,33,32,33,32,33,25,27,29,32,33,25,27,31,31,29,33,33,31,33,32,33,32,33,32,33,33}; + weight_t wgt[] = {1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f}; vertex_t seeds[] = {12, 28, 20, 23, 15, 26}; size_t max_depth = 5; diff --git a/cpp/tests/c_api/random_walks_test.c b/cpp/tests/c_api/random_walks_test.c index d40d74c77e6..be500b2cd91 100644 --- a/cpp/tests/c_api/random_walks_test.c +++ b/cpp/tests/c_api/random_walks_test.c @@ -39,8 +39,8 @@ int test_random_walks_1() typedef float weight_t; cugraph_error_code_t ret_code = CUGRAPH_SUCCESS; - size_t num_edges = 8; - size_t num_vertices = 6; + size_t num_edges = 8; + size_t num_vertices = 6; vertex_t h_src[] = {0, 1, 1, 2, 2, 2, 3, 4}; vertex_t h_dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; @@ -192,8 +192,8 @@ int test_random_walks_2() typedef float weight_t; cugraph_error_code_t ret_code = CUGRAPH_SUCCESS; - size_t num_edges = 8; - size_t num_vertices = 6; + size_t num_edges = 8; + size_t num_vertices = 6; vertex_t h_src[] = {0, 1, 1, 2, 2, 2, 3, 4}; vertex_t h_dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; @@ -319,8 +319,8 @@ int test_random_walks_3() typedef float weight_t; cugraph_error_code_t ret_code = CUGRAPH_SUCCESS; - size_t num_edges = 8; - size_t num_vertices = 6; + size_t num_edges = 8; + size_t num_vertices = 6; vertex_t h_src[] = {0, 1, 1, 2, 2, 2, 3, 4}; vertex_t h_dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; diff --git a/cpp/tests/c_api/sg_random_walks_test.c b/cpp/tests/c_api/sg_random_walks_test.c index 225c71247e7..7b07967e3c9 100644 --- a/cpp/tests/c_api/sg_random_walks_test.c +++ b/cpp/tests/c_api/sg_random_walks_test.c @@ -125,10 +125,11 @@ int generic_uniform_random_walks_test(vertex_t* h_src, "uniform_random_walks found no edge when an edge exists"); } } else { - TEST_ASSERT(test_ret_value, - M[h_result_verts[src_index]][h_result_verts[dst_index]] == - h_result_wgts[i * max_depth + j], - "uniform_random_walks got edge that doesn't exist"); + TEST_ASSERT( + test_ret_value, + M[h_result_verts[src_index]][h_result_verts[dst_index]] == + h_result_wgts[i * max_depth + j], + "uniform_random_walks got edge that doesn't exist"); } } } diff --git a/cpp/tests/c_api/sssp_test.c b/cpp/tests/c_api/sssp_test.c index 48039fcb43c..1113ed88e14 100644 --- a/cpp/tests/c_api/sssp_test.c +++ b/cpp/tests/c_api/sssp_test.c @@ -102,15 +102,15 @@ int generic_sssp_test(vertex_t* h_src, } int generic_sssp_test_double(vertex_t* h_src, - vertex_t* h_dst, - double* h_wgt, - vertex_t source, - double const* expected_distances, - vertex_t const* expected_predecessors, - size_t num_vertices, - size_t num_edges, - double cutoff, - bool_t store_transposed) + vertex_t* h_dst, + double* h_wgt, + vertex_t source, + double const* expected_distances, + vertex_t const* expected_predecessors, + size_t num_vertices, + size_t num_edges, + double cutoff, + bool_t store_transposed) { int test_ret_value = 0; @@ -182,8 +182,8 @@ int test_sssp() vertex_t src[] = {0, 1, 1, 2, 2, 2, 3, 4}; vertex_t dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; - float wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; - float expected_distances[] = {0.0f, 0.1f, FLT_MAX, 2.2f, 1.2f, 4.4f}; + float wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; + float expected_distances[] = {0.0f, 0.1f, FLT_MAX, 2.2f, 1.2f, 4.4f}; vertex_t expected_predecessors[] = {-1, 0, -1, 1, 1, 4}; // Bfs wants store_transposed = FALSE @@ -206,8 +206,8 @@ int test_sssp_with_transpose() vertex_t src[] = {0, 1, 1, 2, 2, 2, 3, 4}; vertex_t dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; - float wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; - float expected_distances[] = {0.0f, 0.1f, FLT_MAX, 2.2f, 1.2f, 4.4f}; + float wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f}; + float expected_distances[] = {0.0f, 0.1f, FLT_MAX, 2.2f, 1.2f, 4.4f}; vertex_t expected_predecessors[] = {-1, 0, -1, 1, 1, 4}; // Bfs wants store_transposed = FALSE @@ -223,8 +223,8 @@ int test_sssp_with_transpose_double() vertex_t src[] = {0, 1, 1, 2, 2, 2, 3, 4}; vertex_t dst[] = {1, 3, 4, 0, 1, 3, 5, 5}; - double wgt[] = {0.1d, 2.1d, 1.1d, 5.1d, 3.1d, 4.1d, 7.2d, 3.2d}; - double expected_distances[] = {0.0d, 0.1d, DBL_MAX, 2.2d, 1.2d, 4.4d}; + double wgt[] = {0.1d, 2.1d, 1.1d, 5.1d, 3.1d, 4.1d, 7.2d, 3.2d}; + double expected_distances[] = {0.0d, 0.1d, DBL_MAX, 2.2d, 1.2d, 4.4d}; vertex_t expected_predecessors[] = {-1, 0, -1, 1, 1, 4}; // Bfs wants store_transposed = FALSE diff --git a/cpp/tests/c_api/strongly_connected_components_test.c b/cpp/tests/c_api/strongly_connected_components_test.c index 5a9110cf2a5..51e27e4f469 100644 --- a/cpp/tests/c_api/strongly_connected_components_test.c +++ b/cpp/tests/c_api/strongly_connected_components_test.c @@ -52,8 +52,7 @@ int generic_scc_test(vertex_t* h_src, TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, cugraph_error_message(ret_error)); ret_code = cugraph_strongly_connected_components(p_handle, p_graph, FALSE, &p_result, &ret_error); - TEST_ASSERT( - test_ret_value, ret_code == CUGRAPH_NOT_IMPLEMENTED, "SCC should not be implemented, but is"); + TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_NOT_IMPLEMENTED, "SCC should not be implemented, but is"); #if 0 // FIXME: Actual implementation will be something like this diff --git a/cpp/tests/c_api/triangle_count_test.c b/cpp/tests/c_api/triangle_count_test.c index 5929e3d6560..a9fc0cbb292 100644 --- a/cpp/tests/c_api/triangle_count_test.c +++ b/cpp/tests/c_api/triangle_count_test.c @@ -96,7 +96,8 @@ int generic_triangle_count_test(vertex_t* h_src, TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "copy_to_host failed."); for (int i = 0; (i < num_local_results) && (test_ret_value == 0); ++i) { - TEST_ASSERT(test_ret_value, h_result[i] == h_counts[i], "counts results don't match"); + TEST_ASSERT( + test_ret_value, h_result[i] == h_counts[i], "counts results don't match"); } cugraph_triangle_count_result_free(p_result); From 95accc9e4d13e7a118db5bb85f9dafe568bb3751 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Fri, 9 Dec 2022 14:05:12 -0600 Subject: [PATCH 6/8] Update copyright script. --- ci/checks/copyright.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/checks/copyright.py b/ci/checks/copyright.py index 83f43183f71..0f2540c440c 100644 --- a/ci/checks/copyright.py +++ b/ci/checks/copyright.py @@ -68,8 +68,8 @@ def modifiedFiles(): we can read only the staged changes. """ repo = git.Repo() - # Use the environment variable TARGET_BRANCH (defined in CI) if possible - target_branch = os.environ.get("TARGET_BRANCH") + # Use the environment variable TARGET_BRANCH or RAPIDS_BASE_BRANCH (defined in CI) if possible + target_branch = os.environ.get("TARGET_BRANCH", os.environ.get("RAPIDS_BASE_BRANCH")) if target_branch is None: # Fall back to the closest branch if not on CI target_branch = repo.git.describe( From 05f37325dd040dfb9c2dc7412c9de6494293657d Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Fri, 9 Dec 2022 14:09:39 -0600 Subject: [PATCH 7/8] Enable clang-format with excludes that were missing from run-clang-format.py. --- .pre-commit-config.yaml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5c158d15551..a075beea3f3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,12 +32,17 @@ repos: - id: yesqa additional_dependencies: - flake8==6.0.0 -# - repo: https://github.com/pre-commit/mirrors-clang-format -# rev: v11.1.0 -# hooks: -# - id: clang-format -# types_or: [c, c++, cuda] -# args: ["-fallback-style=none", "-style=file", "-i"] + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v11.1.0 + hooks: + - id: clang-format + exclude: | + (?x)^( + cpp/libcugraph_etl| + cpp/tests/c_api/.* + ) + types_or: [c, c++, cuda] + args: ["-fallback-style=none", "-style=file", "-i"] - repo: local hooks: - id: copyright-check From 752412d86e5da6be0389a469840265ec9a56ff0f Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Wed, 14 Dec 2022 10:57:42 -0600 Subject: [PATCH 8/8] Update copyright check script. --- ci/checks/copyright.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/ci/checks/copyright.py b/ci/checks/copyright.py index 0f2540c440c..407204f6a38 100644 --- a/ci/checks/copyright.py +++ b/ci/checks/copyright.py @@ -24,13 +24,11 @@ FilesToCheck = [ re.compile(r"[.](cmake|cpp|cu|cuh|h|hpp|sh|pxd|py|pyx)$"), re.compile(r"CMakeLists[.]txt$"), - re.compile(r"CMakeLists_standalone[.]txt$"), re.compile(r"setup[.]cfg$"), re.compile(r"[.]flake8[.]cython$"), re.compile(r"meta[.]yaml$"), ] ExemptFiles = [ - re.compile(r"cpp/include/cudf_test/cxxopts.hpp"), re.compile(r"versioneer[.]py"), ]