Taking Static Type-safety to the Next Level: Physical Units for Matrices

Daniel Withopf

in-person
60 minute session
intermediate
advanced
14:00-15:00, Thursday, 7th July 2022

This talk will present a full-blown solution for a problem that has not been solved in C++ before: How can physical unit types (think Meters, Seconds, ...) be used inside vector / matrix types from a linear algebra library where each entry can have a different unit? The presented solution uses C++'s strong type system to provide physical unit annotations for each matrix element. Furthermore, it also enables coordinate frame and quantity kind annotations (think X- and Y-position in coordinate frame A or B which have identical units but refer to different things).

We will learn what is the best way to represent these annotations, how they propagate through linear algebra operations, how they determine the subset of valid operations on each type and of course and most importantly, how this can be implemented efficiently in C++ (with a special on how C++20 is a game-changer here). While developing the solution, we will also understand how this leads to code that is more expressive and less likely to contain errors because the majority of bugs can be caught at compile-time.

Applications that benefit from this include robotics, computer graphics, automated driving and any other domain that works with physical units, different coordinate frames and matrix operations.

templates
physical units
type-safety
linear algebra

Daniel Withopf

Daniel Withopf has been working on solving real-world problems with C++ in robotics and related fields for over 20 years. He currently is a Software Engineer at the German car supplier Bosch where he wrote and maintains an object tracking framework for self-driving car projects. While doing that he discovered novel ways how to leverage C++'s type system to create linear algebra and tracking code that is more expressive, easier to understand and less likely to contain errors.