Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-fufem
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ansgar Burchardt
dune-fufem
Commits
45e90f13
Commit
45e90f13
authored
8 years ago
by
Carsten Gräser
Browse files
Options
Downloads
Patches
Plain Diff
[python] Add functions for construction of callable functions
parent
61295d8f
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
dune/fufem/python/common.hh
+40
-0
40 additions, 0 deletions
dune/fufem/python/common.hh
with
40 additions
and
0 deletions
dune/fufem/python/common.hh
+
40
−
0
View file @
45e90f13
...
...
@@ -14,9 +14,14 @@
#include
<type_traits>
#include
<dune/common/exceptions.hh>
#include
<dune/common/std/apply.hh>
#include
<dune/functions/common/signature.hh>
#include
<dune/functions/common/differentiablefunctionfromcallables.hh>
#include
<dune/fufem/python/reference.hh>
#include
<dune/fufem/python/module.hh>
#include
<dune/fufem/python/callable.hh>
namespace
Python
...
...
@@ -522,6 +527,41 @@ Reference keys(const Reference& dict)
return
PyDict_Keys
(
dict
);
}
/**
* \brief Create a callable function for given signature
*
* \tparam Signature Signature of function to create
*/
template
<
class
Signature
,
template
<
class
>
class
DerivativeTraits
=
Dune
::
Functions
::
DefaultDerivativeTraits
>
auto
makeFunction
(
const
Reference
&
f
)
{
using
Range
=
typename
Dune
::
Functions
::
SignatureTraits
<
Signature
>::
Range
;
using
Domain
=
typename
Dune
::
Functions
::
SignatureTraits
<
Signature
>::
Domain
;
return
[
callable
=
Python
::
Callable
(
f
)](
const
Domain
&
x
)
{
return
callable
(
x
).
template
toC
<
Range
>();
};
}
/**
* \brief Create a callable differentiable function for given signature
*
* \tparam Signature Signature of function to create
* \tparam DerivativeTraits Traits template to use for construction of derivative signatures
* \tparam R Must derive from Python::Reference
* \param f Callable python objects for the function and its derivatives
*/
template
<
class
Signature
,
template
<
class
>
class
DerivativeTraits
=
Dune
::
Functions
::
DefaultDerivativeTraits
,
class
...
R
>
auto
makeDifferentiableFunction
(
const
R
&
...
f
)
{
auto
signatureTag
=
Dune
::
Functions
::
SignatureTag
<
Signature
,
DerivativeTraits
>
();
auto
derivativeSignatureTags
=
Dune
::
Functions
::
derivativeSignatureTags
<
sizeof
...(
f
)
-
1
>
(
signatureTag
);
return
Dune
::
Std
::
apply
([
&
](
auto
...
tag
)
{
return
Dune
::
Functions
::
makeDifferentiableFunctionFromCallables
(
signatureTag
,
makeFunction
<
typename
decltype
(
tag
)
::
Signature
>
(
f
)...);
},
derivativeSignatureTags
);
}
/**
* \brief If a python error occured throw an exception and clear python error indicator
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment