Skip to content

atomic lint mat vec

hgratten requested to merge atomic_lint_mat_vec into master

this merge request introduces the clang-tidied MatVec chapter

LectureCodes/MatVec/*:

  • removed cmake_minimum_required(VERSION 2.8), since the cmake version is better handled by the global CMakeLists.txt file
  • introduced const wherever possible
  • wrapped body statement of for, do while, and while in braces. increases readability and forgetting braces is a common source of bugs for students
  • avoided implict cast of integers to bool in conditional expression, increases readibility and avoids bugs
  • removed "using namespace", since it clutters the translation unit
  • reordered includes as good practice (user header first, then system headers, ordered alphabetically)
  • introduced a using declatation for commonly used symbols from other namespaces, except Eigen::Index
  • explicitly casted integer types to double
  • replaced atoi with strtol since, atoi does not check the validity of the conversion and does not detect errors
  • avoided pointer arithmetic, instead used span, which is safe to index
  • replaced typedef with using alias. typedef is deprecated, since it cannot handle templated type aliases. however, the semantics for non-templated statements are identical between the two.
  • avoided else after exit since it reduces readability of code flow and quickly causes bugs
  • avoided uninitialized variables, instead used NAN to initialize doubles or -1 to initialize indices. this is more likely to show up as an error than accidentally using unitialized memory
  • removed unused typedefs
  • avoided pointer arithmetic, instead used begin and end iterator for e.g. modern std::partial_sum
  • used emplace_back (e.g. for initializing sparse triplets) instead of push_back since it may save a copy
  • reserved space in vectors before using push/emplace in a loop, since the added number of elements is almost always known ahead of time
  • explicitly casted between integer types (narrowing, different signedness)

LectureCodes/MatVec/Dense/accesstiming/Eigen/main.cpp:

  • ignored locally the otherwise commonly problematic use of macros, since we need to disable assert statements during timing

LectureCodes/MatVec/Dense/arrowsys/Eigen/arrowsys_(fast/slow/sparse).hpp:

  • ignored locally the bugprone-easily-swappable-parameters check since the parameters are clearly named as in the lecture script and the caller code file. this could be fixed by introducing a struct where each parameter is named, which would force the caller to name arguments explicitly

LectureCodes/MatVec/Dense/blas/ColumnMajorMatrix.(hpp/cpp):

  • replaced raw-pointer-to-double implementation with a std::vector-based one, since working with raw pointers throws many unavoidable safety warnings
  • rule of five: added move constructor and move assignment operator since copy constructor and copy assignment operator are present. From clang-tidy cppcoreguidelines-special-member-functions: The relationship between which functions will be suppressed by definitions of other functions is complicated and it is advised that all five are defaulted or explicitly defined.
  • defaulted destructor since the data vector is a std container and thus automatically deallocated as a class member upon destruction

LectureCodes/MatVec/Dense/smw/Eigen/smw.hpp:

  • reordered function arguments to avoid warning about easily swappable arguments

LectureCodes/MatVec/Sparse/eigensparseinit/Eigen/sparsetiming.cpp and LectureCodes/MatVec/Sparse/sparseformat/Eigen/main.cpp:

  • restructured to capturing lambdas instead of functions accessing mutable statics, since this throws all kinds of warnings and lives in too broad of a scope

LectureCodes/MatVec/Sparse/triangulations/Eigen/triangulation.hpp:

  • avoided pointer arithmetic, instead used .reshaped().begin() and reshaped().end() iterator for modern vector initialization

Merge request reports

Loading