Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-codegen
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Christian Heinigk
dune-codegen
Commits
5d9a7dd6
Commit
5d9a7dd6
authored
9 years ago
by
Dominic Kempf
Browse files
Options
Downloads
Patches
Plain Diff
More adjustments to the decorator magic
parent
720966e9
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
python/dune/perftool/preambles.py
+15
-10
15 additions, 10 deletions
python/dune/perftool/preambles.py
with
15 additions
and
10 deletions
python/dune/perftool/preambles.py
+
15
−
10
View file @
5d9a7dd6
...
...
@@ -26,12 +26,12 @@ class UFL2LoopyDataCache(dict):
def
__init__
(
self
):
self
.
counter
=
0
def
register
(
self
,
cachekey
,
content
,
preamble
):
self
[
cachekey
]
=
(
content
,
self
.
counter
,
preamble
)
def
register
(
self
,
cachekey
,
content
):
self
[
cachekey
]
=
(
content
,
self
.
counter
)
self
.
counter
=
self
.
counter
+
1
def
extract_preambles
(
self
):
return
[(
p
[
1
],
p
[
0
])
for
p
in
self
.
values
()
if
p
[
2
]
]
return
[(
p
[
1
],
p
[
0
])
for
p
in
self
.
values
()
if
p
[
0
].
generate_preambel
]
# have one such cache on the module level. It is easier than handing around an instance of it.
...
...
@@ -72,21 +72,23 @@ class _RegisteredFunction(object):
"""
The data structure for a function that accesses UFL2LoopyDataCache
"""
def
__init__
(
self
,
func
,
cache_key_generator
=
lambda
*
a
:
freeze
(
a
),
generate_preamble
=
True
generate_preamble
=
False
,
return_content
=
False
):
self
.
func
=
func
self
.
cache_key_generator
=
cache_key_generator
self
.
generate_preamble
=
generate_preamble
self
.
return_content
=
return_content
def
__call__
(
self
,
*
args
):
cache_key
=
(
self
.
func
,
self
.
cache_key_generator
(
*
args
))
cache_key
=
(
self
,
self
.
cache_key_generator
(
*
args
))
if
cache_key
in
_cache
:
if
not
self
.
generate_preamble
:
if
self
.
return_content
:
return
_cache
[
cache_key
][
0
]
else
:
content
=
self
.
func
(
*
args
)
_cache
.
register
(
cache_key
,
content
,
self
.
generate_preamble
)
if
not
self
.
generate_preamble
:
_cache
.
register
(
cache_key
,
content
)
if
self
.
return_content
:
return
content
...
...
@@ -112,6 +114,9 @@ def _dune_decorator_factory(**factory_kwargs):
This is usually not the case, when you generate something
like symbol names. Those are inserted into other snippets,
but not on their own right.
return_content : bool
Whether the content of the cache should be returned on subsequent function calls.
If the cache is only used for requirements tracking, this is not needed.
"""
def
_dec
(
*
args
,
**
kwargs
):
# Modify the kwargs according to the factorys kwargs
...
...
@@ -127,7 +132,7 @@ def _dune_decorator_factory(**factory_kwargs):
# A decorator for a dune preambel
dune_preambel
=
_dune_decorator_factory
()
dune_preambel
=
_dune_decorator_factory
(
generate_preamble
=
True
)
# A decorator for a dune symbol name
dune_symbol
=
_dune_decorator_factory
(
generate_preamble
=
Fals
e
)
dune_symbol
=
_dune_decorator_factory
(
return_content
=
Tru
e
)
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