Commit Graph

1006 Commits

Author SHA1 Message Date
Sergiu Deitsch 2fba61434b support log1p and expm1 jet
Currently, it is not possible to accurately evaluate the derivative of
d/dx log(1 + x) under all circumstances and significant deviations from
the actual derivative d/dx log1p(x) can occur. This changeset introduces
the necessary Jet overload and its inverse, expm1.

Change-Id: Ifcf88f6d684f61ba86bbe49f0d551b703f34ad0d
2021-11-16 00:14:39 +01:00
Sergiu Deitsch a668cabbcf support norm jet
norm allows to compute the squared magnitude both of complex and real
numbers. While Jet does not support decaying of a std::complex to a
scalar performed by norm, the function is still useful when applied to
scalars alone for computing the square.

Change-Id: I27a3513f53f37fb3960411362e80d170d1ae6f74
2021-11-15 22:29:44 +00:00
Sergiu Deitsch a3a4b6d77f support copysign jet
libc++ (default on macOS) uses the copysign function for std::complex
multiplication which causes compilation errors such as these if
std::complex is combined with jets:

/Applications/Xcode_12.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/complex:607:19: error: no matching function for call to 'copysign'
            __a = copysign(__libcpp_isinf_or_builtin(__a) ? _Tp(1) : _Tp(0), __a);
                  ^~~~~~~~
foo.hpp:218:39: note: in instantiation of function template specialization 'std::__1::operator*<ceres::Jet<double, 3> >' requested here
    std::complex<Scalar> result = lhs * rhs;

copysign is also useful in other situations where the sign is required
allowing it to compute without branching.

Change-Id: I84b2d23374f1bf3bae32833016bb686d97d74054
2021-11-15 23:27:33 +01:00
Sergiu Deitsch b75dac1694 fix abs jet test comment
The comment suggests a non-existing (incorrect) test. Update the comment
and extend the test.

Change-Id: I362f0b5a2e81d286b672476bdb4394ed20263eb1
2021-11-15 18:34:34 +00:00
Sergiu Deitsch 034bf566f0 use copysign for abs jet
abs() implementation does not correctly handle the sign of the
infinitesimal part when the value is a NaN. Define the function in terms
of copysign which is the only portable way of manipulating the sign of
a NaN value.

Change-Id: I2f13fb1db62d35ca8b09e6bff1c05a736cb91513
2021-11-14 17:07:14 +01:00
Sameer Agarwal 06e02a1735 Delete unused files split.h/cc
Change-Id: I67a4542389a0c1162875975efd23cdfbe797c6bc
2021-09-18 06:10:26 -07:00
Sameer Agarwal ac7268da52 Fix an 80cols issue in covariance_impl.cc
Change-Id: I2422282919e7100ac852be2176cd754941a8b472
2021-09-15 06:22:29 -07:00
Sameer Agarwal 17dccef91b Add NumericDiffFirstOrderFunction
This has been a long requested feature so that users can minimize
functions using numeric differentiation.

As part of this, I have also redone rosenbrock.cc, which now has three
variants.

rosenbrock.cc now uses automatic differentiation.
rosenbrock_numeric_diff.cc uses numeric differentiation.
rosenbrock_analytic_diff.cc uses analytic derivatives.

This is analogus to how the helloworld example code is structured.

The tutorial for GradientProblemSolver has also been updated to reflect
this.

https://github.com/ceres-solver/ceres-solver/issues/691

Change-Id: Ib0fb9e35127fe4c8299d4793bea3558722c70dd7
2021-09-15 06:21:02 -07:00
Sameer Agarwal 03d64141ae Fix a incorrect check in reorder_program.cc
Thanks to William Gandler for pointing this out.

Change-Id: I7a4e0eebd2e557f7572df7455d7fa77527c087b6
2021-09-14 17:36:07 -07:00
Sameer Agarwal 2a2b9bd6fa Fix a bug in covariance_impl.cc
A matrix reference was being incorrectly sized. It was using
the block_size number of rows, where as there are only block_local_size
number of rows that are present in the underlying matrix.

This did not affect the correctness of the resulting code, because
right after construction we then access a subblock with block_local_size
rows.

Thanks to William Gandler for reporting this.

Change-Id: I35e1f5a30b79e31b0b9fac79f7e361821d6073df
2021-08-15 16:52:08 -07:00
Sameer Agarwal 27fade7b8c Fix a bug in system_test.cc
Fix an error in the cost functor for Powell's function.
Reported by William Gandler.

Change-Id: I4ffbbca3b3731aa13c3608067baaebd06c1a044a
2021-08-15 16:44:15 -07:00
Sameer Agarwal d4eb83ee58 Fix the Jacobian in trust_region_minimizer_test.cc
The analytical Jacobians for Powell's singular function were
incorrect. Thanks to William Gandler for reporting this.

Change-Id: I780ffe449daa6935a79b904835e13edcf1cdffa2
2021-08-15 16:37:47 -07:00
Sameer Agarwal 5f6071a1cc Fix a bug in local_parameterization_test.cc
Fix an incorrect comparison between in QuaternionParameterizationTestHelper.
Reported by William Gandler.

Change-Id: If4d63a51f6a55013b4e6f0c299462c5af6e80c70
2021-08-15 16:10:12 -07:00
Sameer Agarwal b2e732b1e2 Fix errors in comments from William Gandler.
Change-Id: I1c1f1f7bdc4a1748994c3b43e72270b88f2a2b96
2021-08-15 16:01:40 -07:00
Ahmed Taei aefd37b182 Refactor small_blas_gemm_benchmark
This allows benchmarking both dynamic and static problem sizes.

On my X86 2Ghz machine:

CPU Caches:
  L1 Data 32 KiB (x48)
  L1 Instruction 32 KiB (x48)
  L2 Unified 1024 KiB (x48)
  L3 Unified 39424 KiB (x2)

----------------------------------------------------------------------------------------------
Benchmark                                                    Time             CPU   Iterations
----------------------------------------------------------------------------------------------
BM_MatrixMatrixMultiplyEigen_Static_2x3x4                 10.9 ns         10.9 ns     63960496
BM_MatrixMatrixMultiplyEigen_Static_3x3x3                 11.9 ns         11.9 ns     58093785
BM_MatrixMatrixMultiplyEigen_Static_4x4x4                 24.9 ns         24.9 ns     28540133
BM_MatrixMatrixMultiplyEigen_Static_8x8x8                  258 ns          258 ns      2755921
BM_MatrixMatrixMultiplyEigen_Static_9x9x3                  255 ns          255 ns      2778628
BM_MatrixMatrixMultiplyEigen_Static_9x3x3                 37.7 ns         37.7 ns     18556359
BM_MatrixMatrixMultiplyEigen_Static_3x9x9                  220 ns          220 ns      3195163
BM_MatrixMatrixMultiplyEigen_Dynamic_2x3x4                37.8 ns         37.7 ns     18491162
BM_MatrixMatrixMultiplyEigen_Dynamic_3x3x3                48.8 ns         48.8 ns     13724884
BM_MatrixMatrixMultiplyEigen_Dynamic_4x4x4                74.5 ns         74.5 ns      9313146
BM_MatrixMatrixMultiplyEigen_Dynamic_8x8x8                 271 ns          271 ns      2595807
BM_MatrixMatrixMultiplyEigen_Dynamic_9x9x3                 259 ns          259 ns      2688515
BM_MatrixMatrixMultiplyEigen_Dynamic_9x3x3                 123 ns          123 ns      5792115
BM_MatrixMatrixMultiplyEigen_Dynamic_3x9x9                 236 ns          236 ns      2963896
BM_MatrixMatrixMultiplyNaive_Static_2x3x4                 12.2 ns         12.2 ns     56472772
BM_MatrixMatrixMultiplyNaive_Static_3x3x3                 15.5 ns         15.5 ns     44346456
BM_MatrixMatrixMultiplyNaive_Static_4x4x4                 41.5 ns         41.5 ns     17196984
BM_MatrixMatrixMultiplyNaive_Static_8x8x8                  199 ns          199 ns      3561730
BM_MatrixMatrixMultiplyNaive_Static_9x9x3                  148 ns          148 ns      4764814
BM_MatrixMatrixMultiplyNaive_Static_9x3x3                 38.4 ns         38.4 ns     17259019
BM_MatrixMatrixMultiplyNaive_Static_3x9x9                  115 ns          115 ns      6104752
BM_MatrixMatrixMultiplyNaive_Dynamic_2x3x4                9.66 ns         9.66 ns     74722971
BM_MatrixMatrixMultiplyNaive_Dynamic_3x3x3                13.0 ns         13.0 ns     53435308
BM_MatrixMatrixMultiplyNaive_Dynamic_4x4x4                47.8 ns         47.8 ns     14358184
BM_MatrixMatrixMultiplyNaive_Dynamic_8x8x8                 200 ns          200 ns      3572809
BM_MatrixMatrixMultiplyNaive_Dynamic_9x9x3                 104 ns          104 ns      6793797
BM_MatrixMatrixMultiplyNaive_Dynamic_9x3x3                34.0 ns         34.0 ns     20790695
BM_MatrixMatrixMultiplyNaive_Dynamic_3x9x9                 130 ns          130 ns      5170402
BM_MatrixTransposeMatrixMultiplyEigen_Static_2x3x4        10.3 ns         10.3 ns     69105234
BM_MatrixTransposeMatrixMultiplyEigen_Static_3x3x3        28.9 ns         28.9 ns     24478934
BM_MatrixTransposeMatrixMultiplyEigen_Static_4x4x4        23.7 ns         23.7 ns     29351926
BM_MatrixTransposeMatrixMultiplyEigen_Static_8x8x8         233 ns          233 ns      2929398
BM_MatrixTransposeMatrixMultiplyEigen_Static_9x9x3         211 ns          211 ns      3287409
BM_MatrixTransposeMatrixMultiplyEigen_Static_9x3x3        26.5 ns         26.5 ns     26515136
BM_MatrixTransposeMatrixMultiplyEigen_Static_3x9x9         196 ns          196 ns      3594314
BM_MatrixTransposeMatrixMultiplyEigen_Dynamic_2x3x4       9.05 ns         9.05 ns     77621001
BM_MatrixTransposeMatrixMultiplyEigen_Dynamic_3x3x3       11.1 ns         11.1 ns     62227812
BM_MatrixTransposeMatrixMultiplyEigen_Dynamic_4x4x4       25.5 ns         25.5 ns     27356089
BM_MatrixTransposeMatrixMultiplyEigen_Dynamic_8x8x8        248 ns          248 ns      2834983
BM_MatrixTransposeMatrixMultiplyEigen_Dynamic_9x9x3        229 ns          229 ns      3082369
BM_MatrixTransposeMatrixMultiplyEigen_Dynamic_9x3x3       28.4 ns         28.4 ns     24318629
BM_MatrixTransposeMatrixMultiplyEigen_Dynamic_3x9x9        229 ns          229 ns      3091288
BM_MatrixTransposeMatrixMultiplyNaive_Static_2x3x4        11.0 ns         11.0 ns     63773538
BM_MatrixTransposeMatrixMultiplyNaive_Static_3x3x3        19.1 ns         19.1 ns     37003139
BM_MatrixTransposeMatrixMultiplyNaive_Static_4x4x4        49.1 ns         49.1 ns     14142301
BM_MatrixTransposeMatrixMultiplyNaive_Static_8x8x8         244 ns          244 ns      2874755
BM_MatrixTransposeMatrixMultiplyNaive_Static_9x9x3         140 ns          140 ns      4992156
BM_MatrixTransposeMatrixMultiplyNaive_Static_9x3x3        46.2 ns         46.2 ns     15068317
BM_MatrixTransposeMatrixMultiplyNaive_Static_3x9x9         112 ns          112 ns      6213574
BM_MatrixTransposeMatrixMultiplyNaive_Dynamic_2x3x4       9.74 ns         9.74 ns     72155001
BM_MatrixTransposeMatrixMultiplyNaive_Dynamic_3x3x3       11.5 ns         11.5 ns     60070577
BM_MatrixTransposeMatrixMultiplyNaive_Dynamic_4x4x4       52.5 ns         52.5 ns     13473642
BM_MatrixTransposeMatrixMultiplyNaive_Dynamic_8x8x8        224 ns          224 ns      3124264
BM_MatrixTransposeMatrixMultiplyNaive_Dynamic_9x9x3       98.0 ns         98.0 ns      7199292
BM_MatrixTransposeMatrixMultiplyNaive_Dynamic_9x3x3       34.7 ns         34.6 ns     20203685
BM_MatrixTransposeMatrixMultiplyNaive_Dynamic_3x9x9        105 ns          105 ns      6653151

Change-Id: Iee403b4d27801d1614ecc1f78a1f8c0011514bd7
2021-08-09 21:24:17 -07:00
Ahmed Taei c3129c3d4a Fix tests not executing
- The operator() wasn't called and tests where not executed.
- Fill test matrices with non-constant data.

Change-Id: Iacc9e8cb47d8539aded05bb821d3ce2f08a740d6
2021-08-03 14:04:01 -07:00
Ahmed Taei 4fbe218f24 Refactor small_blas_test
- Add testMatrix{Transpose}MatrixMultiply size
  templated functions and test multiple problem
  sizes.
- Removes duplicated code for matrix{transpose}-
  matrix{naive} test cases

Change-Id: I9a5d4b0362732ea7bef58572edcaada778fb4aa0
2021-07-30 13:18:18 -07:00
Alexander Karatarakis 0c85c40923 Revert "Reduce copies involved in Jet operations"
This reverts commit c036c78196.

Change-Id: I736f2141d041e7a2c21491a159b48c5565df2bfa
2021-07-01 22:55:31 -07:00
Alexander Karatarakis 7b2c223be7 Add fmax/fmin overloads for scalars
Comparison operators are defined for Jet-scalar and scalar-Jet.
Add corresponding overloads for fmax and fmix so users
don't have to convert to Jet only to access these functions,
plus it can potentially save an unnecessary conversion.

Change-Id: I20cc2d5874935e019d4ecb2d6a8c2ae631c8a4d3
2021-06-23 13:40:58 -07:00
Alexander Karatarakis c036c78196 Reduce copies involved in Jet operations
- Avoid copies in compound assignment operators (+=, -=, *=, /=)
- Add r-value overloads to +,-,*./ operators

Addition<3>/1000                                  +0.0382         +0.0382          2798          2905          2798          2905
Addition<10>/1000                                 -0.0009         -0.0009          4831          4827          4831          4827
Addition<15>/1000                                 -0.0011         -0.0010          8005          7996          8005          7996
Addition<25>/1000                                 +0.0014         +0.0014         13951         13970         13951         13970
Addition<32>/1000                                 +0.0010         +0.0009         13638         13651         13638         13651
Addition<200>/160                                 -0.1732         -0.1732         40301         33321         40300         33320
AdditionScalar<3>/1000                            +0.0016         +0.0016          2493          2497          2493          2497
AdditionScalar<10>/1000                           +0.0060         +0.0060          2701          2718          2701          2717
AdditionScalar<15>/1000                           -0.0024         -0.0024          2598          2592          2598          2592
AdditionScalar<25>/1000                           -0.0038         -0.0038          3730          3716          3730          3716
AdditionScalar<32>/1000                           +0.0062         +0.0062          4137          4162          4137          4162
AdditionScalar<200>/160                           -0.5626         -0.5626         19355          8466         19355          8466
Subtraction<3>/1000                               -0.0011         -0.0012          3162          3158          3162          3158
Subtraction<10>/1000                              -0.0027         -0.0026          4982          4969          4982          4969
Subtraction<15>/1000                              -0.0112         -0.0112          7820          7733          7820          7733
Subtraction<25>/1000                              +0.0181         +0.0181         13088         13325         13088         13325
Subtraction<32>/1000                              -0.0007         -0.0007         14514         14505         14514         14504
Subtraction<200>/160                              -0.1668         -0.1668         44586         37148         44586         37147
SubtractionScalar<3>/1000                         -0.0028         -0.0028          2540          2533          2540          2533
SubtractionScalar<10>/1000                        -0.0024         -0.0024          2682          2676          2682          2676
SubtractionScalar<15>/1000                        -0.0023         -0.0023          2603          2597          2603          2597
SubtractionScalar<25>/1000                        -0.0018         -0.0018          3570          3563          3570          3563
SubtractionScalar<32>/1000                        -0.0012         -0.0012          4223          4218          4223          4218
SubtractionScalar<200>/160                        -0.5070         -0.5070         20375         10044         20375         10044
Multiplication<3>/1000                            -0.0543         -0.0544          6171          5836          6172          5836
Multiplication<10>/1000                           -0.0617         -0.0617         11860         11128         11860         11128
Multiplication<15>/1000                           -0.0106         -0.0106         17456         17271         17456         17271
Multiplication<25>/1000                           -0.0114         -0.0114         27204         26893         27204         26893
Multiplication<32>/1000                           -0.0125         -0.0125         32704         32293         32703         32293
Multiplication<200>/160                           -0.3849         -0.3849         60557         37246         60557         37246
MultiplicationLeftScalar<3>/1000                  +0.0005         +0.0005          3086          3088          3086          3088
MultiplicationLeftScalar<10>/1000                 -0.0008         -0.0008          4486          4483          4486          4483
MultiplicationLeftScalar<15>/1000                 -0.0010         -0.0010          5840          5834          5840          5834
MultiplicationLeftScalar<25>/1000                 -0.0047         -0.0047         11350         11297         11350         11298
MultiplicationLeftScalar<32>/1000                 -0.0014         -0.0014         13892         13873         13892         13873
MultiplicationLeftScalar<200>/160                 -0.2646         -0.2646         28124         20682         28124         20682
MultiplicationRightScalar<3>/1000                 +0.0024         +0.0025          3090          3098          3090          3098
MultiplicationRightScalar<10>/1000                +0.0008         +0.0009          4596          4600          4596          4600
MultiplicationRightScalar<15>/1000                -0.0033         -0.0033          5832          5812          5832          5812
MultiplicationRightScalar<25>/1000                -0.0005         -0.0005         11353         11347         11353         11347
MultiplicationRightScalar<32>/1000                +0.0043         +0.0043         14041         14102         14041         14102
MultiplicationRightScalar<200>/160                -0.2600         -0.2600         28104         20796         28104         20796
Division<3>/1000                                  -0.0006         -0.0006          8977          8972          8977          8972
Division<10>/1000                                 -0.0095         -0.0095         14613         14474         14613         14473
Division<15>/1000                                 -0.0081         -0.0081         23109         22922         23108         22922
Division<25>/1000                                 -0.0081         -0.0081         37292         36992         37292         36992
Division<32>/1000                                 -0.0234         -0.0234         41693         40718         41692         40717
Division<200>/160                                 -0.1306         -0.1306         44486         38677         44486         38677
DivisionLeftScalar<3>/1000                        -0.0080         -0.0080          6683          6630          6683          6630
DivisionLeftScalar<10>/1000                       -0.0018         -0.0018          9255          9239          9255          9238
DivisionLeftScalar<15>/1000                       -0.0011         -0.0011         12180         12166         12180         12166
DivisionLeftScalar<25>/1000                       +0.0060         +0.0060         22381         22515         22381         22516
DivisionLeftScalar<32>/1000                       -0.0016         -0.0016         20159         20126         20159         20126
DivisionLeftScalar<200>/160                       -0.2528         -0.2528         28773         21499         28772         21499
DivisionRightScalar<3>/1000                       -0.0006         -0.0006          3784          3782          3784          3782
DivisionRightScalar<10>/1000                      -0.0014         -0.0014          5699          5691          5699          5691
DivisionRightScalar<15>/1000                      -0.0009         -0.0009          7490          7484          7490          7484
DivisionRightScalar<25>/1000                      +0.0031         +0.0031         13751         13793         13751         13793
DivisionRightScalar<32>/1000                      -0.0006         -0.0006         16712         16702         16712         16702
DivisionRightScalar<200>/160                      -0.2532         -0.2532         28412         21217         28411         21217
MultiplyAndAdd<3>/1000                            -0.0191         -0.0191          4382          4299          4382          4299
MultiplyAndAdd<10>/1000                           -0.0060         -0.0060         10238         10176         10238         10176
MultiplyAndAdd<15>/1000                           -0.0053         -0.0053         11696         11634         11696         11634
MultiplyAndAdd<25>/1000                           -0.0171         -0.0171         19185         18858         19185         18858
MultiplyAndAdd<32>/1000                           +0.0070         +0.0070         23783         23951         23783         23951
MultiplyAndAdd<200>/160                           -0.1252         -0.1252         61470         53776         61469         53776

Change-Id: Ib366d5753ed4f398667766384e05389d45e0d444
2021-06-18 15:04:17 -07:00
Alexander Karatarakis 51945e0619 Introduce benchmark for Jet operations
Run on (20 X 4300 MHz CPU s)
CPU Caches:
L1 Data 32 KiB (x10)
L1 Instruction 32 KiB (x10)
L2 Unified 1024 KiB (x10)
L3 Unified 14080 KiB (x1)
Load Average: 2.37, 3.00, 3.08
-----------------------------------------------------------------------------
Benchmark                                   Time             CPU   Iterations
-----------------------------------------------------------------------------
Addition<3>/1000                         2872 ns         2872 ns       240449
Addition<10>/1000                        5304 ns         5304 ns       100000
Addition<15>/1000                        8211 ns         8210 ns        78742
Addition<25>/1000                       14214 ns        14213 ns        46762
Addition<32>/1000                       13746 ns        13746 ns        50892
Addition<200>/160                       41228 ns        41228 ns        17183
AdditionScalar<3>/1000                   2514 ns         2514 ns       273996
AdditionScalar<10>/1000                  2733 ns         2733 ns       255508
AdditionScalar<15>/1000                  2622 ns         2622 ns       264291
AdditionScalar<25>/1000                  3753 ns         3753 ns       183508
AdditionScalar<32>/1000                  4254 ns         4254 ns       167016
AdditionScalar<200>/160                 18314 ns        18314 ns        38116
Subtraction<3>/1000                      3241 ns         3241 ns       206370
Subtraction<10>/1000                     5023 ns         5023 ns       139271
Subtraction<15>/1000                     8387 ns         8386 ns        89927
Subtraction<25>/1000                    14951 ns        14950 ns        48756
Subtraction<32>/1000                    14587 ns        14587 ns        47056
Subtraction<200>/160                    47175 ns        47175 ns        15574
SubtractionScalar<3>/1000                2572 ns         2572 ns       264468
SubtractionScalar<10>/1000               2713 ns         2713 ns       257920
SubtractionScalar<15>/1000               2621 ns         2621 ns       265289
SubtractionScalar<25>/1000               3593 ns         3593 ns       192266
SubtractionScalar<32>/1000               4255 ns         4255 ns       163738
SubtractionScalar<200>/160              19906 ns        19906 ns        35295
Multiplication<3>/1000                   6058 ns         6058 ns       114067
Multiplication<10>/1000                 11999 ns        11999 ns        58492
Multiplication<15>/1000                 17906 ns        17905 ns        39565
Multiplication<25>/1000                 27361 ns        27360 ns        25335
Multiplication<32>/1000                 33074 ns        33074 ns        20875
Multiplication<200>/160                 61364 ns        61362 ns        11542
MultiplicationLeftScalar<3>/1000         3104 ns         3104 ns       223720
MultiplicationLeftScalar<10>/1000        4549 ns         4549 ns       154366
MultiplicationLeftScalar<15>/1000        5921 ns         5921 ns       119294
MultiplicationLeftScalar<25>/1000       11429 ns        11428 ns        61685
MultiplicationLeftScalar<32>/1000       14094 ns        14094 ns        49941
MultiplicationLeftScalar<200>/160       28186 ns        28185 ns        24484
MultiplicationRightScalar<3>/1000        3110 ns         3110 ns       223333
MultiplicationRightScalar<10>/1000       4655 ns         4655 ns       150534
MultiplicationRightScalar<15>/1000       5890 ns         5890 ns       119746
MultiplicationRightScalar<25>/1000      11464 ns        11464 ns        61483
MultiplicationRightScalar<32>/1000      14243 ns        14242 ns        49492
MultiplicationRightScalar<200>/160      28282 ns        28281 ns        24604
Division<3>/1000                         9128 ns         9128 ns        77846
Division<10>/1000                       14811 ns        14811 ns        47682
Division<15>/1000                       23293 ns        23292 ns        30091
Division<25>/1000                       37313 ns        37313 ns        18608
Division<32>/1000                       41229 ns        41229 ns        16982
Division<200>/160                       44802 ns        44802 ns        15573
DivisionLeftScalar<3>/1000               6720 ns         6720 ns       104747
DivisionLeftScalar<10>/1000              9403 ns         9402 ns        75216
DivisionLeftScalar<15>/1000             12313 ns        12313 ns        57366
DivisionLeftScalar<25>/1000             22739 ns        22739 ns        30421
DivisionLeftScalar<32>/1000             20321 ns        20321 ns        34191
DivisionLeftScalar<200>/160             29018 ns        29017 ns        23908
DivisionRightScalar<3>/1000              3815 ns         3815 ns       182333
DivisionRightScalar<10>/1000             5750 ns         5750 ns       121691
DivisionRightScalar<15>/1000             7574 ns         7574 ns        92994
DivisionRightScalar<25>/1000            13953 ns        13953 ns        49250
DivisionRightScalar<32>/1000            16892 ns        16892 ns        41668
DivisionRightScalar<200>/160            28663 ns        28662 ns        24226
MultiplyAndAdd<3>/1000                   4399 ns         4399 ns       158635
MultiplyAndAdd<10>/1000                 10453 ns        10453 ns        68112
MultiplyAndAdd<15>/1000                 11830 ns        11830 ns        59598
MultiplyAndAdd<25>/1000                 19624 ns        19624 ns        36240
MultiplyAndAdd<32>/1000                 25539 ns        25538 ns        29066
MultiplyAndAdd<200>/160                 65362 ns        65358 ns        11086

Change-Id: Ie62492b3fd19ff9d3394f90bd00f0aa01522fc2a
2021-06-16 16:17:52 -07:00
Fuhao Shi ec4f2995bb Do not check MaxNumThreadsAvailable if the thread number is set to 1.
- this saves the sysfs cost in MaxNumThreadsAvailable.

Change-Id: I6b33ceae363da19346341be95abbd89d7b7b0f2f
2021-03-24 22:16:45 +00:00
Sameer Agarwal 98f639f542 Add a macro CERES_GET_FLAG.
This is needed to add a layer of indirection which will allow
us to use gflags in the public version and absl inside Google.

Change-Id: I32f3da23200a01c9b658bbf8aaa66cb8fddc2cc3
2021-03-18 11:07:57 -07:00
Daniel Henell 766f2cab55 Reduce log spam in covariance_impl.cc.
Make the rank deficiency warning in the covariance module a VLOG(1) instead of
LOG(ERROR) since this is a commonly occuring case.

Change-Id: Id46eba6dcf9afbaf0554c2d6f230b2af7a1fbdea
2021-03-17 13:55:00 +00:00
Sameer Agarwal 2b32b32124 Revert "Group specializations into groups of four"
This reverts commit 4ba244cdbc.

Reason for revert: This commit causes CI failures.

Change-Id: I954f2b8f093e39e3b52ca91b331591b73e646554
2021-02-17 18:38:43 +00:00
Tobias Schlüter 313caf1aec Allow Unity build.
Two parts:
- missing include guard in solver_utils.h
- exclude schur_specializations from unity build.  This
  can only be done with cmake >= 3.16, so only allow
  unity build for these versions.

Cuts build time by 5 minutes with default settings.
libceres.a shrinks from 7549968 bytes to 7009696 bytes.

Change-Id: I833ac8266623da0e725cc2f07a6415b4fa72bc18
2021-02-16 08:30:36 +09:00
Tobias Schlüter 4ba244cdbc Group specializations into groups of four
Genrerate the specialization files by grouping the specializations into
five groups, cutting build time by three minutes (roughly 20%) in my
tests.

Change-Id: Ifd6a4523a47346c5e84c1cda15b7abba60d8e953
2021-02-12 19:56:53 +09:00
Tobias Schlüter d77a8100a3 Make miniglog's InitGoogleLogging argument const.
This is in line with glog.  Also, the argument is unused.  Third try.

Change-Id: I23331ae26089956454d66ab9e93fc04d4b24ed2e
2021-02-08 00:56:02 +00:00
Sameer Agarwal d15b1bcd3e Increase tolerance in small_blas_test.cc
Change-Id: I7b8460bec65e56029d01c293e83743e99a57d10c
2021-01-12 09:15:05 -08:00
Austin Schuh 64029909b3 Fix -Wno-maybe-uninitialized error
One of my compilers couldn't deduce that Chunk was assigned before being
used based on the context.  Make it more obvious...

Change-Id: I1e331c6c02a2783eff8db03c6359823ac3c46686
2021-01-04 14:44:49 -08:00
Austin Schuh 21294123d7 Fix nonnull arg compared to NULL error.
external/com_google_ceres_solver/internal/ceres/rotation_test.cc: In member function 'bool ceres::internal::IsNormalizedQuaternionMatcher::gmock_Impl<arg_type>::MatchAndExplain(typename testing::internal::ConstRef<arg_type>::type, testing::MatchResultListener*) const [with arg_type = const double (&)[4]]':
external/com_google_ceres_solver/internal/ceres/rotation_test.cc:74:3: error: nonnull argument 'arg' compared to NULL [-Werror=nonnull-compare]
   if (arg == NULL) {
   ^~

Change-Id: I21abd87e97e44188580f4926b3700dc321fecb0e
2021-01-04 14:44:11 -08:00
Austin Schuh 1dd4174109 Fix -Wno-format-nonliteral
GCC doesn't like printf formats which aren't char strings.

Change-Id: I41464ba336076b892d893a5729611488c159f01d
2021-01-04 14:40:44 -08:00
Austin Schuh 6c106bf510 Fix -Wmissing-field-initializers error
Clang was complaining that fields were uninitialized.

Change-Id: Iff76fb2ebf823eb072465c0b0381a4a5cdee0fa9
2020-12-23 22:50:28 -08:00
Austin Schuh e0e14a5cdb Fix errors found by -Werror
"'const' type qualifier on return type has no effect" is one of the
errors, and an unused parameter for another.

Change-Id: Ib4bc245d992c1fc1bea0b25d5396871ca1df8411
2020-12-23 22:37:54 -08:00
Sameer Agarwal d45ec47b58 Fix a typo in schur_eliminator.h
Change-Id: Ib2c6ea9598d49ee77e2f0429686045cf58cd8574
2020-11-18 08:59:06 -08:00
Sameer Agarwal bb127272f9 Fix typos.
Contributed by Ishamis@, IanBoyanZhang@, gkrobner@ & mithunjacob@.

Change-Id: Iab3c19a07a6f3db2486e3557dcb55bfe5de2aee5
2020-10-19 09:32:47 -07:00
Taylor Braun-Jones 3f6d273676 Unify symbol visibility configuration for all compilers
This makes it possible to build unit tests with shared libraries on MSVC.

Change-Id: I1db66a80b2c78c4f3d354e35235244d17bac9809
2020-10-15 16:56:07 -04:00
Nikolaus Demmel 600e8c529e fix minor typos
all timing values in the summary are initialized to -1, so the one
+1 is likely an oversight.

Change-Id: Ie355f3b7da08a56d49d19ca9a5bc48fe5581dee3
2020-10-12 23:01:02 +02:00
Sameer Agarwal 8bfdb02fb1 Rewrite uses of VLOG_IF and LOG_IF.
VLOG_IF's evaluation order is ambiguous - does it mean
`if (cond) VLOG(lvl)` or `if (VLOG_IS_ON(lvl) && cond) LOG(INFO)`?
In particular, the way it works now is inconsistent with the way the
rest of the LOG macros evaluate their arguments.
Fixing this would be hard, and the macro's behavior would still surprise
some people. Replacing it with an if statement is simple, clear, and unambiguous.

Change-Id: I97a92d17a932c0a5344a1bf98d676308793ba877
2020-10-12 18:34:24 +00:00
Nikolaus Demmel 542613c13d minor formatting fix for trust_region_minimizer.cc
Change-Id: I18ba27825fc23dd0e9e3e15dc13fc0833db01b5b
2020-10-06 22:49:32 +02:00
Sameer Agarwal 6d9e9843d8 Remove inclusion of ceres/eigen.h
The initial reason for this is because of a previous reformatting CL
triggered a macro redefinition warning in the schur eliminator. But
actually it was worse because the reordering had caused the macro
definition to be ignored and caused a performance regression.

This simplifies the generated files, fixes some formatting errors
and recovers the performance.

Change-Id: I9dbeffc38743b3f24b25843feec2e26a73188413
2020-09-28 19:20:24 +00:00
Sameer Agarwal eafeca5dcb Fix a logging bug in TrustRegionMinimizer.
Upon encountering an unsuccessful step (one where the cost goes up)
the the trust region minimizer failed to populate the gradient norm
in the IterationSummary. This would cause the gradient norm to be
logged as zero which is incorrect. Instead it should be the gradient
norm at the current point.

This CL fixes this issue.

Before:
iter      cost      cost_change  |gradient|   |step|    tr_ratio  tr_radius  ls_iter  iter_time  total_time
   0  1.115206e+07    0.00e+00    1.90e+07   0.00e+00   0.00e+00  1.00e+04        0    2.72e-01    1.33e+00
   1  3.687552e+06    7.46e+06    1.84e+08   2.86e+03   6.91e-01  1.06e+04        1    1.32e+00    2.65e+00
   2  3.670266e+10   -3.67e+10    0.00e+00   3.27e+03  -1.07e+04  5.30e+03        1    7.52e-01    3.40e+00
   3  4.335397e+07   -3.97e+07    0.00e+00   2.74e+03  -1.16e+01  1.32e+03        1    7.28e-01    4.13e+00
   4  1.345488e+06    2.34e+06    4.12e+07   1.55e+03   6.87e-01  1.40e+03        1    9.31e-01    5.06e+00
   5  5.376653e+05    8.08e+05    9.99e+06   6.64e+02   7.46e-01  1.59e+03        1    9.64e-01    6.03e+00

After:
iter      cost      cost_change  |gradient|   |step|    tr_ratio  tr_radius  ls_iter  iter_time  total_time
   0  1.115206e+07    0.00e+00    1.90e+07   0.00e+00   0.00e+00  1.00e+04        0    2.37e-01    1.13e+00
   1  3.687552e+06    7.46e+06    1.84e+08   2.86e+03   6.91e-01  1.06e+04        1    1.08e+00    2.21e+00
   2  3.670266e+10   -3.67e+10    1.84e+08   3.27e+03  -1.07e+04  5.30e+03        1    7.50e-01    2.96e+00
   3  4.335397e+07   -3.97e+07    1.84e+08   2.74e+03  -1.16e+01  1.32e+03        1    7.13e-01    3.67e+00
   4  1.345488e+06    2.34e+06    4.12e+07   1.55e+03   6.87e-01  1.40e+03        1    9.01e-01    4.57e+00
   5  5.376653e+05    8.08e+05    9.99e+06   6.64e+02   7.46e-01  1.59e+03        1    9.36e-01    5.51e+00

Change-Id: Iae538fe089be07c7bb219337a6f1392f7213acfe
2020-09-28 12:19:45 -07:00
Nikolaus Demmel d3f66d77f4 fix formatting generated files (best effort)
- update file generator scripts / templates so generated files adhere
  to clang-format
- A few exceptions are not fixed, where the file generation results in
  lines of different width. To properly fix this would make the code
  more complicated and it's not that important for generated files
  anyway.
- note that generated files are excluded in ./scripts/format_all.sh

Change-Id: I4f42c83d1fec01242eada5e7ce6c1a5192234d37
2020-09-28 02:24:43 +02:00
Nikolaus Demmel a9c7361c8d minor formatting fix (wrongly updated in earlier commit)
Change-Id: I544635fd936cb5b7f7bd9255876641cd5a9590c6
2020-09-28 02:19:02 +02:00
Nikolaus Demmel 7b8f675bfd fix formatting for (non-generated) internal source files
- Change formatting standard to Cpp11. Main difference is not having
  the space between two closing >> for nested templates. We don't
  choose c++14, because older versions of clang-format (version 9
  and earlier) don't know this value yet, and it doesn't make a
  difference in the formatting.
- Apply clang-format to all (non generated) internal source files.
- Manually fix some code sections (clang-format on/off) and c-strings
- Exclude some embedded external files with very different formatting
  (gtest/gmock)
- Add script to format all source files

Change-Id: Ic6cea41575ad6e37c9e136dbce176b0d505dc44d
2020-09-21 02:52:07 +02:00
Sameer Agarwal 921368ce31 Fix a number of typos in covariance.h
Also some minor cleanups in covariance_impl.h

Thanks to Lorenzo Lamia for pointing these out.

Change-Id: Icb4012a367fdd1f249bc1e7019e0114c868e45b6
2020-09-09 09:39:42 -07:00
Morten Hannemose 8cbd721c19 Add erf and erfc to jet.h, including tests in jet_test.cc
erf is necessary for evaluating Gaussian functions.
erfc was added because it is so similar to erf.

Change-Id: I5e470dbe013cc938fabb87cde3b0ebf26a90fff4
2020-09-03 17:54:20 +02:00
Sameer Agarwal 31366cff29 Benchmarks for dynamic autodiff.
This patch is from Clement Courbet. courbet@google.com

Change-Id: I886390663644733bfa5b7b52b0c883079e793726
2020-09-01 09:25:02 -07:00
Sameer Agarwal 41d05f13d0 Fix lint errors in evaluation_callback_test.cc
Change-Id: I63eb069544ad0d8f495490fe4caa07b9f04f7ec2
2020-08-04 14:56:33 -07:00
Sameer Agarwal 4b67903c1f Remove unused variables from problem_test.cc
Change-Id: Ia1a13cfc6e462f6d249dcbf169ad34831dd93ec2
2020-08-04 14:40:50 -07:00