lint things

Summary:
Lint related fixes: Improve internal/OSS consistency. Fix the fight between black and certain pyre-ignore markers by moving them to the line before.
Use clang-format-8 automatically if present. Small number of pyre fixes.

arc doesn't run pyre at the moment, so I put back the explicit call to pyre. I don't know if there's an option somewhere to change this.

Reviewed By: nikhilaravi

Differential Revision: D19780518

fbshipit-source-id: ef1c243392322fa074130f6cff2dd8a6f7738a7f
This commit is contained in:
Jeremy Reizenstein
2020-02-21 05:03:38 -08:00
committed by Facebook Github Bot
parent 9e21659fc5
commit e491efb81f
11 changed files with 66 additions and 52 deletions

View File

@@ -8,7 +8,7 @@ import os
import pathlib
import warnings
from collections import namedtuple
from typing import List
from typing import List, Optional
import torch
from fvcore.common.file_io import PathManager
from PIL import Image
@@ -519,7 +519,7 @@ def load_mtl(f_mtl, material_names: List, data_dir: str):
return material_properties, texture_images
def save_obj(f, verts, faces, decimal_places: int = None):
def save_obj(f, verts, faces, decimal_places: Optional[int] = None):
"""
Save a mesh to an .obj file.
@@ -544,7 +544,7 @@ def save_obj(f, verts, faces, decimal_places: int = None):
# TODO (nikhilar) Speed up this function.
def _save(f, verts, faces, decimal_places: int = None):
def _save(f, verts, faces, decimal_places: Optional[int] = None):
if verts.dim() != 2 or verts.size(1) != 3:
raise ValueError("Argument 'verts' should be of shape (num_verts, 3).")
if faces.dim() != 2 or faces.size(1) != 3:

View File

@@ -63,21 +63,22 @@ def packed_to_padded(inputs, first_idxs, max_size):
Torch wrapper that handles allowed input shapes. See description below.
Args:
inputs: FloatTensor of shape (F,) or (F, D), representing the packed batch tensor.
e.g. areas for faces in a batch of meshes.
inputs: FloatTensor of shape (F,) or (F, D), representing the packed
batch tensor, e.g. areas for faces in a batch of meshes.
first_idxs: LongTensor of shape (N,) where N is the number of
elements in the batch and `first_idxs[i] = f`
means that the inputs for batch element i begin at `inputs[f]`.
max_size: Max length of an element in the batch.
Returns:
inputs_padded: FloatTensor of shape (N, max_size) or (N, max_size, D) where max_size is
max of `sizes`. The values for batch element i which start at
`inputs[first_idxs[i]]` will be copied to `inputs_padded[i, :]`,
with zeros padding out the extra inputs.
To handle the allowed input shapes, we convert the inputs tensor of shape (F,) to (F, 1).
We reshape the output back to (N, max_size) from (N, max_size, 1).
inputs_padded: FloatTensor of shape (N, max_size) or (N, max_size, D)
where max_size is max of `sizes`. The values for batch element i
which start at `inputs[first_idxs[i]]` will be copied to
`inputs_padded[i, :]`, with zeros padding out the extra inputs.
To handle the allowed input shapes, we convert the inputs tensor of shape
(F,) to (F, 1). We reshape the output back to (N, max_size) from
(N, max_size, 1).
"""
# if inputs is of shape (F,), reshape into (F, 1)
flat = False
@@ -101,8 +102,8 @@ class _PaddedToPacked(Function):
"""
Args:
ctx: Context object used to calculate gradients.
inputs: FloatTensor of shape (N, max_size, D), representing the padded tensor.
e.g. areas for faces in a batch of meshes.
inputs: FloatTensor of shape (N, max_size, D), representing
the padded tensor, e.g. areas for faces in a batch of meshes.
first_idxs: LongTensor of shape (N,) where N is the number of
elements in the batch and `first_idxs[i] = f`
means that the inputs for batch element i begin at `inputs_packed[f]`.
@@ -141,11 +142,12 @@ class _PaddedToPacked(Function):
def padded_to_packed(inputs, first_idxs, num_inputs):
"""
Torch wrapper that handles allowed input shapes. See description below.
Torch wrapper that handles allowed input shapes. See description below.
Args:
inputs: FloatTensor of shape (N, max_size) or (N, max_size, D), representing the
padded tensor. e.g. areas for faces in a batch of meshes.
inputs: FloatTensor of shape (N, max_size) or (N, max_size, D),
representing the padded tensor, e.g. areas for faces in a batch of
meshes.
first_idxs: LongTensor of shape (N,) where N is the number of
elements in the batch and `first_idxs[i] = f`
means that the inputs for batch element i begin at `inputs_packed[f]`.
@@ -155,8 +157,9 @@ def padded_to_packed(inputs, first_idxs, num_inputs):
inputs_packed: FloatTensor of shape (F,) or (F, D) where
`inputs_packed[first_idx[i]:] = inputs[i, :]`.
To handle the allowed input shapes, we convert the inputs tensor of shape (N, max_size)
to (N, max_size, 1). We reshape the output back to (F,) from (F, 1).
To handle the allowed input shapes, we convert the inputs tensor of shape
(N, max_size) to (N, max_size, 1). We reshape the output back to (F,) from
(F, 1).
"""
# if inputs is of shape (N, max_size), reshape into (N, max_size, 1))
flat = False

View File

@@ -103,9 +103,8 @@ class OpenGLPerspectiveCameras(TensorProperties):
znear = kwargs.get("znear", self.znear) # pyre-ignore[16]
zfar = kwargs.get("zfar", self.zfar) # pyre-ignore[16]
fov = kwargs.get("fov", self.fov) # pyre-ignore[16]
aspect_ratio = kwargs.get(
"aspect_ratio", self.aspect_ratio
) # pyre-ignore[16]
# pyre-ignore[16]
aspect_ratio = kwargs.get("aspect_ratio", self.aspect_ratio)
degrees = kwargs.get("degrees", self.degrees)
P = torch.zeros(
@@ -529,12 +528,10 @@ class SfMPerspectiveCameras(TensorProperties):
[0, 0, 1, 0],
]
"""
principal_point = kwargs.get(
"principal_point", self.principal_point
) # pyre-ignore[16]
focal_length = kwargs.get(
"focal_length", self.focal_length
) # pyre-ignore[16]
# pyre-ignore[16]
principal_point = kwargs.get("principal_point", self.principal_point)
# pyre-ignore[16]
focal_length = kwargs.get("focal_length", self.focal_length)
P = _get_sfm_calibration_matrix(
self._N, self.device, focal_length, principal_point, False
@@ -699,12 +696,10 @@ class SfMOrthographicCameras(TensorProperties):
[0, 0, 0, 1],
]
"""
principal_point = kwargs.get(
"principal_point", self.principal_point
) # pyre-ignore[16]
focal_length = kwargs.get(
"focal_length", self.focal_length
) # pyre-ignore[16]
# pyre-ignore[16]
principal_point = kwargs.get("principal_point", self.principal_point)
# pyre-ignore[16]
focal_length = kwargs.get("focal_length", self.focal_length)
P = _get_sfm_calibration_matrix(
self._N, self.device, focal_length, principal_point, True

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
from typing import List, Union
from typing import List, Optional, Union
import torch
import torchvision.transforms as T
@@ -81,10 +81,10 @@ def _extend_tensor(input_tensor: torch.Tensor, N: int) -> torch.Tensor:
class Textures(object):
def __init__(
self,
maps: Union[List, torch.Tensor] = None,
faces_uvs: torch.Tensor = None,
verts_uvs: torch.Tensor = None,
verts_rgb: torch.Tensor = None,
maps: Union[List, torch.Tensor, None] = None,
faces_uvs: Optional[torch.Tensor] = None,
verts_uvs: Optional[torch.Tensor] = None,
verts_rgb: Optional[torch.Tensor] = None,
):
"""
Args:
@@ -105,7 +105,7 @@ class Textures(object):
msg = "Expected verts_rgb to be of shape (N, V, 3); got %r"
raise ValueError(msg % verts_rgb.shape)
if maps is not None:
if torch.is_tensor(map) and map.ndim != 4:
if torch.is_tensor(maps) and maps.ndim != 4:
msg = "Expected maps to be of shape (N, H, W, 3); got %r"
raise ValueError(msg % repr(maps.shape))
elif isinstance(maps, list):

View File

@@ -2,6 +2,7 @@
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
import functools
from typing import Optional
import torch
@@ -246,7 +247,10 @@ def matrix_to_euler_angles(matrix, convention: str):
def random_quaternions(
n: int, dtype: torch.dtype = None, device=None, requires_grad=False
n: int,
dtype: Optional[torch.dtype] = None,
device=None,
requires_grad=False,
):
"""
Generate random quaternions representing rotations,
@@ -272,7 +276,10 @@ def random_quaternions(
def random_rotations(
n: int, dtype: torch.dtype = None, device=None, requires_grad=False
n: int,
dtype: Optional[torch.dtype] = None,
device=None,
requires_grad=False,
):
"""
Generate random rotations as 3x3 rotation matrices.
@@ -295,7 +302,7 @@ def random_rotations(
def random_rotation(
dtype: torch.dtype = None, device=None, requires_grad=False
dtype: Optional[torch.dtype] = None, device=None, requires_grad=False
):
"""
Generate a single random 3x3 rotation matrix.

View File

@@ -3,6 +3,7 @@
import math
import warnings
from typing import Optional
import torch
from .rotation_conversions import _axis_angle_rotation
@@ -250,7 +251,7 @@ class Transform3d:
out._matrix = matrix
return out
def transform_points(self, points, eps: float = None):
def transform_points(self, points, eps: Optional[float] = None):
"""
Use this transform to transform a set of 3D points. Assumes row major
ordering of the input points.