Library-wide automatic differentiation#849
Open
hverhelst wants to merge 22 commits into
Open
Conversation
Add template to gsSurfMesh (move implementations from cpp to hpp files) Remove obsolete files NOTE: ternary operators have been replaced in some cases due to differences in type left and right of `:`. This also affects Eigen source code. I hope we can find a way to solve this differently
IMPROVE: Use autodiff for gsFunctionExpr
…stream components - Fixed gsSurfMesh.h: Remove non-template operator<< from Vertex struct (free function exists) - Fixed gsSurfMesh.hpp: Add 'typename' keyword for dependent iterator types in template methods - Fixed gsSurfMesh.hpp: Add '.template' keyword for dependent template member access - Added explicit template instantiation for gsSurfMesh<real_t> in gsSurfMesh_.cpp - Added IO function instantiations (read_mesh, write_mesh, read/write_stl/off/obj/poly) - Updated gsMultiPatch.hpp: toMesh() now returns gsSurfMesh<T>, preserving scalar type - Fixed gsWriteParaview templating: Made function template on Scalar parameter - Updated gsWriteParaview.hpp: Added '.template' for dependent template member access - Added gsWriteParaview explicit instantiation for gsSurfMesh<real_t> - Fixed IO_stl.hpp, IO_off.hpp: Added '.template' keywords for dependent template access - Fixed gsSubdivScheme.cpp: Use Halfedge typedef instead of gsSurfMesh::Halfedge - Updated example files to use auto or explicit gsSurfMesh<> template args All examples compile and run successfully. IO operations work correctly with templated mesh.
- Added gsMath.h include for autodiff-aware math::abs function - Replaced std::abs with math::abs in CmpVec comparator - math::abs has overloads for autodiff::Dual and other scalar types - Fixes compiler errors when gsSurfMesh is used with autodiff types - Mesh examples (subdivSurfaces_example, patches_from_mesh) now build and run successfully with autodiff
Split gsSubDivScheme in `.h` and `.hpp` files as it is templated now. Added gsSubDivScheme_.cpp for template instantiation
Add adjoint examples for poisson
filiatra
reviewed
Apr 3, 2026
| { | ||
| const T epsilon( epsilon_type<ad_type_tag>::value() ); | ||
| const T eps_norm = (max(T(1),max(abs(v0),abs(v1))) * epsilon); | ||
| const T eps_norm = (std::max(T(1),std::max(abs(v0),abs(v1))) * epsilon); |
Member
There was a problem hiding this comment.
Please remplase as math::max(..)
Same for math::abs(..) etc
filiatra
requested changes
Apr 3, 2026
| static inline void acc_global(const T contrib, T & res) | ||
| { | ||
| # pragma omp atomic update | ||
| # pragma omp critical |
Member
There was a problem hiding this comment.
please use an #if/#else to check if the type is a build-in type.
In that case atomic is available, otherwise use critical
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enable automatic differentiation throughout the whole library, using
dual_t(forward) andvar_t(reverse).The advantage over the existing
external/gsAutoDiffis that the new autodiff types inoptional/gsAutoDiffare using the licensed autodiff library, which also provides reverse mode.The module
optional/gsAutoDiffcan probably not be externalized in a separate GitHub repo, since it implies quite some changes in the maingismorepository.NEW:
Add the types of the autodiff library, into gsAutoDiff module
Add examples and unittests
IMPROVED:
FIXED:
API:
The
gsSurfMeshis now templated overTFor each new/improved/fixed/api change use a new line with the
respective word prefix in capital.
Please consider the following checklist before issuing a pull
request:
you'd like us to include them?