Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-xt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
ag-ohlberger
dune-community
dune-xt
Commits
325a1081
Commit
325a1081
authored
4 years ago
by
Dr. Felix Tobias Schindler
Browse files
Options
Downloads
Patches
Plain Diff
[python|common.paramter] add type conversion
parent
59ccb548
No related branches found
No related tags found
1 merge request
!20
Update bindings
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dune/xt/common/parameter.hh
+6
-0
6 additions, 0 deletions
dune/xt/common/parameter.hh
python/dune/xt/common/parameter.hh
+82
-0
82 additions, 0 deletions
python/dune/xt/common/parameter.hh
with
88 additions
and
0 deletions
dune/xt/common/parameter.hh
+
6
−
0
View file @
325a1081
...
...
@@ -59,6 +59,12 @@ public:
return
keys_
;
}
void
clear
()
{
keys_
.
clear
();
dict_
.
clear
();
}
bool
empty
()
const
{
return
dict_
.
size
()
==
0
;
...
...
This diff is collapsed.
Click to expand it.
python/dune/xt/common/parameter.hh
0 → 100644
+
82
−
0
View file @
325a1081
// This file is part of the dune-xt project:
// https://github.com/dune-community/dune-xt
// Copyright 2009-2018 dune-xt developers and contributors. All rights reserved.
// License: Dual licensed as BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
// or GPL-2.0+ (http://opensource.org/licenses/gpl-license)
// with "runtime exception" (http://www.dune-project.org/license.html)
// Authors:
// Felix Schindler (2020)
#ifndef PYTHON_DUNE_XT_COMMON_PARAMETER_HH
#define PYTHON_DUNE_XT_COMMON_PARAMETER_HH
#include
<dune/pybindxi/pybind11.h>
#include
<dune/pybindxi/cast.h>
#include
<dune/xt/common/parameter.hh>
NAMESPACE_BEGIN
(
pybind11
)
NAMESPACE_BEGIN
(
detail
)
template
<
typename
Type
,
typename
Value
>
struct
simple_dict_caster
{
using
Key
=
std
::
string
;
using
key_conv
=
make_caster
<
Key
>
;
using
value_conv
=
make_caster
<
Value
>
;
bool
load
(
handle
src
,
bool
convert
)
{
if
(
!
isinstance
<
dict
>
(
src
))
return
false
;
auto
d
=
reinterpret_borrow
<
dict
>
(
src
);
value
.
clear
();
for
(
auto
it
:
d
)
{
key_conv
kconv
;
value_conv
vconv
;
if
(
!
kconv
.
load
(
it
.
first
.
ptr
(),
convert
)
||
!
vconv
.
load
(
it
.
second
.
ptr
(),
convert
))
return
false
;
value
.
set
(
cast_op
<
Key
&&>
(
std
::
move
(
kconv
)),
cast_op
<
Value
&&>
(
std
::
move
(
vconv
)));
}
return
true
;
}
// ... load(...)
static
handle
cast
(
const
Type
&
src
,
return_value_policy
policy
,
handle
parent
)
{
dict
d
;
return_value_policy
policy_key
=
policy
;
return_value_policy
policy_value
=
policy
;
if
(
!
std
::
is_lvalue_reference
<
Type
>::
value
)
{
policy_key
=
return_value_policy_override
<
Key
>::
policy
(
policy_key
);
policy_value
=
return_value_policy_override
<
Value
>::
policy
(
policy_value
);
}
for
(
auto
&&
key
:
src
.
keys
())
{
auto
key_obj
=
reinterpret_steal
<
object
>
(
key_conv
::
cast
(
key
,
policy_key
,
parent
));
auto
value_obj
=
reinterpret_steal
<
object
>
(
value_conv
::
cast
(
src
.
get
(
key
),
policy_value
,
parent
));
if
(
!
key_obj
||
!
value_obj
)
return
handle
();
d
[
key_obj
]
=
value_obj
;
}
return
d
.
release
();
}
PYBIND11_TYPE_CASTER
(
Type
,
_
(
"Dict["
)
+
key_conv
::
name
+
_
(
", "
)
+
value_conv
::
name
+
_
(
"]"
));
};
// struct simple_dict_caster
template
<
>
struct
type_caster
<
Dune
::
XT
::
Common
::
ParameterType
>
:
public
simple_dict_caster
<
Dune
::
XT
::
Common
::
ParameterType
,
size_t
>
{};
template
<
>
struct
type_caster
<
Dune
::
XT
::
Common
::
Parameter
>
:
public
simple_dict_caster
<
Dune
::
XT
::
Common
::
Parameter
,
std
::
vector
<
double
>>
{};
NAMESPACE_END
(
detail
)
NAMESPACE_END
(
pybind11
)
#endif // PYTHON_DUNE_XT_COMMON_PARAMETER_HH
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