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
89c9cb8e
Commit
89c9cb8e
authored
7 years ago
by
Dr. Felix Tobias Schindler
Browse files
Options
Downloads
Patches
Plain Diff
[parameter] refactor comparison and parsing
parent
d4ce2dda
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dune/xt/common/parameter.cc
+69
-32
69 additions, 32 deletions
dune/xt/common/parameter.cc
dune/xt/common/parameter.hh
+19
-8
19 additions, 8 deletions
dune/xt/common/parameter.hh
with
88 additions
and
40 deletions
dune/xt/common/parameter.cc
+
69
−
32
View file @
89c9cb8e
...
...
@@ -91,24 +91,6 @@ const ValueType& SimpleDict<ValueType>::get(const std::string& key) const
return
result
->
second
;
}
template
<
class
ValueType
>
bool
SimpleDict
<
ValueType
>::
operator
<
(
const
SimpleDict
<
ValueType
>&
other
)
const
{
return
dict_
<
other
.
dict_
;
}
template
<
class
ValueType
>
bool
SimpleDict
<
ValueType
>::
operator
==
(
const
SimpleDict
<
ValueType
>&
other
)
const
{
return
dict_
==
other
.
dict_
;
}
template
<
class
ValueType
>
bool
SimpleDict
<
ValueType
>::
operator
!=
(
const
SimpleDict
<
ValueType
>&
other
)
const
{
return
dict_
!=
other
.
dict_
;
}
template
<
class
ValueType
>
size_t
SimpleDict
<
ValueType
>::
size
()
const
{
...
...
@@ -186,6 +168,37 @@ ParameterType::ParameterType(const std::vector<std::pair<std::string, size_t>>&
{
}
bool
ParameterType
::
operator
==
(
const
ParameterType
&
other
)
const
{
if
(
this
->
size
()
==
1
&&
other
.
size
()
==
1
)
{
const
auto
&
this_single_element
=
*
this
->
dict_
.
begin
();
const
auto
&
other_single_element
=
*
other
.
dict_
.
begin
();
if
(
this_single_element
.
first
==
other_single_element
.
first
||
this_single_element
.
first
==
"_unspecified"
||
other_single_element
.
first
==
"_unspecified"
)
{
return
this_single_element
.
second
==
other_single_element
.
second
;
}
else
{
return
false
;
}
}
else
{
return
this
->
dict_
==
other
.
dict_
;
}
}
bool
ParameterType
::
operator
!=
(
const
ParameterType
&
other
)
const
{
return
!
(
*
this
==
other
);
}
bool
ParameterType
::
operator
<
(
const
ParameterType
&
other
)
const
{
return
this
->
dict_
<
other
.
dict_
;
}
bool
ParameterType
::
operator
<=
(
const
ParameterType
&
other
)
const
{
return
*
this
<
other
||
*
this
==
other
;
}
std
::
string
ParameterType
::
report
()
const
{
return
"ParameterType("
+
BaseType
::
report
(
"ParameterType("
)
+
")"
;
...
...
@@ -203,7 +216,12 @@ std::ostream& operator<<(std::ostream& out, const ParameterType& param_type)
// ===== Parameter =====
// =====================
Parameter
::
Parameter
(
const
double
&
value
)
:
BaseType
(
"None"
,
{
value
})
:
BaseType
(
"_unspecified"
,
{
value
})
{
}
Parameter
::
Parameter
(
const
std
::
vector
<
double
>&
value
)
:
BaseType
(
"_unspecified"
,
value
)
{
}
...
...
@@ -222,6 +240,11 @@ Parameter::Parameter(const std::vector<std::pair<std::string, ValueType>>& key_v
{
}
bool
Parameter
::
operator
<
(
const
Parameter
&
other
)
const
{
return
this
->
dict_
<
other
.
dict_
;
}
ParameterType
Parameter
::
type
()
const
{
ParameterType
ret
;
...
...
@@ -254,25 +277,39 @@ bool ParametricInterface::is_parametric() const
const
ParameterType
&
ParametricInterface
::
parameter_type
()
const
{
return
none
_parameter_type_
;
return
_unspecified
_parameter_type_
;
}
Parameter
ParametricInterface
::
parse_parameter
(
const
Parameter
&
mu
)
const
{
const
auto
&
target_type
=
parameter_type
();
if
(
mu
.
type
()
==
target_type
)
return
mu
;
if
(
target_type
.
size
()
==
1
&&
mu
.
size
()
==
1
)
{
const
auto
&
target_key
=
target_type
.
keys
().
at
(
0
);
const
auto
&
mus_value
=
mu
.
get
(
mu
.
keys
().
at
(
0
));
if
(
mus_value
.
size
()
!=
target_type
.
get
(
target_key
))
const
auto
&
this_type
=
this
->
parameter_type
();
const
auto
&
mus_type
=
mu
.
type
();
if
(
this_type
.
size
()
==
1
&&
mus_type
.
size
()
==
1
)
{
const
auto
this_single_key
=
this_type
.
keys
().
at
(
0
);
const
auto
mus_single_key
=
mus_type
.
keys
().
at
(
0
);
if
(
this_single_key
==
mus_single_key
)
return
mu
;
return
Parameter
(
target_key
,
mus_value
);
if
(
this_single_key
==
"_unspecified"
||
mus_single_key
==
"_unspecified"
)
{
// these could be equivalent ...
if
(
mus_type
.
get
(
this_single_key
)
==
this_type
.
get
(
this_single_key
))
{
// .. and they are
return
Parameter
(
this_single_key
,
mu
.
get
(
mus_single_key
));
}
}
// they are both of length 1, but the keys don't match and neither is '_unspecified'
DUNE_THROW
(
Exceptions
::
parameter_error
,
"this->parameter_type() = "
<<
this_type
<<
"
\n
"
<<
"mu.type() = "
<<
mus_type
);
}
return
mu
;
// one of them is not lenght 1, so '_unspecified' does not play a role here
if
(
this_type
<=
mus_type
)
return
mu
;
DUNE_THROW
(
Exceptions
::
parameter_error
,
"this->parameter_type() = "
<<
this_type
<<
"
\n
"
<<
"mu.type() = "
<<
mus_type
);
return
Parameter
();
}
// ... parse_parameter(...)
// TODO: Why doesn't parse_parameter check this? Is that additional block
...
...
This diff is collapsed.
Click to expand it.
dune/xt/common/parameter.hh
+
19
−
8
View file @
89c9cb8e
...
...
@@ -44,12 +44,6 @@ public:
const
ValueType
&
get
(
const
std
::
string
&
key
)
const
;
bool
operator
<
(
const
SimpleDict
<
ValueType
>&
other
)
const
;
bool
operator
==
(
const
SimpleDict
<
ValueType
>&
other
)
const
;
bool
operator
!=
(
const
SimpleDict
<
ValueType
>&
other
)
const
;
size_t
size
()
const
;
protected:
...
...
@@ -86,6 +80,19 @@ public:
ParameterType
(
const
std
::
vector
<
std
::
pair
<
std
::
string
,
size_t
>>&
key_size_pairs
);
/**
* \note In the special case that this and other both have only a single key, and either of the keys is
* '_unspecified', then they compare equal if the sizes corresponding to these keys compare equal.
* \sa Take a look at test/parameter.cc for examples.
*/
bool
operator
==
(
const
ParameterType
&
other
)
const
;
bool
operator
!=
(
const
ParameterType
&
other
)
const
;
bool
operator
<
(
const
ParameterType
&
other
)
const
;
bool
operator
<=
(
const
ParameterType
&
other
)
const
;
std
::
string
report
()
const
;
};
// class ParameterType
...
...
@@ -95,7 +102,7 @@ std::ostream& operator<<(std::ostream& out, const ParameterType& param_type);
class
Parameter
:
public
internal
::
SimpleDict
<
std
::
vector
<
double
>>
{
typedef
SimpleDict
<
std
::
vector
<
double
>>
BaseType
;
typedef
internal
::
SimpleDict
<
std
::
vector
<
double
>>
BaseType
;
typedef
std
::
vector
<
double
>
ValueType
;
public:
...
...
@@ -103,6 +110,8 @@ public:
Parameter
(
const
double
&
value
);
Parameter
(
const
std
::
vector
<
double
>&
value
);
Parameter
(
const
std
::
string
&
key
,
const
double
&
value
);
Parameter
(
const
std
::
string
&
key
,
const
ValueType
&
value
);
...
...
@@ -112,6 +121,8 @@ public:
{
}
bool
operator
<
(
const
Parameter
&
other
)
const
;
ParameterType
type
()
const
;
std
::
string
report
()
const
;
...
...
@@ -135,7 +146,7 @@ public:
Parameter
parse_and_check
(
const
Parameter
&
mu
)
const
;
private:
ParameterType
none
_parameter_type_
;
const
ParameterType
_unspecified
_parameter_type_
;
};
// class ParametricInterface
...
...
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