Commit 64289a49 authored by Patrick Labatut's avatar Patrick Labatut Committed by Facebook GitHub Bot
Browse files

Annotate dunder functions

Summary: Annotate the (return type of the) following dunder functions across the codebase: `__init__()`, `__len__()`, `__getitem__()`

Reviewed By: nikhilaravi

Differential Revision: D29001801

fbshipit-source-id: 928d9e1c417ffe01ab8c0445311287786e997c7c
parent 35855bf8
...@@ -36,7 +36,7 @@ class ListDataset(Dataset): ...@@ -36,7 +36,7 @@ class ListDataset(Dataset):
A simple dataset made of a list of entries. A simple dataset made of a list of entries.
""" """
def __init__(self, entries: List): def __init__(self, entries: List) -> None:
""" """
Args: Args:
entries: The list of dataset entries. entries: The list of dataset entries.
...@@ -45,7 +45,7 @@ class ListDataset(Dataset): ...@@ -45,7 +45,7 @@ class ListDataset(Dataset):
def __len__( def __len__(
self, self,
): ) -> int:
return len(self._entries) return len(self._entries)
def __getitem__(self, index): def __getitem__(self, index):
......
...@@ -22,7 +22,7 @@ class AverageMeter: ...@@ -22,7 +22,7 @@ class AverageMeter:
Tracks the exact history of the added values in every epoch. Tracks the exact history of the added values in every epoch.
""" """
def __init__(self): def __init__(self) -> None:
""" """
Initialize the structure with empty history and zero-ed moving average. Initialize the structure with empty history and zero-ed moving average.
""" """
...@@ -110,7 +110,7 @@ class Stats: ...@@ -110,7 +110,7 @@ class Stats:
verbose: bool = False, verbose: bool = False,
epoch: int = -1, epoch: int = -1,
plot_file: Optional[str] = None, plot_file: Optional[str] = None,
): ) -> None:
""" """
Args: Args:
log_vars: The list of variable names to be logged. log_vars: The list of variable names to be logged.
......
...@@ -64,7 +64,7 @@ class R2N2(ShapeNetBase): # pragma: no cover ...@@ -64,7 +64,7 @@ class R2N2(ShapeNetBase): # pragma: no cover
voxels_rel_path: str = "ShapeNetVoxels", voxels_rel_path: str = "ShapeNetVoxels",
load_textures: bool = True, load_textures: bool = True,
texture_resolution: int = 4, texture_resolution: int = 4,
): ) -> None:
""" """
Store each object's synset id and models id the given directories. Store each object's synset id and models id the given directories.
......
...@@ -437,7 +437,7 @@ class BlenderCamera(CamerasBase): # pragma: no cover ...@@ -437,7 +437,7 @@ class BlenderCamera(CamerasBase): # pragma: no cover
(which uses Blender for rendering the views for each model). (which uses Blender for rendering the views for each model).
""" """
def __init__(self, R=r, T=t, K=k, device: Device = "cpu"): def __init__(self, R=r, T=t, K=k, device: Device = "cpu") -> None:
""" """
Args: Args:
R: Rotation matrix of shape (N, 3, 3). R: Rotation matrix of shape (N, 3, 3).
......
...@@ -31,7 +31,7 @@ class ShapeNetCore(ShapeNetBase): # pragma: no cover ...@@ -31,7 +31,7 @@ class ShapeNetCore(ShapeNetBase): # pragma: no cover
version: int = 1, version: int = 1,
load_textures: bool = True, load_textures: bool = True,
texture_resolution: int = 4, texture_resolution: int = 4,
): ) -> None:
""" """
Store each object's synset id and models id from data_dir. Store each object's synset id and models id from data_dir.
......
...@@ -30,7 +30,7 @@ class ShapeNetBase(torch.utils.data.Dataset): # pragma: no cover ...@@ -30,7 +30,7 @@ class ShapeNetBase(torch.utils.data.Dataset): # pragma: no cover
and __getitem__ need to be implemented. and __getitem__ need to be implemented.
""" """
def __init__(self): def __init__(self) -> None:
""" """
Set up lists of synset_ids and model_ids. Set up lists of synset_ids and model_ids.
""" """
...@@ -44,7 +44,7 @@ class ShapeNetBase(torch.utils.data.Dataset): # pragma: no cover ...@@ -44,7 +44,7 @@ class ShapeNetBase(torch.utils.data.Dataset): # pragma: no cover
self.load_textures = True self.load_textures = True
self.texture_resolution = 4 self.texture_resolution = 4
def __len__(self): def __len__(self) -> int:
""" """
Return number of total models in the loaded dataset. Return number of total models in the loaded dataset.
""" """
......
...@@ -187,7 +187,7 @@ def _make_node_transform(node: Dict[str, Any]) -> Transform3d: ...@@ -187,7 +187,7 @@ def _make_node_transform(node: Dict[str, Any]) -> Transform3d:
class _GLTFLoader: class _GLTFLoader:
def __init__(self, stream: BinaryIO): def __init__(self, stream: BinaryIO) -> None:
self._json_data = None self._json_data = None
# Map from buffer index to (decoded) binary data # Map from buffer index to (decoded) binary data
self._binary_data = {} self._binary_data = {}
...@@ -539,7 +539,7 @@ class MeshGlbFormat(MeshFormatInterpreter): ...@@ -539,7 +539,7 @@ class MeshGlbFormat(MeshFormatInterpreter):
used which does not match the semantics of the standard. used which does not match the semantics of the standard.
""" """
def __init__(self): def __init__(self) -> None:
self.known_suffixes = (".glb",) self.known_suffixes = (".glb",)
def read( def read(
......
...@@ -291,7 +291,7 @@ def load_objs_as_meshes( ...@@ -291,7 +291,7 @@ def load_objs_as_meshes(
class MeshObjFormat(MeshFormatInterpreter): class MeshObjFormat(MeshFormatInterpreter):
def __init__(self): def __init__(self) -> None:
self.known_suffixes = (".obj",) self.known_suffixes = (".obj",)
def read( def read(
......
...@@ -419,7 +419,7 @@ class MeshOffFormat(MeshFormatInterpreter): ...@@ -419,7 +419,7 @@ class MeshOffFormat(MeshFormatInterpreter):
""" """
def __init__(self): def __init__(self) -> None:
self.known_suffixes = (".off",) self.known_suffixes = (".off",)
def read( def read(
......
...@@ -63,7 +63,7 @@ class IO: ...@@ -63,7 +63,7 @@ class IO:
self, self,
include_default_formats: bool = True, include_default_formats: bool = True,
path_manager: Optional[PathManager] = None, path_manager: Optional[PathManager] = None,
): ) -> None:
if path_manager is None: if path_manager is None:
self.path_manager = PathManager() self.path_manager = PathManager()
else: else:
......
...@@ -66,7 +66,7 @@ class _PlyElementType: ...@@ -66,7 +66,7 @@ class _PlyElementType:
self.name: (str) name of the element self.name: (str) name of the element
""" """
def __init__(self, name: str, count: int): def __init__(self, name: str, count: int) -> None:
self.name = name self.name = name
self.count = count self.count = count
self.properties: List[_Property] = [] self.properties: List[_Property] = []
...@@ -130,7 +130,7 @@ class _PlyElementType: ...@@ -130,7 +130,7 @@ class _PlyElementType:
class _PlyHeader: class _PlyHeader:
def __init__(self, f): def __init__(self, f) -> None:
""" """
Load a header of a Ply file from a file-like object. Load a header of a Ply file from a file-like object.
Members: Members:
...@@ -1232,7 +1232,7 @@ def save_ply( ...@@ -1232,7 +1232,7 @@ def save_ply(
class MeshPlyFormat(MeshFormatInterpreter): class MeshPlyFormat(MeshFormatInterpreter):
def __init__(self): def __init__(self) -> None:
self.known_suffixes = (".ply",) self.known_suffixes = (".ply",)
def read( def read(
...@@ -1313,7 +1313,7 @@ class MeshPlyFormat(MeshFormatInterpreter): ...@@ -1313,7 +1313,7 @@ class MeshPlyFormat(MeshFormatInterpreter):
class PointcloudPlyFormat(PointcloudFormatInterpreter): class PointcloudPlyFormat(PointcloudFormatInterpreter):
def __init__(self): def __init__(self) -> None:
self.known_suffixes = (".ply",) self.known_suffixes = (".ply",)
def read( def read(
......
...@@ -21,7 +21,7 @@ class GraphConv(nn.Module): ...@@ -21,7 +21,7 @@ class GraphConv(nn.Module):
output_dim: int, output_dim: int,
init: str = "normal", init: str = "normal",
directed: bool = False, directed: bool = False,
): ) -> None:
""" """
Args: Args:
input_dim: Number of input features per vertex. input_dim: Number of input features per vertex.
......
...@@ -15,7 +15,7 @@ EPS = 0.00001 ...@@ -15,7 +15,7 @@ EPS = 0.00001
class Cube: class Cube:
def __init__(self, bfl_vertex: Tuple[int, int, int], spacing: int = 1): def __init__(self, bfl_vertex: Tuple[int, int, int], spacing: int = 1) -> None:
""" """
Initializes a cube given the bottom front left vertex coordinate Initializes a cube given the bottom front left vertex coordinate
and the cube spacing and the cube spacing
......
...@@ -26,7 +26,7 @@ class SubdivideMeshes(nn.Module): ...@@ -26,7 +26,7 @@ class SubdivideMeshes(nn.Module):
but different vertex positions. but different vertex positions.
""" """
def __init__(self, meshes=None): def __init__(self, meshes=None) -> None:
""" """
Args: Args:
meshes: Meshes object or None. If a meshes object is provided, meshes: Meshes object or None. If a meshes object is provided,
......
...@@ -364,7 +364,7 @@ class FoVPerspectiveCameras(CamerasBase): ...@@ -364,7 +364,7 @@ class FoVPerspectiveCameras(CamerasBase):
T=_T, T=_T,
K=None, K=None,
device: Device = "cpu", device: Device = "cpu",
): ) -> None:
""" """
Args: Args:
...@@ -848,7 +848,7 @@ class PerspectiveCameras(CamerasBase): ...@@ -848,7 +848,7 @@ class PerspectiveCameras(CamerasBase):
K=None, K=None,
device="cpu", device="cpu",
image_size=((-1, -1),), image_size=((-1, -1),),
): ) -> None:
""" """
Args: Args:
...@@ -1013,7 +1013,7 @@ class OrthographicCameras(CamerasBase): ...@@ -1013,7 +1013,7 @@ class OrthographicCameras(CamerasBase):
K=None, K=None,
device="cpu", device="cpu",
image_size=((-1, -1),), image_size=((-1, -1),),
): ) -> None:
""" """
Args: Args:
......
...@@ -49,7 +49,7 @@ class EmissionAbsorptionRaymarcher(torch.nn.Module): ...@@ -49,7 +49,7 @@ class EmissionAbsorptionRaymarcher(torch.nn.Module):
elements along the ray direction. elements along the ray direction.
""" """
def __init__(self, surface_thickness: int = 1): def __init__(self, surface_thickness: int = 1) -> None:
""" """
Args: Args:
surface_thickness: Denotes the overlap between the absorption surface_thickness: Denotes the overlap between the absorption
...@@ -128,7 +128,7 @@ class AbsorptionOnlyRaymarcher(torch.nn.Module): ...@@ -128,7 +128,7 @@ class AbsorptionOnlyRaymarcher(torch.nn.Module):
It then returns `opacities = 1 - total_transmission`. It then returns `opacities = 1 - total_transmission`.
""" """
def __init__(self): def __init__(self) -> None:
super().__init__() super().__init__()
def forward( def forward(
......
...@@ -66,7 +66,7 @@ class GridRaysampler(torch.nn.Module): ...@@ -66,7 +66,7 @@ class GridRaysampler(torch.nn.Module):
n_pts_per_ray: int, n_pts_per_ray: int,
min_depth: float, min_depth: float,
max_depth: float, max_depth: float,
): ) -> None:
""" """
Args: Args:
min_x: The leftmost x-coordinate of each ray's source pixel's center. min_x: The leftmost x-coordinate of each ray's source pixel's center.
...@@ -150,7 +150,7 @@ class NDCGridRaysampler(GridRaysampler): ...@@ -150,7 +150,7 @@ class NDCGridRaysampler(GridRaysampler):
n_pts_per_ray: int, n_pts_per_ray: int,
min_depth: float, min_depth: float,
max_depth: float, max_depth: float,
): ) -> None:
""" """
Args: Args:
image_width: The horizontal size of the image grid. image_width: The horizontal size of the image grid.
...@@ -192,7 +192,7 @@ class MonteCarloRaysampler(torch.nn.Module): ...@@ -192,7 +192,7 @@ class MonteCarloRaysampler(torch.nn.Module):
n_pts_per_ray: int, n_pts_per_ray: int,
min_depth: float, min_depth: float,
max_depth: float, max_depth: float,
): ) -> None:
""" """
Args: Args:
min_x: The smallest x-coordinate of each ray's source pixel. min_x: The smallest x-coordinate of each ray's source pixel.
......
...@@ -105,7 +105,7 @@ class ImplicitRenderer(torch.nn.Module): ...@@ -105,7 +105,7 @@ class ImplicitRenderer(torch.nn.Module):
``` ```
""" """
def __init__(self, raysampler: Callable, raymarcher: Callable): def __init__(self, raysampler: Callable, raymarcher: Callable) -> None:
""" """
Args: Args:
raysampler: A `Callable` that takes as input scene cameras raysampler: A `Callable` that takes as input scene cameras
...@@ -206,7 +206,7 @@ class VolumeRenderer(torch.nn.Module): ...@@ -206,7 +206,7 @@ class VolumeRenderer(torch.nn.Module):
def __init__( def __init__(
self, raysampler: Callable, raymarcher: Callable, sample_mode: str = "bilinear" self, raysampler: Callable, raymarcher: Callable, sample_mode: str = "bilinear"
): ) -> None:
""" """
Args: Args:
raysampler: A `Callable` that takes as input scene cameras raysampler: A `Callable` that takes as input scene cameras
...@@ -256,7 +256,7 @@ class VolumeSampler(torch.nn.Module): ...@@ -256,7 +256,7 @@ class VolumeSampler(torch.nn.Module):
at 3D points sampled along projection rays. at 3D points sampled along projection rays.
""" """
def __init__(self, volumes: Volumes, sample_mode: str = "bilinear"): def __init__(self, volumes: Volumes, sample_mode: str = "bilinear") -> None:
""" """
Args: Args:
volumes: An instance of the `Volumes` class representing a volumes: An instance of the `Volumes` class representing a
......
...@@ -164,7 +164,7 @@ class DirectionalLights(TensorProperties): ...@@ -164,7 +164,7 @@ class DirectionalLights(TensorProperties):
specular_color=((0.2, 0.2, 0.2),), specular_color=((0.2, 0.2, 0.2),),
direction=((0, 1, 0),), direction=((0, 1, 0),),
device: Device = "cpu", device: Device = "cpu",
): ) -> None:
""" """
Args: Args:
ambient_color: RGB color of the ambient component. ambient_color: RGB color of the ambient component.
...@@ -225,7 +225,7 @@ class PointLights(TensorProperties): ...@@ -225,7 +225,7 @@ class PointLights(TensorProperties):
specular_color=((0.2, 0.2, 0.2),), specular_color=((0.2, 0.2, 0.2),),
location=((0, 1, 0),), location=((0, 1, 0),),
device: Device = "cpu", device: Device = "cpu",
): ) -> None:
""" """
Args: Args:
ambient_color: RGB color of the ambient component ambient_color: RGB color of the ambient component
...@@ -294,7 +294,7 @@ class AmbientLights(TensorProperties): ...@@ -294,7 +294,7 @@ class AmbientLights(TensorProperties):
not used in rendering. not used in rendering.
""" """
def __init__(self, *, ambient_color=None, device: Device = "cpu"): def __init__(self, *, ambient_color=None, device: Device = "cpu") -> None:
""" """
If ambient_color is provided, it should be a sequence of If ambient_color is provided, it should be a sequence of
triples of floats. triples of floats.
......
...@@ -24,7 +24,7 @@ class Materials(TensorProperties): ...@@ -24,7 +24,7 @@ class Materials(TensorProperties):
specular_color=((1, 1, 1),), specular_color=((1, 1, 1),),
shininess=64, shininess=64,
device: Device = "cpu", device: Device = "cpu",
): ) -> None:
""" """
Args: Args:
ambient_color: RGB ambient reflectivity of the material ambient_color: RGB ambient reflectivity of the material
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment