Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
81a9917
Update for regex 20 lookbehind test.
MaxSagebaum Jun 23, 2025
eff33c2
Fix for name lookup issues with MSVC.
MaxSagebaum Aug 8, 2025
bb405b6
Add missing files.
MaxSagebaum Aug 8, 2025
5169cbf
Refactor of autodiff with generalized traversal.
MaxSagebaum Aug 9, 2025
97470ba
Handling of expression lists.
MaxSagebaum Aug 9, 2025
965af06
Handling of expresson terms.
MaxSagebaum Aug 9, 2025
b3dc845
Handling of function calls.
MaxSagebaum Aug 11, 2025
358226d
Added special handling of math functions.
MaxSagebaum Aug 11, 2025
8166f0f
Added declarations and statements to simple_traversal.
MaxSagebaum Aug 11, 2025
00be8ff
Handling if/else statements.
MaxSagebaum Aug 11, 2025
dad71ef
Added handling of direct return.
MaxSagebaum Aug 11, 2025
e1ab97b
Stub handling of value declarations.
MaxSagebaum Aug 11, 2025
0c8983d
Added example for non differential variable.
MaxSagebaum Aug 11, 2025
1d23291
Added handling of while and do while loops.
MaxSagebaum Aug 11, 2025
be60ab2
Handling of for loops and added special functions.
MaxSagebaum Aug 12, 2025
f1b5de7
Unified function call handling.
MaxSagebaum Aug 12, 2025
6932cde
Proper handling of initializer expressions.
MaxSagebaum Aug 12, 2025
8548b9b
Fix initializer problem.
MaxSagebaum Aug 12, 2025
093f291
Suffix can now be user defined.
MaxSagebaum Aug 12, 2025
065c3e9
Added second order test.
MaxSagebaum Aug 12, 2025
e95bd0a
Merge remote-tracking branch 'origin/main' into feature/autodiff
MaxSagebaum Aug 13, 2025
93e676f
Remove initialization order workaround.
MaxSagebaum Aug 13, 2025
86f0c7b
Taylor polynomial propagation implementation.
MaxSagebaum Aug 13, 2025
617a089
Basic handling of higher order derivatives and handling of add and mi…
MaxSagebaum Aug 13, 2025
8b5c1e9
Added handling for multiply and division.
MaxSagebaum Aug 13, 2025
05cff29
Higher order handling for special functions.
MaxSagebaum Aug 13, 2025
b930fe7
Remaining tests for higher order derivatives.
MaxSagebaum Aug 13, 2025
364d13f
Declaration lookup and lookup of function return name.
MaxSagebaum Aug 15, 2025
d9ac9e1
Basic changes for adding new things for the differentiation.
MaxSagebaum Aug 15, 2025
92d2407
Moved handling of types and functions to autodiff_declaration_handler.
MaxSagebaum Aug 15, 2025
e83e561
Added handling for differentiation of symbols outside of metafunction…
MaxSagebaum Aug 15, 2025
50d271c
Merge remote-tracking branch 'origin/main' into feature/autodiff
MaxSagebaum Aug 17, 2025
6d2659c
Basic differentation for type and namespace value declarations.
MaxSagebaum Aug 18, 2025
803dfde
Refactor of autodiff_expression_handler.
MaxSagebaum Aug 18, 2025
a286c84
Handling of member access.
MaxSagebaum Aug 18, 2025
bc3597a
Moved assignment handling code to proper traverse function.
MaxSagebaum Aug 18, 2025
247a79d
Added type differentiation for types without member functions.
MaxSagebaum Aug 18, 2025
dd704be
Handling of member function calls.
MaxSagebaum Aug 18, 2025
211b4af
Handling of prefix + and -.
MaxSagebaum Aug 18, 2025
e1e391d
Basic preperations for reverse mode AD.
MaxSagebaum Aug 19, 2025
50bea33
Refactor of diff string to structure.
MaxSagebaum Aug 22, 2025
e48a43f
Reverse handling of function declaration.
MaxSagebaum Aug 23, 2025
beb3629
Reverse differentiation of additive expressions.
MaxSagebaum Aug 25, 2025
c5258a2
Basic handling of multiplication and division.
MaxSagebaum Aug 26, 2025
f2fbe55
Merge remote-tracking branch 'origin/main' into feature/autodiff
MaxSagebaum Aug 28, 2025
ff18571
Fix for to_string of expressions.
MaxSagebaum Aug 28, 2025
cae65f1
Activity analysis for variables and functions.
MaxSagebaum Aug 28, 2025
e0b4a6a
Update for tests and acitivity analysis.
MaxSagebaum Aug 29, 2025
7b3b9c8
Added tests for combined binary expressions.
MaxSagebaum Aug 29, 2025
3898548
Handling of special functions for reverse mode.
MaxSagebaum Aug 29, 2025
7504683
Added handling of function calls for reverse.
MaxSagebaum Aug 29, 2025
9726000
Merge remote-tracking branch 'origin/main' into feature/autodiff
MaxSagebaum Aug 29, 2025
a05accd
Handling of statement parameters for loops in forward mode.
MaxSagebaum Sep 1, 2025
c8fdb06
Reverse handling of for loops.
MaxSagebaum Sep 2, 2025
75b990b
Temp.
MaxSagebaum Sep 5, 2025
2b19b38
Build clean with GCC 10 and Clang 21, and update regression test results
hsutter Sep 8, 2025
8140b2a
Merge remote-tracking branch 'own/feature/autodiff' into feature/auto…
MaxSagebaum Sep 8, 2025
ece0c9b
Bugfix for passive variables in addition or subtraction statements.
MaxSagebaum Sep 8, 2025
4cd35d0
Add an AD unit test
hsutter Sep 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build_h2.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ cd source
cppfront reflect.h2 -verb %1
cd ..\include
cppfront cpp2regex.h2 -verb %1
cppfront cpp2taylor.h2 -verb %1
cd..
38 changes: 38 additions & 0 deletions include/cpp2ad_stack.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef CPP2_CPP2AD_STACK_H
#define CPP2_CPP2AD_STACK_H

#include <vector>

namespace cpp2 {

struct ad_stack {

template<typename T>
static void push(T const& v) {
std::vector<T>& stack = get_stack<T>();

stack.push_back(v);
}

template<typename T>
static T pop() {
std::vector<T>& stack = get_stack<T>();

T v = stack.back();
stack.pop_back();

return v;
}

private:

template<typename T>
static std::vector<T>& get_stack() {
static std::vector<T> stack = {};

return stack;
}
};
} // cpp2 namespace

#endif // CPP2_CPP2AD_STACK_H
20 changes: 10 additions & 10 deletions include/cpp2regex.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,10 @@ template<typename CharT, typename Iter, int max_groups> [[nodiscard]] auto make_
#line 184 "cpp2regex.h2"
// Helpers for creating wrappers of the iterators.
//
template <typename Iter> [[nodiscard]] auto make_forward_iterator(Iter const& pos) -> auto;
template <typename Iter> [[nodiscard]] auto make_forward_iterator(std::reverse_iterator<Iter> const& pos) -> auto;
template <typename Iter> [[nodiscard]] auto make_reverse_iterator(Iter const& pos) -> auto;
template<typename Iter> [[nodiscard]] auto make_reverse_iterator(std::reverse_iterator<Iter> const& pos) -> auto;
template <typename Iter> [[nodiscard]] auto cpp2_make_forward_iterator(Iter const& pos) -> auto;
template<typename Iter> [[nodiscard]] auto cpp2_make_forward_iterator(std::reverse_iterator<Iter> const& pos) -> auto;
template <typename Iter> [[nodiscard]] auto cpp2_make_reverse_iterator(Iter const& pos) -> auto;
template<typename Iter> [[nodiscard]] auto cpp2_make_reverse_iterator(std::reverse_iterator<Iter> const& pos) -> auto;

#line 192 "cpp2regex.h2"
// End function that returns a valid match.
Expand Down Expand Up @@ -927,13 +927,13 @@ template<typename CharT, typename Iter, int max_groups> [[nodiscard]] auto make_
}

#line 186 "cpp2regex.h2"
template <typename Iter> [[nodiscard]] auto make_forward_iterator(Iter const& pos) -> auto { return pos; }
template <typename Iter> [[nodiscard]] auto cpp2_make_forward_iterator(Iter const& pos) -> auto { return pos; }
#line 187 "cpp2regex.h2"
template <typename Iter> [[nodiscard]] auto make_forward_iterator(std::reverse_iterator<Iter> const& pos) -> auto { return CPP2_UFCS(base)(pos); }
template<typename Iter> [[nodiscard]] auto cpp2_make_forward_iterator(std::reverse_iterator<Iter> const& pos) -> auto { return CPP2_UFCS(base)(pos); }
#line 188 "cpp2regex.h2"
template <typename Iter> [[nodiscard]] auto make_reverse_iterator(Iter const& pos) -> auto { return std::make_reverse_iterator(pos); }
template <typename Iter> [[nodiscard]] auto cpp2_make_reverse_iterator(Iter const& pos) -> auto { return std::make_reverse_iterator(pos); }
#line 189 "cpp2regex.h2"
template<typename Iter> [[nodiscard]] auto make_reverse_iterator(std::reverse_iterator<Iter> const& pos) -> auto { return pos; }
template<typename Iter> [[nodiscard]] auto cpp2_make_reverse_iterator(std::reverse_iterator<Iter> const& pos) -> auto { return pos; }

#line 196 "cpp2regex.h2"
[[nodiscard]] auto true_end_func::operator()(auto const& cur, auto& ctx) const& -> decltype(auto) { return ctx.pass(cur); }
Expand Down Expand Up @@ -1153,7 +1153,7 @@ template<typename CharT, bool match_new_line> [[nodiscard]] auto line_start_toke
#line 575 "cpp2regex.h2"
template<typename CharT, bool positive> [[nodiscard]] auto lookahead_token_matcher(auto const& cur, auto& ctx, auto const& func) -> bool
{
auto r {func(make_forward_iterator(cur), make_forward_match_context(ctx), true_end_func())};
auto r {func(cpp2_make_forward_iterator(cur), make_forward_match_context(ctx), true_end_func())};
if (!(positive)) {
r.matched = !(r.matched);
}
Expand All @@ -1164,7 +1164,7 @@ template<typename CharT, bool positive> [[nodiscard]] auto lookahead_token_match
#line 589 "cpp2regex.h2"
template<typename CharT, bool positive> [[nodiscard]] auto lookbehind_token_matcher(auto const& cur, auto& ctx, auto const& func) -> bool
{
auto r {func(make_reverse_iterator(cur), make_reverse_match_context(ctx), true_end_func())};
auto r {func(cpp2_make_reverse_iterator(cur), make_reverse_match_context(ctx), true_end_func())};
if (!(positive)) {
r.matched = !(r.matched);
}
Expand Down
12 changes: 6 additions & 6 deletions include/cpp2regex.h2
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ make_reverse_match_context: <CharT, Iter, max_groups: int> (inout ctx: reverse_m

// Helpers for creating wrappers of the iterators.
//
make_forward_iterator: <Iter> (pos: Iter) -> _ = pos;
make_forward_iterator: <Iter> (pos: std::reverse_iterator<Iter>) -> _ = pos.base();
make_reverse_iterator: <Iter> (pos: Iter) -> _ = std::make_reverse_iterator(pos);
make_reverse_iterator: <Iter> (pos: std::reverse_iterator<Iter>) -> _ = pos;
cpp2_make_forward_iterator: <Iter> (pos: Iter) -> _ = pos;
cpp2_make_forward_iterator: <Iter> (pos: std::reverse_iterator<Iter>) -> _ = pos.base();
cpp2_make_reverse_iterator: <Iter> (pos: Iter) -> _ = std::make_reverse_iterator(pos);
cpp2_make_reverse_iterator: <Iter> (pos: std::reverse_iterator<Iter>) -> _ = pos;


// End function that returns a valid match.
Expand Down Expand Up @@ -574,7 +574,7 @@ line_start_token_matcher: <CharT, match_new_line: bool> (cur, inout ctx) -> bool
//
lookahead_token_matcher: <CharT, positive: bool> (cur, inout ctx, func) -> bool =
{
r := func(make_forward_iterator(cur), make_forward_match_context(ctx), true_end_func());
r := func(cpp2_make_forward_iterator(cur), make_forward_match_context(ctx), true_end_func());
if !positive {
r.matched = !r.matched;
}
Expand All @@ -588,7 +588,7 @@ lookahead_token_matcher: <CharT, positive: bool> (cur, inout ctx, func) -> bool
//
lookbehind_token_matcher: <CharT, positive: bool> (cur, inout ctx, func) -> bool =
{
r := func(make_reverse_iterator(cur), make_reverse_match_context(ctx), true_end_func());
r := func(cpp2_make_reverse_iterator(cur), make_reverse_match_context(ctx), true_end_func());
if !positive {
r.matched = !r.matched;
}
Expand Down
Loading
Loading