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

Apply clang formatting #72

Merged
merged 1 commit into from
Aug 16, 2024
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
9 changes: 4 additions & 5 deletions src/embedding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ check_shape_forward(
)
{
TORCH_CHECK(
options.exterior.size() == 4,
op, ": exterior must be a tuple of four doubles comprising a rectangle (x, y, w, h)"
options.exterior.size() == 4, op,
": exterior must be a tuple of four doubles comprising a rectangle (x, y, w, h)"
);
TORCH_CHECK(options.padding.size() == 2, op, ": padding should be comprised of 2 elements");

Expand Down Expand Up @@ -119,9 +119,8 @@ check_shape_backward(
);

TORCH_CHECK(
grad.sizes() == grad_sizes,
op,
": gradient shape (", grad.sizes(), ") should be the same as input (", input.sizes(), ")"
grad.sizes() == grad_sizes, op, ": gradient shape (", grad.sizes(),
") should be the same as input (", input.sizes(), ")"
);
}

Expand Down
24 changes: 14 additions & 10 deletions test/embedding_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ BOOST_AUTO_TEST_CASE(embedding2d_backward_grad)
auto padding = std::vector<int64_t>({1, 1});
auto exterior = std::vector<double>({0.0, 0.0, 10.0, 10.0});

auto grad_weight = embedding2d_backward(
grad, input, weight, /*padding=*/padding, /*exterior=*/exterior
);
auto grad_weight
= embedding2d_backward(grad, input, weight, /*padding=*/padding, /*exterior=*/exterior);

BOOST_REQUIRE_EQUAL(grad_weight.sizes(), weight.sizes());
// Grad of weight represents the following field:
Expand All @@ -118,17 +117,22 @@ BOOST_AUTO_TEST_CASE(embedding2d_backward_grad)
// [3]| 1| 11| 10| 11|
// [0]| [1]| [2]| [3]|

auto grad_expect = torch::tensor({
{1.0, 1.0, 0.0, 1.0},
{1.0, 11.0, 10.0, 11.0},
{0.0, 10.0, 10.0, 10.0},
{1.0, 11.0, 10.0, 11.0},
}, options);
auto grad_expect = torch::tensor(
{
{1.0, 1.0, 0.0, 1.0},
{1.0, 11.0, 10.0, 11.0},
{0.0, 10.0, 10.0, 10.0},
{1.0, 11.0, 10.0, 11.0},
},
options
);

for (auto i : c10::irange(weight.size(0))) {
for (auto j : c10::irange(weight.size(1))) {
for (auto k : c10::irange(weight.size(2))) {
BOOST_CHECK_EQUAL(grad_weight[i][j][k].item<double>(), grad_expect[i][j].item<double>());
BOOST_CHECK_EQUAL(
grad_weight[i][j][k].item<double>(), grad_expect[i][j].item<double>()
);
}
}
}
Expand Down