Skip to content

Commit

Permalink
Explicitly convert to numpy uint32 type where appropriate.
Browse files Browse the repository at this point in the history
`dtype=int` converts to the C `long` data type. On 64b Linux, that defaults to
`int64_t`. On Windows however, even 64b, it is `int32_t`.

Using `dtype=int` on Windows will raise an OverflowError when trying to convert
uint32_t 0xFFFFFFFF values.
  • Loading branch information
adamshapiro0 committed Oct 10, 2023
1 parent e2be15c commit c41c444
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion python/fusion_engine_client/analysis/data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def to_numpy(self, remove_nan_times: bool = True):

if do_conversion:
self.__dict__.update(self.message_class.to_numpy(self.messages))
self.messages_bytes = np.array(self.messages_bytes, dtype=int)
self.messages_bytes = np.array(self.messages_bytes, dtype=np.uint64)
self.message_index = np.array(self.message_index, dtype=int)

if remove_nan_times and 'p1_time' in self.__dict__:
Expand Down
14 changes: 7 additions & 7 deletions python/fusion_engine_client/messages/measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,10 @@ def __str__(self):
@classmethod
def to_numpy(cls, messages):
result = {
'front_left_wheel_ticks': np.array([m.front_left_wheel_ticks for m in messages], dtype=int),
'front_right_wheel_ticks': np.array([m.front_right_wheel_ticks for m in messages], dtype=int),
'rear_left_wheel_ticks': np.array([m.rear_left_wheel_ticks for m in messages], dtype=int),
'rear_right_wheel_ticks': np.array([m.rear_right_wheel_ticks for m in messages], dtype=int),
'front_left_wheel_ticks': np.array([m.front_left_wheel_ticks for m in messages], dtype=np.uint32),
'front_right_wheel_ticks': np.array([m.front_right_wheel_ticks for m in messages], dtype=np.uint32),
'rear_left_wheel_ticks': np.array([m.rear_left_wheel_ticks for m in messages], dtype=np.uint32),
'rear_right_wheel_ticks': np.array([m.rear_right_wheel_ticks for m in messages], dtype=np.uint32),
'gear': np.array([m.gear for m in messages], dtype=int),
}
result.update(MeasurementDetails.to_numpy([m.details for m in messages]))
Expand Down Expand Up @@ -690,7 +690,7 @@ def __str__(self):
@classmethod
def to_numpy(cls, messages):
result = {
'tick_count': np.array([m.tick_count for m in messages], dtype=int),
'tick_count': np.array([m.tick_count for m in messages], dtype=np.uint32),
'gear': np.array([m.gear for m in messages], dtype=int),
}
result.update(MeasurementDetails.to_numpy([m.details for m in messages]))
Expand Down Expand Up @@ -1003,7 +1003,7 @@ def calcsize(cls) -> int:
def to_numpy(cls, messages: Sequence['HeadingOutput']):
result = {
'solution_type': np.array([int(m.solution_type) for m in messages], dtype=int),
'flags': np.array([int(m.flags) for m in messages], dtype=int),
'flags': np.array([int(m.flags) for m in messages], dtype=np.uint32),
'ypr_deg': np.array([m.ypr_deg for m in messages]).T,
'heading_true_north_deg': np.array([m.heading_true_north_deg for m in messages], dtype=float).T,
}
Expand Down Expand Up @@ -1122,7 +1122,7 @@ def calcsize(cls) -> int:
def to_numpy(cls, messages: Sequence['RawHeadingOutput']):
result = {
'solution_type': np.array([int(m.solution_type) for m in messages], dtype=int),
'flags': np.array([int(m.flags) for m in messages], dtype=int),
'flags': np.array([int(m.flags) for m in messages], dtype=np.uint32),
'relative_position_enu_m': np.array([m.relative_position_enu_m for m in messages]).T,
'position_std_enu_m': np.array([m.position_std_enu_m for m in messages]).T,
'heading_true_north_deg': np.array([float(m.heading_true_north_deg) for m in messages]),
Expand Down
2 changes: 1 addition & 1 deletion python/fusion_engine_client/messages/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def to_numpy(cls, messages):
'num_svs': np.array([int(m.num_svs) for m in messages], dtype=int),
'corrections_age_sec': np.array([m.corrections_age_sec for m in messages]),
'baseline_distance_m': np.array([m.baseline_distance_m for m in messages]),
'reference_station_id': np.array([int(m.reference_station_id) for m in messages], dtype=int),
'reference_station_id': np.array([int(m.reference_station_id) for m in messages], dtype=np.uint32),
'gdop': np.array([m.gdop for m in messages]),
'pdop': np.array([m.pdop for m in messages]),
'hdop': np.array([m.hdop for m in messages]),
Expand Down

0 comments on commit c41c444

Please sign in to comment.