Commit Graph

44 Commits

Author SHA1 Message Date
Janick Martinez Esturo c2da96082b Fix Eigen >= 3.3 compilation if EIGEN_DONT_VECTORIZE set
Would result in compilation error

include/ceres/jet.h:296:59: error: requested alignment is not a positive power of 2
   alignas(kAlignment) Eigen::Matrix<T, N, 1, kAlignOrNot> v;

because CERES_JET_ALIGN_BYTES = EIGEN_MAX_ALIGN_BYTES = 0 in that case.

Change-Id: I247653d3b7555e80891d3fb78676acfa302a9e1d
2018-01-12 17:50:01 +01:00
Sameer Agarwal 2a956099d4 Add missing Eigen traits to Jets
Add highest and lowest traits to the Jet implementation.

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

Change-Id: I7c68fa8e2baa7742880d3faa21f366352e48aacf
2017-09-27 03:57:49 +00:00
Alex Stewart 5eae62348d Add compound with scalar operators for Jets.
Change-Id: Ie47771d8c9df22ddeb6b643ae8a751860d892d67
2017-07-06 19:10:34 +01:00
Julien Pilet e5dceb3ab0 Fix Jet/Eigen compatibility for Eigen > 3.3
Honour the digits10 NumTraits member introduced in Eigen 3.3.

Change-Id: If20183332beef8335b7758cdb58859a43fc59970
2017-02-28 10:34:26 +01:00
Alex Stewart c1ebbfc79b Require Eigen >= 3.3 to define ScalarBinaryOpTraits in Jet.
- ScalarBinaryOpTraits was introduced in Eigen 3.3, and thus breaks
  compilation of Ceres for Eigen versions < 3.3.
- Reported as issue #252 by AustinDeric:
  https://github.com/ceres-solver/ceres-solver/issues/252

Change-Id: Ie9b7dace17709c348b18b297f2d5306b054ce4b0
2017-02-13 16:14:40 +00:00
Chris Sweeney 9a195d91de Specify ScalarBinaryOpTraits for Jet types.
This commit extends the use of Jets with Eigen matrices and arrays
by enabling the use of binary operators (such as scalar addition,
multiplication, as well as matrix multiplication) when one Eigen
matrix/array is of type Jet and the other is a scalar type. This
should increase performance since Jet types have optimized
scalar-to-jet binary operations.

Change-Id: Ia756064845d845cefcf0abb16d366331d2824b52
2017-02-10 19:50:33 +00:00
Alex Stewart 9321b620ac Fix detection of deprecated Bessel function names on MSVC.
- MSVC deprecated the standard POSIX names for Bessel functions in
  favour of underscore prefixed versions.
- Previously we were checking for the presence of the newer underscore
  functions via a macro, which fails as the functions are not defined
  as macros.
- Now we check via a check_cxx_source_compiles() if the newer underscore
  prefixed versions exist when compiling on MSVC and use a new Ceres
  configuration #define to switch on their presence in jet.h

Change-Id: I430880bde2981d12f4d03dbc94d903b9842e887e
2017-01-27 22:31:53 +00:00
Alex Stewart 3fa415bd0c Enable support for AVX instructions for Jets.
- Eigen versions < 3.3 only supported SIMD instructions that required
  16-byte alignment (SSE), whereas Eigen >= 3.3 also supports AVX
  instructions which require 32+-byte alignment.
- Previously we only ever requested 16-byte alignment for Jets (if >=
  C++11 was enabled) which resulted in Eigen assertions being triggered
  on some compilers as reported as Issue #251:
  https://github.com/ceres-solver/ceres-solver/issues/251.
- Now we use Eigen’s EIGEN_MAX_ALIGN_BYTES macro, defined in Eigen >=
  3.3 to specify the byte alignment for Jets when C++11 is enabled for
  Eigen >= 3.3.  For Eigen versions < 3.3, we maintain the previous
  behaviour of 16.

Change-Id: I749af7a70ae794e0c2a59301128db781e338422c
2017-01-05 19:12:45 +00:00
Alex Stewart 6519e78920 Fix use of alignas(0) which is not ignored on GCC.
- alignas(0) should be ignored, however it results in a build error on
  GCC, so instead default to the alignment of double in Jets if
  we cannot align to 16-byte boundaries on the platform, but are
  compiling with C++11.

Change-Id: I2e54c69516ea2e1447a8bdc138b2dd70050c6dad
2016-11-12 21:45:57 +00:00
Alex Stewart b4e27240b2 Use default alignment if alignof(std::max_align_t) < 16 with C++11.
- As per Andrew Hunter’s comments in the commit which added Jet
  alignment when using C++11 here:
  https://ceres-solver-review.googlesource.com/#/c/7100, there is wide
  lattitude in the standard about what the maximum supported alignment
  can be.
- Previously, we were forcing the alignment to 1, if the value of
  alignof(std::max_align_t), which we use as a proxy for the maximum
  supported alignment on the platform, was < 16.
- An alignment of 1 is not valid for Jets, as it would weaken the
  natural alignment of the types within a Jet, which would typically be
  4 (32-bit systems) or 8 (64-bit systems), thus resulting in a compiler
  error.
- This was reported as issue 235 for Clang 3.8 on i386:
  https://github.com/ceres-solver/ceres-solver/issues/235.

Change-Id: Ie39e5499c64f9231f29ebf4392992b5c9ce2e385
2016-11-12 17:18:25 +00:00
Rob Carroll e69bd2a206 Add missing T() wrappers for constants.
Needed for instantiation with Jet<float,N>.

Change-Id: I8ec07a844cc911a3c7f24c25797bd21c0bee07b5
2016-10-31 12:51:44 -07:00
Sameer Agarwal 44044e25b1 Update the NumTraits for Jets
1. Use AVX if EIGEN_VECTORIZE_AVX is defined.
2. Make the cost of division same as the cost of multiplication.

These are updates to the original numtraits update needed for eigen 3.3
that Shaheen Gandhi sent out.

Change-Id: Ic1e3ed7d05a659c7badc79a894679b2dd61c51b9
2016-08-31 06:19:08 -07:00
Shaheen Gandhi bfc916cf1c Allow ceres to be used with the latest version of Eigen
Change-Id: Ief3b0f6b405484ec04ecd9ab6a1e1e5409a594c2
2016-08-31 12:45:47 +00:00
Alex Stewart ff11d0e63d Use _j[0,1,n]() Bessel functions on MSVC to avoid deprecation errors.
- Microsoft deprecated the POSIX Bessel functions: j[0,1,n]() in favour
  of _j[0,1,n](), it appears since at least MSVC 2005:
  https://msdn.microsoft.com/en-us/library/ms235384(v=vs.100).aspx.
- As this occurs in jet.h (templated public header), although Ceres
  suppresses the warning when it itself is built (to suppress a warning
  about the insecurity of using std::copy), it will crop up again in
  client code (without this fix) unless it is explicitly suppressed
  there also.
- Raised as Issue #190:
  https://github.com/ceres-solver/ceres-solver/issues/190.

Change-Id: If7ac5dbb856748f9900be93ec0452a40c0b00524
2016-06-29 09:33:45 +01:00
Mike Vitus 0c63bd3efb Add floor and ceil functions to the Jet implementation.
Change-Id: I72ebfb0e9ade2964dbf3a014225ead345d5ae352
2016-04-15 10:47:22 -07:00
Keir Mierle efe61b089b Make Jet string output more readable
Change-Id: Iebab111ab136c52f88180688ccb684584ab21dea
2016-03-16 11:27:25 -07:00
Andrew Hunter d80c112168 Tweak alignment hint implementation for Jets
I169b637a1e2a106956b536c41d6a514a266e7cc0 marked Jets (in C++11) as
aligned to 16 bytes, and enabled Eigen vectorization.  However, to
implement this, we added Eigen includes to port.h.

Turns out this broke some other tricks Ceres uses (redefining Eigen
constants for better performance), so we don't want to do that. Move
most of the implementation to jet.h where it is safe.

Change-Id: I47c6fc4180db1ff674bc660723dd5a2b84254e0d
2015-12-11 14:50:19 -08:00
Andrew Hunter 5667505f35 Align Jet matrices where supported
We currently don't align the infinitesimal part of a Jet to a 16-byte
boundary (and thus force Eigen to avoid using SSE ops)--as a member of a
larger struct, we couldn't guarantee Jets would be allocated on
appropriately-aligned boundaries.  However, C++11 adds better support
for requesting alignment: we can use it to guarantee the members will be
properly aligned, and tell Eigen to vectorize.

There is a significant gotcha here: the standard gives wide latitude to
implementations as to which alignments they choose to support.  If we
ask for 16 and the system only supports 8, we may have misaligned
Jets. So we test (using alignof(std::max_align_t)) that the current
system supports 16-byte aligned values; if not, we fall back to the
current solution.

Two other small notes:
- This is obviously gated on C++11 support, and
  thus we put the logic in port.h and export some useful #defines.

- GCC 4.8.x has a
  bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56019) that has
  max_align_t in the wrong namespace.  This will not be a problem with a
  modern GCC, but add a small workaround since many systems still ship 4.8.

This results (on a x86 workstation) in a 60% speedup in Jacobian
evaluation on bin/simple_bundle_adjuster problem-16-22106-pre.txt.

Change-Id: I169b637a1e2a106956b536c41d6a514a266e7cc0
2015-12-08 01:09:07 +00:00
Alessandro Gentilini 49c86018e0 Add Bessel functions in order to use them in residual code.
See "How can I use the Bessel function in the residual function?" at
https://groups.google.com/d/msg/ceres-solver/Vh1gpqac8v0/NIK1EiWJCAAJ

Change-Id: I3e80d9f9d1cadaf7177076e493ff46ace5233b76
2015-10-22 18:47:02 +00:00
Sameer Agarwal 3c52ef2fab More lint changes from William Rucklidge.
Change-Id: I3594ed46e78243034389cad158243e11dd1dc2b0
2015-05-05 11:34:05 -07:00
Sameer Agarwal 5c0954438f Lint changes from William Rucklidge.
Change-Id: I6592b61451ead8f0407bec134fcf4b56ba22ffb9
2015-05-05 11:25:42 -07:00
Russell Smith 77e80aecf7 Additional special cases in the handling of pow(Jet,Jet).
I think this is all of the cases. These cases arise because pow(a,b) is limited
to real valued results, if the argument and result were complex valued then
these cases would disappear.

NOTE: Since there is so much special casing here, it is worth checking to see
if cpow() is implemented in terms of pow(), and what might be the consequences
of using cpow() on the type std::complex<Jet<double, N> >. It is *possible*
that a separate implementation of cpow might be required also.

Also some comment fixes.

Change-Id: Ia1e38df4cdcb548f778304c2854cacba6e1556ff
2015-04-29 12:38:04 +00:00
Sameer Agarwal 365084f976 Lint changes from William Rucklidge.
Change-Id: I5a9683333fbab189058076cb2053f8f7afc7096a
2015-04-16 12:35:51 -07:00
Russell Smith a6f39a939d Fix bug where pow(JetA,JetB) returned wrong result for JetA==0.
Change-Id: Ife7f6f3aca06322fa414ef747008d2b4dc468a57
2015-04-16 18:21:21 +00:00
Keir Mierle 7492b0d8de Update copyright headers with new year and URL
Since Ceres is moving to using GitHub for issues, and the Google
Code URL in the current copyright header will soon become invalid,
update all the headers.

Change-Id: I1fce70375d1bcf098591f07b4d8f01a5c1e0789c
2015-03-18 05:43:23 +00:00
Julius Ziegler c2fe657e32 Fix typo in comment section: .a[...] -> .v[...]
Change-Id: I2116645938c4552ed495e371bfdbcaf62a443461
2015-02-12 20:27:30 +00:00
Sameer Agarwal a0c282adbd Add EIGEN_STRONG_INLINE annotation to jet.h
This improves performance when using MSVC on Windows. On GCC
there will be no effect.

Change-Id: I555a81ff6823c2855d64773073f75af50c48d716
2014-08-25 08:32:41 -07:00
Filippo Basso 91da310aeb Added epsilon() method to NumTraits<ceres::Jet<T, N> >.
Change-Id: Ie849b4ae5c7260976ebf2fb21a00f13d1e6bb647
2014-01-19 14:35:23 +01:00
Sameer Agarwal 8c155d51fa Speed up the application of robust loss functions.
Since we added special handling for the case for rho[2] < 0,
the bulk of CorrectJacobian is pointless in the common case.
So add a simple one dimensional loop which rescales the Jacobian.
This speeds up this method immensely.

The robustification of a Jacobian gets speeded up by > 50%.

Change-Id: I97c4e897ccbb5521c053e1fb931c5d0d32f542c7
2013-11-08 22:18:14 -08:00
Sameer Agarwal ecae1f07ea Lint cleanups.
Thanks to William Rucklidge and Jim Roseborough.

Change-Id: Ibc1a2daf0af878f737ea43e878990ead4e73f63d
2013-09-24 11:20:19 -07:00
Tim Langlois 91087e8936 Added some small optimizations to the jet class (initialize values
directly from eigen expressions, instead of creating a temporary). Also
changed several variable names from temp to tmp to be consistent with
the code base.

Change-Id: I3f7b834cedca9c4af8e5e086237b40301dbde619
2013-09-23 20:39:28 +00:00
Sameer Agarwal 11bf5ffb96 Add RequireInitialization = 1 to NumTraits::Jet.
Thanks to Nima Kevian for reporting this.

Change-Id: I9c45f4cabc8d5ce246c2a6ebe102161c6a771df5
2013-09-19 22:46:29 +00:00
Sameer Agarwal f0b071bac4 Lint and other fixes from William Rucklidge
Change-Id: Ic18561a5cdadccc75e97818fa4422bb5d9d43df9
2013-05-31 13:22:51 -07:00
Johannes Schönberger a8d38d438a Add sinh, cosh, tanh and tan functions to automatic differentiation
Change-Id: I6eb43fe9b340d4074ed3eed1461dda315f6e8ce8
2013-05-30 00:39:43 +02:00
Sameer Agarwal 487250eb27 Minor cleanups.
1. Further BLAS and heap allocation cleanups in  schur_eliminator_impl.h
2. Modularize blas.h using macros.
3. Lint cleanups from William Rucklidge.
4. Small changes to jet.h
5. ResidualBlock now uses blas.h

Performance improvements:

For static and dynamic sized blocks, the peformance is not changed much.

-use_quaternions -ordering user -linear_solver sparse_schur

                                        master         change
problem: 16-22106
gcc                                        3.4            3.3
clang                                      2.8            2.7

problem: 49-7776
gcc                                        1.7            1.7
clang                                      1.4            1.4

problem: 245-198739
gcc                                       80.1           79.6
clang                                     80.6           76.2

problem: 257-65132
gcc                                       12.2           12.0
clang                                     10.4           10.2

problem: 356-226730
gcc                                       99.0           96.8
clang                                     88.9           88.3

problem: 744-543562
gcc                                      361.5          356.2
clang                                    352.7          343.5

problem: 1024-110968
gcc                                       45.9           45.6
clang                                     42.6           42.1

However, performance when using local parameterizations is
significantly improved due to residual_block.cc using blas.h

-use_quaternions -use_local_parameterization -ordering user -linear_solver sparse_schur

                                        master         change
problem: 16-22106
gcc                                        3.6            3.3
clang                                      3.5            2.8

problem: 49-7776
gcc                                        1.8            1.6
clang                                      1.7            1.4

problem: 245-198739
gcc                                       79.7           76.1
clang                                     79.7           73.0

problem: 257-65132
gcc                                       12.8           11.9
clang                                     12.3            9.8

problem: 356-226730
gcc                                      101.9           93.5
clang                                    105.0           86.8

problem: 744-543562
gcc                                      367.9          350.5
clang                                    355.3          323.1

problem: 1024-110968
gcc                                       43.0           40.3
clang                                     41.0           37.5

Change-Id: I6dcf7476ddaa77cb116558d112a9cf1e832f5fc9
2013-04-14 09:33:11 -07:00
Sameer Agarwal 25ac54807e Speed up Jets.
Change-Id: I101bac1b1a1cf72ca49ffcf843b73c0ef5a6dfcb
2013-04-03 18:51:27 -07:00
Keir Mierle 8e68ff395b Zero-initialize Jet derivative components.
Change-Id: I9606aadb1a1f275608f6f332858af9258a120b05
2012-08-14 14:40:42 -07:00
Sameer Agarwal 1d7c49224a Add shared library targets.
Fix a grammo from a previous CL.

Change-Id: Icc683d3a73a542519a6ccefc0f653664f236c24b
2012-07-17 10:23:35 -07:00
Sameer Agarwal 45ccb51701 Drop alignment requirements for Jets.
Change-Id: I7cd1e8f73c6d3e0b9369e567149205075bfbcd82
2012-07-16 21:13:38 -07:00
Keir Mierle efe7ac60a0 Port Ceres to Windows
This is a preliminary, but full, port of Ceres to Windows.
Currently all tests compile and run, with only system_test
failing to work correctly due to a path issue.

Change-Id: I4152c1588bf51ffd7f4d9401ef9759f5d28c299c
2012-06-24 23:22:04 -07:00
Keir Mierle 517e196ca8 Fix IsInfinite on jets
Change-Id: Ibe1933caf681829b978b507a87539d1b75c7c54b
2012-06-24 17:47:13 -07:00
Keir Mierle 58ede2772e Add a portable floating point classification API
Ceres has traditionally battled with portability issues
when trying to classify floating point values as one
type or another. For example, in C99 'isnan' is a
macro. Since it is a macro, it is impossible to
override the name in other namespaces.

Instead of trying to use preprocessor hacks to work
around the issue, define our own set of camel-case
names for use internally and by Ceres clients. For
example do this:

  template<typename T>
  void MyFunction(T x, T y) {
    if (ceres::IsNaN(x)) {
      ...
    }
  }

instead of using "isnan" or "std::isnan". Note that
while GCC and Apple GCC both import 'isnan' into
the std namespace, it is not standard until C++11
which Ceres will not require for some years.

Change-Id: Ibcc96a8bb4ba63aa67cbbc58658b2e5671cd5824
2012-06-24 17:42:53 -07:00
Sameer Agarwal eb893404fa Fix alignment issues with Jets.
1. Test that reproduces the failure on macos.
2. Move the alignment macros from manual_constructor.h
   to macros.h and rename them to prevent conflicts.
3. The inline array used by FixedArray is now aligned.
4. Jet has been modified to be eigen friendly.

Change-Id: I4563847a767a92156dabab1ab420f0cdddb8ba77
2012-06-18 11:08:20 -07:00
Keir Mierle 8ebb073038 Initial commit of Ceres Solver. 2012-04-30 23:09:08 -07:00