Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
### Added
- Added CSC mode to `pyg::sampler::neighbor_sample` and `pyg::sampler::hetero_neighbor_sample` ([#95](https://github.com/pyg-team/pyg-lib/pull/95), [#96](https://github.com/pyg-team/pyg-lib/pull/96))
- Speed up `pyg::sampler::neighbor_sample` via `IndexTracker` implementation ([#84](https://github.com/pyg-team/pyg-lib/pull/84))
- Added `pyg::sampler::hetero_neighbor_sample` implementation ([#90](https://github.com/pyg-team/pyg-lib/pull/90), [#92](https://github.com/pyg-team/pyg-lib/pull/92), [#94](https://github.com/pyg-team/pyg-lib/pull/94), [#97](https://github.com/pyg-team/pyg-lib/pull/97), [#98](https://github.com/pyg-team/pyg-lib/pull/98), [#99](https://github.com/pyg-team/pyg-lib/pull/99), [#102](https://github.com/pyg-team/pyg-lib/pull/102))
- Added `pyg::sampler::hetero_neighbor_sample` implementation ([#90](https://github.com/pyg-team/pyg-lib/pull/90), [#92](https://github.com/pyg-team/pyg-lib/pull/92), [#94](https://github.com/pyg-team/pyg-lib/pull/94), [#97](https://github.com/pyg-team/pyg-lib/pull/97), [#98](https://github.com/pyg-team/pyg-lib/pull/98), [#99](https://github.com/pyg-team/pyg-lib/pull/99), [#102](https://github.com/pyg-team/pyg-lib/pull/102), [#110](https://github.com/pyg-team/pyg-lib/pull/110))
- Added `pyg::utils::to_vector` implementation ([#88](https://github.com/pyg-team/pyg-lib/pull/88))
- Added support for PyTorch 1.12 ([#57](https://github.com/pyg-team/pyg-lib/pull/57), [#58](https://github.com/pyg-team/pyg-lib/pull/58))
- Added `grouped_matmul` and `segment_matmul` CUDA implementations via `cutlass` ([#51](https://github.com/pyg-team/pyg-lib/pull/51), [#56](https://github.com/pyg-team/pyg-lib/pull/56), [#61](https://github.com/pyg-team/pyg-lib/pull/61), [#64](https://github.com/pyg-team/pyg-lib/pull/64), [#69](https://github.com/pyg-team/pyg-lib/pull/69), [#73](https://github.com/pyg-team/pyg-lib/pull/73))
Expand Down
50 changes: 48 additions & 2 deletions test/csrc/sampler/test_neighbor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#include "pyg_lib/csrc/utils/types.h"
#include "test/csrc/graph.h"

TEST(NeighborTest, BasicAssertions) {
TEST(FullNeighborTest, BasicAssertions) {
auto options = at::TensorOptions().dtype(at::kLong);

auto graph = cycle_graph(/*num_nodes=*/6, options);
auto seed = at::arange(2, 4, options);
std::vector<int64_t> num_neighbors = {2, 2};
std::vector<int64_t> num_neighbors = {-1, -1};

auto out = pyg::sampler::neighbor_sample(/*rowptr=*/std::get<0>(graph),
/*col=*/std::get<1>(graph), seed,
Expand All @@ -26,6 +26,52 @@ TEST(NeighborTest, BasicAssertions) {
EXPECT_TRUE(at::equal(std::get<3>(out).value(), expected_edges));
}

TEST(WithoutReplacementNeighborTest, BasicAssertions) {
auto options = at::TensorOptions().dtype(at::kLong);

auto graph = cycle_graph(/*num_nodes=*/6, options);
auto seed = at::arange(2, 4, options);
std::vector<int64_t> num_neighbors = {1, 1};

at::manual_seed(123456);
auto out = pyg::sampler::neighbor_sample(
/*rowptr=*/std::get<0>(graph),
/*col=*/std::get<1>(graph), seed, num_neighbors, /*time=*/c10::nullopt,
/*csc=*/false, /*replace=*/false);

auto expected_row = at::tensor({0, 1, 2, 3}, options);
EXPECT_TRUE(at::equal(std::get<0>(out), expected_row));
auto expected_col = at::tensor({2, 3, 0, 4}, options);
EXPECT_TRUE(at::equal(std::get<1>(out), expected_col));
auto expected_nodes = at::tensor({2, 3, 1, 4, 5}, options);
EXPECT_TRUE(at::equal(std::get<2>(out), expected_nodes));
auto expected_edges = at::tensor({4, 7, 3, 9}, options);
EXPECT_TRUE(at::equal(std::get<3>(out).value(), expected_edges));
}

TEST(WithReplacementNeighborTest, BasicAssertions) {
auto options = at::TensorOptions().dtype(at::kLong);

auto graph = cycle_graph(/*num_nodes=*/6, options);
auto seed = at::arange(2, 4, options);
std::vector<int64_t> num_neighbors = {1, 1};

at::manual_seed(123456);
auto out = pyg::sampler::neighbor_sample(
/*rowptr=*/std::get<0>(graph),
/*col=*/std::get<1>(graph), seed, num_neighbors, /*time=*/c10::nullopt,
/*csc=*/false, /*replace=*/true);

auto expected_row = at::tensor({0, 1, 2, 3}, options);
EXPECT_TRUE(at::equal(std::get<0>(out), expected_row));
auto expected_col = at::tensor({2, 3, 0, 4}, options);
EXPECT_TRUE(at::equal(std::get<1>(out), expected_col));
auto expected_nodes = at::tensor({2, 3, 1, 4, 5}, options);
EXPECT_TRUE(at::equal(std::get<2>(out), expected_nodes));
auto expected_edges = at::tensor({4, 7, 3, 9}, options);
EXPECT_TRUE(at::equal(std::get<3>(out).value(), expected_edges));
}

TEST(DisjointNeighborTest, BasicAssertions) {
auto options = at::TensorOptions().dtype(at::kLong);

Expand Down