Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

random_walk implementation #21

Merged
merged 26 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions cmake/test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

enable_testing()
FILE(GLOB cpp_tests test/csrc/test_*.cpp)

include(GoogleTest)
foreach(t ${cpp_tests})

set(CTEST test/csrc)
file(GLOB_RECURSE ALL_TESTS ${CTEST}/*.cpp)

foreach(t ${ALL_TESTS})
get_filename_component(name ${t} NAME_WE)
add_executable(${name} ${t})
target_link_libraries(${name} ${PROJECT_NAME} gtest_main)
Expand Down
28 changes: 28 additions & 0 deletions pyg_lib/csrc/sampler/random_walk.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "random_walk.h"

#include <ATen/core/dispatch/Dispatcher.h>
#include <torch/library.h>

namespace pyg {
namespace sampler {

at::Tensor random_walk(const at::Tensor& rowptr,
const at::Tensor& col,
const at::Tensor& seed,
int64_t walk_length,
double p,
double q) {
static auto op = c10::Dispatcher::singleton()
rusty1s marked this conversation as resolved.
Show resolved Hide resolved
rusty1s marked this conversation as resolved.
Show resolved Hide resolved
.findSchemaOrThrow("pyg::random_walk", "")
.typed<decltype(random_walk)>();
return op.call(rowptr, col, seed, walk_length, p, q);
}

TORCH_LIBRARY_FRAGMENT(pyg, m) {
m.def(TORCH_SELECTIVE_SCHEMA(
"pyg::random_walk(Tensor rowptr, Tensor col, Tensor seed, int "
"walk_length, float p, float q) -> Tensor"));
}

} // namespace sampler
} // namespace pyg
17 changes: 17 additions & 0 deletions pyg_lib/csrc/sampler/random_walk.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <ATen/ATen.h>
#include "../macros.h"

namespace pyg {
namespace sampler {

PYG_API at::Tensor random_walk(const at::Tensor& rowptr,
const at::Tensor& col,
const at::Tensor& seed,
int64_t walk_length,
double p,
double q);

} // namespace sampler
} // namespace pyg
9 changes: 9 additions & 0 deletions test/csrc/sampler/test_random_walk.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <gtest/gtest.h>

#include "../../../pyg_lib/csrc/sampler/random_walk.h"

#include <iostream>

TEST(RandomWalkTest, BasicAssertions) {
std::cout << "random walk test" << std::endl;
}