@@ -493,7 +493,7 @@ def _np_xyz_to_quat(xyz: np.ndarray, rpy: bool = False, out: np.ndarray | None =
493493 """
494494 assert xyz .ndim >= 1
495495 if out is None :
496- out_ = np .empty ((* xyz .shape [:- 1 ], 4 ))
496+ out_ = np .empty ((* xyz .shape [:- 1 ], 4 ), dtype = xyz . dtype )
497497 else :
498498 assert out .shape == (* xyz .shape [:- 1 ], 4 )
499499 out_ = out
@@ -532,12 +532,13 @@ def _tc_xyz_to_quat(xyz: torch.Tensor, rpy: bool = False, *, out: torch.Tensor |
532532
533533
534534def xyz_to_quat (xyz , rpy = False , degrees = False ):
535- if degrees :
536- xyz = xyz * (math .pi / 180.0 )
537-
538535 if isinstance (xyz , torch .Tensor ):
536+ if degrees :
537+ xyz = torch .deg2rad (xyz )
539538 return _tc_xyz_to_quat (xyz , rpy )
540539 elif isinstance (xyz , np .ndarray ):
540+ if degrees :
541+ xyz = np .deg2rad (xyz )
541542 return _np_xyz_to_quat (xyz , rpy )
542543 else :
543544 gs .raise_exception (f"the input must be either torch.Tensor or np.ndarray. got: { type (xyz )= } " )
@@ -703,12 +704,14 @@ def _tc_quat_to_xyz(quat, rpy=False, out=None):
703704def quat_to_xyz (quat , rpy = False , degrees = False ):
704705 if isinstance (quat , torch .Tensor ):
705706 rpy = _tc_quat_to_xyz (quat , rpy )
707+ if degrees :
708+ rpy = torch .rad2deg (rpy )
706709 elif isinstance (quat , np .ndarray ):
707710 rpy = _np_quat_to_xyz (quat , rpy )
711+ if degrees :
712+ rpy = np .rad2deg (rpy )
708713 else :
709714 gs .raise_exception (f"the input must be either torch.Tensor or np.ndarray. got: { type (quat )= } " )
710- if degrees :
711- rpy *= 180.0 / math .pi
712715 return rpy
713716
714717
@@ -1233,13 +1236,14 @@ def _tc_z_up_to_R(z, up=None, out=None):
12331236
12341237 # Handle zero x norm cases
12351238 zero_x_mask = x_norm [..., 0 ] < gs .EPS
1236- if zero_x_mask .any ():
1239+ zero_x_num = zero_x_mask .sum ()
1240+ if zero_x_num :
12371241 # For zero x norm, set identity matrix
1238- R [zero_x_mask ] = torch .eye (3 , device = z .device , dtype = z .dtype )
1242+ R [zero_x_mask ] = torch .eye (3 , device = z .device , dtype = z .dtype ). unsqueeze ( 0 ). expand (( zero_x_num , 3 , 3 ))
12391243
12401244 # Continue with non-zero cases
12411245 valid_mask = ~ zero_x_mask
1242- if valid_mask . any ():
1246+ if zero_x_num < zero_x_mask . numel ():
12431247 z_valid = z [valid_mask ]
12441248 x_valid = x [valid_mask ]
12451249 y [valid_mask ] = torch .cross (z_valid , x_valid , dim = - 1 )
@@ -1324,7 +1328,7 @@ def _np_euler_to_R(rpy: np.ndarray, out: np.ndarray | None = None) -> np.ndarray
13241328
13251329
13261330def euler_to_R (euler_xyz ):
1327- return _np_euler_to_R (np .asarray (euler_xyz ) * ( math . pi / 180.0 ))
1331+ return _np_euler_to_R (np .deg2rad (euler_xyz ))
13281332
13291333
13301334@nb .jit (nopython = True , cache = True )
0 commit comments