Skip to content

Commit 97acf16

Browse files
nikhilaravifacebook-github-bot
authored andcommitted
lint fixes
Summary: Ran `dev/linter.sh`. Reviewed By: bottler Differential Revision: D19761062 fbshipit-source-id: 1a49abe4a5f2bc7641b2b46e254aa77e6a48aa7d
1 parent 29cd181 commit 97acf16

File tree

3 files changed

+41
-35
lines changed

3 files changed

+41
-35
lines changed

pytorch3d/csrc/nearest_neighbor_points/nearest_neighbors_points_cpu.cpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,36 @@
33
#include <torch/extension.h>
44

55
at::Tensor NearestNeighborIdxCpu(at::Tensor p1, at::Tensor p2) {
6-
const int N = p1.size(0);
7-
const int P1 = p1.size(1);
8-
const int D = p1.size(2);
9-
const int P2 = p2.size(1);
6+
const int N = p1.size(0);
7+
const int P1 = p1.size(1);
8+
const int D = p1.size(2);
9+
const int P2 = p2.size(1);
1010

11-
auto long_opts = p1.options().dtype(torch::kInt64);
12-
torch::Tensor out = torch::empty({N, P1}, long_opts);
11+
auto long_opts = p1.options().dtype(torch::kInt64);
12+
torch::Tensor out = torch::empty({N, P1}, long_opts);
1313

14-
auto p1_a = p1.accessor<float, 3>();
15-
auto p2_a = p2.accessor<float, 3>();
16-
auto out_a = out.accessor<int64_t, 2>();
14+
auto p1_a = p1.accessor<float, 3>();
15+
auto p2_a = p2.accessor<float, 3>();
16+
auto out_a = out.accessor<int64_t, 2>();
1717

18-
for (int n = 0; n < N; ++n) {
19-
for (int i1 = 0; i1 < P1; ++i1) {
20-
// TODO: support other floating-point types?
21-
float min_dist = -1;
22-
int64_t min_idx = -1;
23-
for (int i2 = 0; i2 < P2; ++i2) {
24-
float dist = 0;
25-
for (int d = 0; d < D; ++d) {
26-
float diff = p1_a[n][i1][d] - p2_a[n][i2][d];
27-
dist += diff * diff;
28-
}
29-
if (min_dist == -1 || dist < min_dist) {
30-
min_dist = dist;
31-
min_idx = i2;
32-
}
33-
}
34-
out_a[n][i1] = min_idx;
18+
for (int n = 0; n < N; ++n) {
19+
for (int i1 = 0; i1 < P1; ++i1) {
20+
// TODO: support other floating-point types?
21+
float min_dist = -1;
22+
int64_t min_idx = -1;
23+
for (int i2 = 0; i2 < P2; ++i2) {
24+
float dist = 0;
25+
for (int d = 0; d < D; ++d) {
26+
float diff = p1_a[n][i1][d] - p2_a[n][i2][d];
27+
dist += diff * diff;
3528
}
29+
if (min_dist == -1 || dist < min_dist) {
30+
min_dist = dist;
31+
min_idx = i2;
32+
}
33+
}
34+
out_a[n][i1] = min_idx;
3635
}
37-
return out;
36+
}
37+
return out;
3838
}

scripts/parse_tutorials.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from bs4 import BeautifulSoup
1010
from nbconvert import HTMLExporter, ScriptExporter
1111

12-
1312
TEMPLATE = """const CWD = process.cwd();
1413
1514
const React = require('react');
@@ -43,7 +42,9 @@ def gen_tutorials(repo_dir: str) -> None:
4342
Also create ipynb and py versions of tutorial in Docusaurus site for
4443
download.
4544
"""
46-
with open(os.path.join(repo_dir, "website", "tutorials.json"), "r") as infile:
45+
with open(
46+
os.path.join(repo_dir, "website", "tutorials.json"), "r"
47+
) as infile:
4748
tutorial_config = json.loads(infile.read())
4849

4950
tutorial_ids = {x["id"] for v in tutorial_config.values() for x in v}
@@ -52,7 +53,9 @@ def gen_tutorials(repo_dir: str) -> None:
5253
print("Generating {} tutorial".format(tid))
5354

5455
# convert notebook to HTML
55-
ipynb_in_path = os.path.join(repo_dir, "docs", "tutorials", "{}.ipynb".format(tid))
56+
ipynb_in_path = os.path.join(
57+
repo_dir, "docs", "tutorials", "{}.ipynb".format(tid)
58+
)
5659
with open(ipynb_in_path, "r") as infile:
5760
nb_str = infile.read()
5861
nb = nbformat.reads(nb_str, nbformat.NO_CONVERT)
@@ -105,7 +108,10 @@ def gen_tutorials(repo_dir: str) -> None:
105108
description="Generate JS, HTML, ipynb, and py files for tutorials."
106109
)
107110
parser.add_argument(
108-
"--repo_dir", metavar="path", required=True, help="Pytorch3D repo directory."
111+
"--repo_dir",
112+
metavar="path",
113+
required=True,
114+
help="Pytorch3D repo directory.",
109115
)
110116
args = parser.parse_args()
111-
gen_tutorials(args.repo_dir)
117+
gen_tutorials(args.repo_dir)

tests/test_nearest_neighbor_points.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,21 @@ def test_nn_cuda(self):
4343
"""
4444
Test cuda output vs naive python implementation.
4545
"""
46-
device = torch.device('cuda:0')
46+
device = torch.device("cuda:0")
4747
self._test_nn_helper(device)
4848

4949
def test_nn_cpu(self):
5050
"""
5151
Test cpu output vs naive python implementation
5252
"""
53-
device = torch.device('cpu')
53+
device = torch.device("cpu")
5454
self._test_nn_helper(device)
5555

5656
@staticmethod
5757
def bm_nn_points_cpu_with_init(
5858
N: int = 4, D: int = 4, P1: int = 128, P2: int = 128
5959
):
60-
device = torch.device('cpu')
60+
device = torch.device("cpu")
6161
x = torch.randn(N, P1, D, device=device)
6262
y = torch.randn(N, P2, D, device=device)
6363

0 commit comments

Comments
 (0)