Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/vector/_compute/spatial/cross.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ def make_conversion(azimuthal1, longitudinal1, azimuthal2, longitudinal2):
AzimuthalXY,
LongitudinalZ,
):
to_x1 = None
to_y1 = None
to_z1 = None
to_x2 = None
to_y2 = None
to_z2 = None

if azimuthal1 is AzimuthalXY:
to_x1 = x.xy
to_y1 = y.xy
Expand All @@ -67,6 +74,7 @@ def make_conversion(azimuthal1, longitudinal1, azimuthal2, longitudinal2):
to_z1 = z.xy_theta
elif longitudinal1 is LongitudinalEta:
to_z1 = z.xy_eta

elif azimuthal1 is AzimuthalRhoPhi:
to_x1 = x.rhophi
to_y1 = y.rhophi
Expand All @@ -76,6 +84,7 @@ def make_conversion(azimuthal1, longitudinal1, azimuthal2, longitudinal2):
to_z1 = z.rhophi_theta
elif longitudinal1 is LongitudinalEta:
to_z1 = z.rhophi_eta

if azimuthal2 is AzimuthalXY:
to_x2 = x.xy
to_y2 = y.xy
Expand All @@ -85,15 +94,25 @@ def make_conversion(azimuthal1, longitudinal1, azimuthal2, longitudinal2):
to_z2 = z.xy_theta
elif longitudinal2 is LongitudinalEta:
to_z2 = z.xy_eta

elif azimuthal2 is AzimuthalRhoPhi:
to_x2 = x.rhophi
to_y2 = y.rhophi

if longitudinal2 is LongitudinalZ:
to_z2 = z.rhophi_z
elif longitudinal2 is LongitudinalTheta:
to_z2 = z.rhophi_theta
elif longitudinal2 is LongitudinalEta:
to_z2 = z.rhophi_eta

assert to_x1 is not None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, is pylint warning only because we did not initialize the variables outside of if-else blocks? If so, are these assert statements redundant?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the lint warning seems to come from the variables being assigned only inside conditional branches. The assertions were intended as runtime guards / clearer failures, matching the wording in #512, but they are not strictly needed just to silence pylint if the variables are initialized first. I’m happy to adjust based on your preference.

assert to_y1 is not None
assert to_z1 is not None
assert to_x2 is not None
assert to_y2 is not None
assert to_z2 is not None

cartesian, azout, lout, tout = dispatch_map[
AzimuthalXY, LongitudinalZ, AzimuthalXY, LongitudinalZ
]
Expand Down
10 changes: 10 additions & 0 deletions src/vector/_compute/spatial/rotate_quaternion.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ def cartesian(lib, u, i, j, k, x, y, z):

def make_conversion(azimuthal, longitudinal):
if (azimuthal, longitudinal) != (AzimuthalXY, LongitudinalZ):
to_x = None
to_y = None
to_z = None

if azimuthal is AzimuthalXY:
to_x = x.xy
to_y = y.xy
Expand All @@ -74,6 +78,7 @@ def make_conversion(azimuthal, longitudinal):
to_z = z.xy_theta
elif longitudinal is LongitudinalEta:
to_z = z.xy_eta

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto with the extra lines.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed — I’ll remove the extra blank lines unless formatting tools require them.

elif azimuthal is AzimuthalRhoPhi:
to_x = x.rhophi
to_y = y.rhophi
Expand All @@ -83,6 +88,11 @@ def make_conversion(azimuthal, longitudinal):
to_z = z.rhophi_theta
elif longitudinal is LongitudinalEta:
to_z = z.rhophi_eta

assert to_x is not None
assert to_y is not None
assert to_z is not None

cartesian, azout, lout = dispatch_map[AzimuthalXY, LongitudinalZ]

def f(lib, u, i, j, k, coord1, coord2, coord3):
Expand Down
Loading