mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-12-22 23:30:35 +08:00
Address black + isort fbsource linter warnings
Summary: Address black + isort fbsource linter warnings from D20558374 (previous diff) Reviewed By: nikhilaravi Differential Revision: D20558373 fbshipit-source-id: d3607de4a01fb24c0d5269634563a7914bddf1c8
This commit is contained in:
committed by
Facebook GitHub Bot
parent
eb512ffde3
commit
d57daa6f85
@@ -2,11 +2,10 @@
|
||||
|
||||
|
||||
import unittest
|
||||
|
||||
import torch
|
||||
|
||||
from pytorch3d.structures import utils as struct_utils
|
||||
|
||||
from common_testing import TestCaseMixin
|
||||
from pytorch3d.structures import utils as struct_utils
|
||||
|
||||
|
||||
class TestStructUtils(TestCaseMixin, unittest.TestCase):
|
||||
@@ -27,22 +26,16 @@ class TestStructUtils(TestCaseMixin, unittest.TestCase):
|
||||
self.assertEqual(x_padded.shape[1], K)
|
||||
self.assertEqual(x_padded.shape[2], K)
|
||||
for i in range(N):
|
||||
self.assertClose(
|
||||
x_padded[i, : x[i].shape[0], : x[i].shape[1]], x[i]
|
||||
)
|
||||
self.assertClose(x_padded[i, : x[i].shape[0], : x[i].shape[1]], x[i])
|
||||
|
||||
# check for no pad size (defaults to max dimension)
|
||||
x_padded = struct_utils.list_to_padded(
|
||||
x, pad_value=0.0, equisized=False
|
||||
)
|
||||
x_padded = struct_utils.list_to_padded(x, pad_value=0.0, equisized=False)
|
||||
max_size0 = max(y.shape[0] for y in x)
|
||||
max_size1 = max(y.shape[1] for y in x)
|
||||
self.assertEqual(x_padded.shape[1], max_size0)
|
||||
self.assertEqual(x_padded.shape[2], max_size1)
|
||||
for i in range(N):
|
||||
self.assertClose(
|
||||
x_padded[i, : x[i].shape[0], : x[i].shape[1]], x[i]
|
||||
)
|
||||
self.assertClose(x_padded[i, : x[i].shape[0], : x[i].shape[1]], x[i])
|
||||
|
||||
# check for equisized
|
||||
x = [torch.rand((K, 10), device=device) for _ in range(N)]
|
||||
@@ -88,9 +81,7 @@ class TestStructUtils(TestCaseMixin, unittest.TestCase):
|
||||
split_size = torch.randint(1, K, size=(2 * N,)).view(N, 2).unbind(0)
|
||||
x_list = struct_utils.padded_to_list(x, split_size)
|
||||
for i in range(N):
|
||||
self.assertClose(
|
||||
x_list[i], x[i, : split_size[i][0], : split_size[i][1]]
|
||||
)
|
||||
self.assertClose(x_list[i], x[i, : split_size[i][0], : split_size[i][1]])
|
||||
|
||||
with self.assertRaisesRegex(ValueError, "Supports only"):
|
||||
x = torch.rand((N, K, K, K, K), device=device)
|
||||
@@ -124,32 +115,24 @@ class TestStructUtils(TestCaseMixin, unittest.TestCase):
|
||||
# Add some random values in the input which are the same as the pad_value.
|
||||
# These should not be filtered out.
|
||||
x_list.append(
|
||||
torch.randint(
|
||||
low=pad_value, high=10, size=(dim, K), device=device
|
||||
)
|
||||
torch.randint(low=pad_value, high=10, size=(dim, K), device=device)
|
||||
)
|
||||
split_size.append(dim)
|
||||
x_padded = struct_utils.list_to_padded(x_list, pad_value=pad_value)
|
||||
x_packed = struct_utils.padded_to_packed(x_padded, pad_value=pad_value)
|
||||
curr = 0
|
||||
for i in range(N):
|
||||
self.assertClose(
|
||||
x_packed[curr : curr + split_size[i], ...], x_list[i]
|
||||
)
|
||||
self.assertClose(x_packed[curr : curr + split_size[i], ...], x_list[i])
|
||||
self.assertClose(torch.cat(x_list), x_packed)
|
||||
curr += split_size[i]
|
||||
|
||||
# Case 3: split_size is provided.
|
||||
# Check each section of the packed tensor matches the corresponding
|
||||
# unpadded elements.
|
||||
x_packed = struct_utils.padded_to_packed(
|
||||
x_padded, split_size=split_size
|
||||
)
|
||||
x_packed = struct_utils.padded_to_packed(x_padded, split_size=split_size)
|
||||
curr = 0
|
||||
for i in range(N):
|
||||
self.assertClose(
|
||||
x_packed[curr : curr + split_size[i], ...], x_list[i]
|
||||
)
|
||||
self.assertClose(x_packed[curr : curr + split_size[i], ...], x_list[i])
|
||||
self.assertClose(torch.cat(x_list), x_packed)
|
||||
curr += split_size[i]
|
||||
|
||||
@@ -157,17 +140,13 @@ class TestStructUtils(TestCaseMixin, unittest.TestCase):
|
||||
# Raise an error.
|
||||
split_size = torch.randint(1, K, size=(2 * N,)).view(N, 2).unbind(0)
|
||||
with self.assertRaisesRegex(ValueError, "1-dimensional"):
|
||||
x_packed = struct_utils.padded_to_packed(
|
||||
x_padded, split_size=split_size
|
||||
)
|
||||
x_packed = struct_utils.padded_to_packed(x_padded, split_size=split_size)
|
||||
|
||||
split_size = torch.randint(1, K, size=(2 * N,)).view(N * 2).tolist()
|
||||
with self.assertRaisesRegex(
|
||||
ValueError, "same length as inputs first dimension"
|
||||
):
|
||||
x_packed = struct_utils.padded_to_packed(
|
||||
x_padded, split_size=split_size
|
||||
)
|
||||
x_packed = struct_utils.padded_to_packed(x_padded, split_size=split_size)
|
||||
|
||||
# Case 5: both pad_value and split_size are provided.
|
||||
# Raise an error.
|
||||
@@ -204,8 +183,6 @@ class TestStructUtils(TestCaseMixin, unittest.TestCase):
|
||||
for i in range(N):
|
||||
self.assertTrue(num_items[i] == x_dims[i])
|
||||
self.assertTrue(item_packed_first_idx[i] == cur)
|
||||
self.assertTrue(
|
||||
item_packed_to_list_idx[cur : cur + x_dims[i]].eq(i).all()
|
||||
)
|
||||
self.assertTrue(item_packed_to_list_idx[cur : cur + x_dims[i]].eq(i).all())
|
||||
self.assertClose(x_packed[cur : cur + x_dims[i]], x[i])
|
||||
cur += x_dims[i]
|
||||
|
||||
Reference in New Issue
Block a user