Precompute scalar derivatives in Jet elementary functions

Compute cbrt(f) using a single cbrt(f.a) call with f.v / (3 * r * r),
avoiding both the second cbrt evaluation and f.a * f.a overflow or
underflow at extreme magnitudes. Precompute the scalar derivative factor
in erf(x) and erfc(x) using a compile-time constant for 2 / sqrt(pi)
before multiplying x.v so Eigen evaluates a single scalar-vector product
instead of scaling x.v twice. Parenthesize (T(1.0) / log(T(10.0))) / f.a
in log10 and (T(1.0) / log(T(2.0))) / f.a in log2 so the reciprocal
constant folds at compile time, and use T(0.5) / tmp in sqrt. Standardize
on floating-point T(...) constants and left-multiplication by scalar
derivatives across elementary functions in jet.h.

Benchmark (Apple M1 Pro):
----------------------------------------------------------------------
Benchmark                                     Before    After   Change
----------------------------------------------------------------------
Cbrt<3>/1000                                 11.7 us  7.29 us   -37.7%
Cbrt<10>/1000                                15.9 us  11.5 us   -27.6%
Cbrt<32>/1000                                29.9 us  25.7 us   -14.0%
Erf<3>/1000                                  23.8 us  21.1 us   -11.3%
Erf<32>/1000                                 39.9 us  32.8 us   -17.8%
Erfc<3>/1000                                 23.1 us  20.2 us   -12.6%
Erfc<32>/1000                                39.8 us  32.7 us   -17.8%
Sqrt<15>/1000                                4.50 us  4.38 us    -2.7%
Sqrt<32>/1000                                12.5 us  12.4 us    -0.8%
----------------------------------------------------------------------

Change-Id: I2a4ceebad76cbb0eddc42be6368872a9e5543b70
3 files changed
tree: c6159df39c7a3ac9f1eb99ea6973a799a68ad484
  1. .github/
  2. bazel/
  3. cmake/
  4. config/
  5. data/
  6. docs/
  7. examples/
  8. include/
  9. internal/
  10. LICENSES/
  11. scripts/
  12. third_party/
  13. .bazelignore
  14. .clang-format
  15. .gitignore
  16. .gitmodules
  17. .readthedocs.yaml
  18. BUILD
  19. CITATION.cff
  20. CMakeLists.txt
  21. CONTRIBUTING.md
  22. LICENSE
  23. MODULE.bazel
  24. package.xml
  25. README.md
  26. REUSE.toml
  27. WORKSPACE
README.md

Android Linux macOS Windows

Ceres Solver

Ceres Solver is an open source C++ library for modeling and solving large, complicated optimization problems. It is a feature rich, mature and performant library which has been used in production at Google since 2010. Ceres Solver can solve two kinds of problems.

  1. Non-linear Least Squares problems with bounds constraints.
  2. General unconstrained optimization problems.

Please see ceres-solver.org for more information.