GCC Code Coverage Report


Directory: ./
File: include/crocoddyl/core/utils/scalar.hpp
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 2 3 66.7%
Branches: 0 0 -%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2025-2025, Heriot-Watt University
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
7 ///////////////////////////////////////////////////////////////////////////////
8
9 #ifndef CROCODDYL_UTILS_SCALAR_HPP_
10 #define CROCODDYL_UTILS_SCALAR_HPP_
11
12 #include <type_traits>
13
14 #include "crocoddyl/core/utils/conversions.hpp"
15
16 namespace crocoddyl {
17
18 // Trait to extract base scalar type
19 template <typename Scalar>
20 struct ScalarBaseType {
21 typedef Scalar type;
22 };
23
24 #ifdef CROCODDYL_WITH_CODEGEN
25
26 template <typename Scalar>
27 struct ScalarBaseType<CppAD::AD<Scalar>> {
28 typedef typename ScalarBaseType<Scalar>::type type;
29 };
30
31 template <typename Scalar>
32 struct ScalarBaseType<CppAD::cg::CG<Scalar>> {
33 typedef typename ScalarBaseType<Scalar>::type type;
34 };
35
36 #endif
37
38 // Main function
39 template <typename Scalar>
40 220 Scalar ScaleNumerics(double base_value, double float_multiplier = 1e4) {
41 typedef typename ScalarBaseType<Scalar>::type Base;
42 return std::is_same<Base, float>::value
43 ? static_cast<Scalar>(base_value * float_multiplier)
44 220 : static_cast<Scalar>(base_value);
45 }
46
47 } // namespace crocoddyl
48
49 #endif // CROCODDYL_UTILS_SCALAR_HPP_
50