Commit Graph

9 Commits

Author SHA1 Message Date
Darius Rueckert a60136b7aa Add COMMENT ExpressionType
The comment expression allows the user to insert single-line
comments into the generated code. These will not be moved or
optimized away.

Comment expressions should make it easier to understand the
generated autodiff code.

Change-Id: Ie87d0698aa6af2aac8a437a13b25e0fef33dbfdc
2019-12-18 09:44:33 +01:00
Darius Rueckert 47e784bb41 NULL-jacobians are handled correctly in generated autodiff code
The autodiff code generator is extended in the following ways:
  - Evaluate the complete jacobian into a temporary array
  - Copy the temporary jacobian to the result if != NULL

Change-Id: If5ed0bff3b31e93a2d7d5dc718862cb648dba474
2019-12-10 15:19:48 +01:00
Darius Rueckert edd54b83e1 Update Jet.h and rotation.h to use the new IF/ELSE macros
Also use branchless implementation for isfinite(Jet),
isinf(Jet), isnan(Jet), and isnormal(Jet).

Change-Id: Ia881df03ba873e0560d67e976ab1e99e199eb523
2019-12-09 18:30:30 +01:00
Darius Rueckert 848c1f90c0 Update return type in code generator and add tests for logical functions
Change-Id: I128f8ccc21c2c3a2c79674ac28dd9a5b26b58772
2019-12-09 17:57:10 +01:00
Darius Rueckert 5010421bb7 Add the expression return type as a member to Expression
Before this patch the return type was implicitly defined by the
ExpressionType. This patch separates this connection and allows
each Expression to have one of the predefined types (scalar,
boolean, void).

This patch is required to add support for the functions isfinite,
isinf, isnan, and isnormal. These are function taking a double and
returning a bool.

This also moves some complexity of the code generator to the
Expression, because the generator can direclty get the c++ type.

Change-Id: I8b32bab1bfab2f668875e506d6f3b789a5d1f3fd
2019-12-09 17:13:05 +01:00
Darius Rueckert f4dc670ee8 Improve testing of the codegen system
- Move codegen tests to a sub directory
- Add tests for all functions of Expression, ExpressionRef, and ExpressionGraph
- Respect dependencies during tests: The ExpressionGraph test doesn't
  use ExpressionRef anymore.

The new tests revealed a few bugs so the following changes were made:

- Expression::MakeNop now resets the current expression with the default
  constructed NOP expression
- ExpressionGraph::Insert now updates the lhs_id the same way as
  InsertBack()

Change-Id: I6a18925c1e4d972c29ec1219f2073b4eaf2df737
2019-12-09 15:13:07 +01:00
Darius Rueckert 572ec4a5a5 Rework Expression creation and insertion
Objects of 'Expression' can now be freely created and copied around.
This creation does NOT add them to the active ExpressionGraph any
more. The insertion into the graph is now done by ExpressionRef,
which explicitly call graph.add(...) in each operation.

This change brings the following advantages:

1. 'Expression' is now stand-alone and side-effect free
   - Remove the dependency Expression->ExpressionGraph
   - Expressions can be created by the optimizer

2. Explicit graph insertion
  - Previously CreateCompileTimeConstant not only created an
    expression, but also inserted it into the active graph. Now
    this insertion is done explicitly by ExpressionRef

3. It is now easier to insert new types and members
  - Should be straight forward now, because we got rid of the
    3-way dependency
  - This is a preparation patch for the new return-type member in
    https://ceres-solver-review.googlesource.com/c/ceres-solver/+/16224

Change-Id: Icef2fe529a4db001a10d1fb6816c9dc681b14ff2
2019-12-06 13:35:21 +01:00
Darius Rueckert d160264403 Autodiff Codegen Part 4: Public API
The public API for the Autodiff Codegen system consist of a single
function, GenerateCodeForFunctor. This function takes as template
argument a cost functor type and the residual/parameter structure.
The output is the C++ for the residual and derivative. This class
mainly serves as a wrapper for the different codegen modules.

Change-Id: I8ee974199219805d54eed5e07c0e8d1394940779
2019-12-02 17:09:03 +01:00
Darius Rueckert d1703db45a Moved AutoDiffCodeGen macros to a separate (public) header
User defined cost functors have to include this new header
instead of internal/expression_ref.h. This hides some
complexity of ExpressionRef and reduces compile time outside
of code generation mode.

This patch also removes the dependency ExpressionRef->Jet.

Change-Id: Ie3f93648775e14881dc5cfab213bbc983c6cfeee
2019-12-02 16:17:19 +01:00