Skip to content

dtype consistency (float vs float32) #35

@taka-rl

Description

@taka-rl

Make sure that the data type shall be consistent np.float32.
Due to the complexity of the project, the project follows these for now.

  • Observation(state) and actions are in float32.
  • Rendering/Physics calculation are in float64/float.

Rendering requires np.float64 as pygame.draw.polygon(screen, color, pixel_vertex) causes an error if pixel_vertex is np.float32, not np.float64.

Todo

parking_env.py

Todo later not now

car.py

  • each member of car class
  • return rotated vertices in np.float32 in rotate_car()
  • kinematic bicycle model calculation and update a state
  • Add tests to ensure the data type.

parking.py

  • Ensure that each method returns in np.float32.
  • CarSize
  • WheelSize
  • ParkingLotSize
  • Config
  • Add tests to ensure the data type.

references

NumPy type hints

some examples of numpy data type hints:

def example(
    x: np.ndarray[tuple[int], np.dtype[np.bool_]],
    y: np.ndarray[tuple[int, int, int], np.dtype[np.uint8]],
    ) -> np.ndarray[tuple[int], np.dtype[np.float32]]: ...
  • A 1D array of Booleans:
np.ndarray[tuple[int], np.dtype[np.bool_]]
  • A 3D array of unsigned 8-bit integers:
np.ndarray[tuple[int, int, int], np.dtype[np.uint8]]
  • A two-dimensional (2D) array of float32:
np.ndarray[tuple[int, int], np.dtype[np.float32]]
  • A 1D array of any numeric type:
np.ndarray[tuple[int], np.dtype[np.number]]

Improving Code Quality with Array and DataFrame Type Hints

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions