Skip to content

Commit

Permalink
Pre-silence Pyre Errors for upcoming upgrade] [batch:94/596] [shard:2/N]
Browse files Browse the repository at this point in the history
Reviewed By: MaggieMoss

Differential Revision: D65224532

fbshipit-source-id: 694104b691efcec7777a9cfa46979332c60f9f8e
  • Loading branch information
generatedunixname89002005287564 authored and facebook-github-bot committed Oct 31, 2024
1 parent 0733669 commit c83b97d
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions opensfm/actions/create_submodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def _cluster_images(meta_data: MetaDataSet, cluster_size: float) -> None:
K = float(images.shape[0]) / cluster_size
K = int(np.ceil(K))

# pyre-fixme[23]: Unable to unpack single value, 2 were expected.
labels, centers = tools.kmeans(positions, K)[1:]

images = images.ravel()
Expand Down
8 changes: 8 additions & 0 deletions opensfm/actions/export_colmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def blob_to_array(blob, dtype, shape: Tuple[int] = (-1,)):
return np.frombuffer(blob, dtype=dtype).reshape(*shape)


# pyre-fixme[11]: Annotation `Connection` is not defined as a type.
class COLMAPDatabase(sqlite3.Connection):
@staticmethod
def connect(database_path) -> t.Any:
Expand All @@ -205,6 +206,7 @@ def connect(database_path) -> t.Any:
def __init__(self, *args, **kwargs) -> None:
super(COLMAPDatabase, self).__init__(*args, **kwargs)

# pyre-fixme[16]: `COLMAPDatabase` has no attribute `executescript`.
self.create_tables = lambda: self.executescript(CREATE_ALL)
self.create_cameras_table = lambda: self.executescript(CREATE_CAMERAS_TABLE)
self.create_descriptors_table = lambda: self.executescript(
Expand All @@ -222,6 +224,7 @@ def add_camera(
self, model, width, height, params, prior_focal_length=False, camera_id=None
) -> t.Any:
params = np.asarray(params, np.float64)
# pyre-fixme[16]: `COLMAPDatabase` has no attribute `execute`.
cursor = self.execute(
"INSERT INTO cameras VALUES (?, ?, ?, ?, ?, ?)",
(
Expand All @@ -238,6 +241,7 @@ def add_camera(
def add_image(
self, name, camera_id, prior_q=(0, 0, 0, 0), prior_t=(0, 0, 0), image_id=None
) -> t.Any:
# pyre-fixme[16]: `COLMAPDatabase` has no attribute `execute`.
cursor = self.execute(
"INSERT INTO images VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
(
Expand All @@ -260,13 +264,15 @@ def add_keypoints(self, image_id, keypoints) -> None:
assert keypoints.shape[1] in [2, 4, 6]

keypoints = np.asarray(keypoints, np.float32)
# pyre-fixme[16]: `COLMAPDatabase` has no attribute `execute`.
self.execute(
"INSERT INTO keypoints VALUES (?, ?, ?, ?)",
(image_id,) + keypoints.shape + (array_to_blob(keypoints),),
)

def add_descriptors(self, image_id, descriptors) -> None:
descriptors = np.ascontiguousarray(descriptors, np.uint8)
# pyre-fixme[16]: `COLMAPDatabase` has no attribute `execute`.
self.execute(
"INSERT INTO descriptors VALUES (?, ?, ?, ?)",
(image_id,) + descriptors.shape + (array_to_blob(descriptors),),
Expand All @@ -281,6 +287,7 @@ def add_matches(self, image_id1, image_id2, matches) -> None:

pair_id = image_ids_to_pair_id(image_id1, image_id2)
matches = np.asarray(matches, np.uint32)
# pyre-fixme[16]: `COLMAPDatabase` has no attribute `execute`.
self.execute(
"INSERT INTO matches VALUES (?, ?, ?, ?)",
(pair_id,) + matches.shape + (array_to_blob(matches),),
Expand All @@ -300,6 +307,7 @@ def add_two_view_geometry(
F = np.asarray(F, dtype=np.float64)
E = np.asarray(E, dtype=np.float64)
H = np.asarray(H, dtype=np.float64)
# pyre-fixme[16]: `COLMAPDatabase` has no attribute `execute`.
self.execute(
"INSERT INTO two_view_geometries VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
(pair_id,)
Expand Down
4 changes: 4 additions & 0 deletions opensfm/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,10 @@ def save_matchgraph(
continue
o1 = reconstructions[comp1].shots[node1].pose.get_origin()
o2 = reconstructions[comp2].shots[node2].pose.get_origin()
# pyre-fixme[58]: `-` is not supported for operand types `int` and
# `floating[Any]`.
# pyre-fixme[58]: `/` is not supported for operand types `int` and
# `floating[Any]`.
c = max(0, min(1.0, 1 - (edge - lowest) / (highest - lowest)))
plt.plot([o1[0], o2[0]], [o1[1], o2[1]], linestyle="-", color=cmap(c))

Expand Down
5 changes: 5 additions & 0 deletions opensfm/test/test_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,18 @@ def test_bundle_projection_fixed_internals(scene_synthetic) -> None:
color = g_obs["feature_color"]
pt = g_obs["feature"]
obs = pymap.Observation(
# pyre-fixme[6]: For 1st argument expected `str` but got `int`.
pt[0],
# pyre-fixme[6]: For 1st argument expected `str` but got `int`.
pt[1],
# pyre-fixme[6]: For 3rd argument expected `float` but got
# `Dict[str, typing.Any]`.
g_obs["feature_scale"],
# pyre-fixme[6]: For 1st argument expected `str` but got `int`.
color[0],
# pyre-fixme[6]: For 1st argument expected `str` but got `int`.
color[1],
# pyre-fixme[6]: For 1st argument expected `str` but got `int`.
color[2],
# pyre-fixme[6]: For 7th argument expected `int` but got
# `Dict[str, typing.Any]`.
Expand Down
48 changes: 48 additions & 0 deletions opensfm/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1133,11 +1133,15 @@ def euler_matrix(ai: float, aj: float, ak: float, axes: str = "sxyz") -> numpy.n
try:
firstaxis, parity, repetition, frame = _AXES2TUPLE[axes]
except (AttributeError, KeyError):
# pyre-fixme[6]: For 1st argument expected `tuple[int, ...]` but got `str`.
_TUPLE2AXES[axes] # validation
firstaxis, parity, repetition, frame = axes

i = firstaxis
# pyre-fixme[6]: For 1st argument expected `int` but got `Union[int, str]`.
j = _NEXT_AXIS[i + parity]
# pyre-fixme[58]: `-` is not supported for operand types `Union[int, str]` and
# `Union[int, str]`.
k = _NEXT_AXIS[i - parity + 1]

if frame:
Expand Down Expand Up @@ -1198,32 +1202,69 @@ def euler_from_matrix(
try:
firstaxis, parity, repetition, frame = _AXES2TUPLE[axes.lower()]
except (AttributeError, KeyError):
# pyre-fixme[6]: For 1st argument expected `tuple[int, ...]` but got `str`.
_TUPLE2AXES[axes] # validation
firstaxis, parity, repetition, frame = axes

i = firstaxis
# pyre-fixme[6]: For 1st argument expected `int` but got `Union[int, str]`.
j = _NEXT_AXIS[i + parity]
# pyre-fixme[58]: `-` is not supported for operand types `Union[int, str]` and
# `Union[int, str]`.
k = _NEXT_AXIS[i - parity + 1]

M = numpy.array(matrix, dtype=numpy.float64, copy=False)[:3, :3]
if repetition:
# pyre-fixme[6]: For 1st argument expected `Union[ndarray[Any, dtype[Any]],
# tuple[ndarray[Any, dtype[Any]], ...]]` but got `Tuple[Union[int, str],
# int]`.
sy = math.sqrt(M[i, j] * M[i, j] + M[i, k] * M[i, k])
if sy > _EPS:
# pyre-fixme[6]: For 1st argument expected `Union[ndarray[Any,
# dtype[Any]], tuple[ndarray[Any, dtype[Any]], ...]]` but got
# `Tuple[Union[int, str], int]`.
ax = math.atan2(M[i, j], M[i, k])
# pyre-fixme[6]: For 1st argument expected `Union[ndarray[Any,
# dtype[Any]], tuple[ndarray[Any, dtype[Any]], ...]]` but got
# `Tuple[Union[int, str], Union[int, str]]`.
ay = math.atan2(sy, M[i, i])
# pyre-fixme[6]: For 1st argument expected `Union[ndarray[Any,
# dtype[Any]], tuple[ndarray[Any, dtype[Any]], ...]]` but got `Tuple[int,
# Union[int, str]]`.
az = math.atan2(M[j, i], -M[k, i])
else:
ax = math.atan2(-M[j, k], M[j, j])
# pyre-fixme[6]: For 1st argument expected `Union[ndarray[Any,
# dtype[Any]], tuple[ndarray[Any, dtype[Any]], ...]]` but got
# `Tuple[Union[int, str], Union[int, str]]`.
ay = math.atan2(sy, M[i, i])
az = 0.0
else:
# pyre-fixme[6]: For 1st argument expected `Union[ndarray[Any, dtype[Any]],
# tuple[ndarray[Any, dtype[Any]], ...]]` but got `Tuple[Union[int, str],
# Union[int, str]]`.
# pyre-fixme[6]: For 1st argument expected `Union[ndarray[Any, dtype[Any]],
# tuple[ndarray[Any, dtype[Any]], ...]]` but got `Tuple[int, Union[int,
# str]]`.
cy = math.sqrt(M[i, i] * M[i, i] + M[j, i] * M[j, i])
if cy > _EPS:
ax = math.atan2(M[k, j], M[k, k])
# pyre-fixme[6]: For 1st argument expected `Union[ndarray[Any,
# dtype[Any]], tuple[ndarray[Any, dtype[Any]], ...]]` but got `Tuple[int,
# Union[int, str]]`.
ay = math.atan2(-M[k, i], cy)
# pyre-fixme[6]: For 1st argument expected `Union[ndarray[Any,
# dtype[Any]], tuple[ndarray[Any, dtype[Any]], ...]]` but got `Tuple[int,
# Union[int, str]]`.
# pyre-fixme[6]: For 1st argument expected `Union[ndarray[Any,
# dtype[Any]], tuple[ndarray[Any, dtype[Any]], ...]]` but got
# `Tuple[Union[int, str], Union[int, str]]`.
az = math.atan2(M[j, i], M[i, i])
else:
ax = math.atan2(-M[j, k], M[j, j])
# pyre-fixme[6]: For 1st argument expected `Union[ndarray[Any,
# dtype[Any]], tuple[ndarray[Any, dtype[Any]], ...]]` but got `Tuple[int,
# Union[int, str]]`.
ay = math.atan2(-M[k, i], cy)
az = 0.0

Expand Down Expand Up @@ -1263,11 +1304,18 @@ def quaternion_from_euler(
try:
firstaxis, parity, repetition, frame = _AXES2TUPLE[axes.lower()]
except (AttributeError, KeyError):
# pyre-fixme[6]: For 1st argument expected `tuple[int, ...]` but got `str`.
_TUPLE2AXES[axes] # validation
firstaxis, parity, repetition, frame = axes

# pyre-fixme[58]: `+` is not supported for operand types `Union[int, str]` and
# `int`.
i = firstaxis + 1
# pyre-fixme[58]: `+` is not supported for operand types `int` and `Union[int,
# str]`.
j = _NEXT_AXIS[i + parity - 1] + 1
# pyre-fixme[58]: `-` is not supported for operand types `int` and `Union[int,
# str]`.
k = _NEXT_AXIS[i - parity] + 1

if frame:
Expand Down

0 comments on commit c83b97d

Please sign in to comment.