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
d9f05fa0
Commit
d9f05fa0
authored
6 years ago
by
Tim Keil
Browse files
Options
Downloads
Patches
Plain Diff
[FloatCmp] Fix bug in FloatCmp::ge and ::le
parent
8d5fe824
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
dune/xt/common/float_cmp_internal.hh
+100
-7
100 additions, 7 deletions
dune/xt/common/float_cmp_internal.hh
with
100 additions
and
7 deletions
dune/xt/common/float_cmp_internal.hh
+
100
−
7
View file @
d9f05fa0
...
...
@@ -198,6 +198,100 @@ cmp_gt(const XType& xx, const YType& yy)
return
true
;
}
// ... cmp_gt(...)
template
<
Dune
::
FloatCmp
::
CmpStyle
style
,
class
T
>
typename
std
::
enable_if
<
is_arithmetic
<
T
>::
value
,
bool
>::
type
cmp_ge
(
const
T
&
xx
,
const
T
&
yy
,
const
T
&
eps
)
{
return
std
::
greater
<
T
>
()(
xx
,
yy
)
||
Dune
::
FloatCmp
::
eq
<
T
,
style
>
(
xx
,
yy
,
eps
);
}
template
<
Dune
::
FloatCmp
::
CmpStyle
style
,
class
T
>
bool
cmp_ge
(
const
std
::
complex
<
T
>&
xx
,
const
std
::
complex
<
T
>&
yy
,
const
T
&
eps
)
{
return
cmp_ge
<
style
>
(
real
(
xx
),
real
(
yy
),
eps
)
&&
cmp_ge
<
style
>
(
imag
(
xx
),
imag
(
yy
),
eps
);
}
template
<
Dune
::
FloatCmp
::
CmpStyle
style
,
class
XType
,
class
YType
,
class
EpsType
>
typename
std
::
enable_if
<
is_vector
<
XType
>::
value
&&
is_vector
<
YType
>::
value
&&
std
::
is_same
<
typename
VectorAbstraction
<
XType
>::
S
,
EpsType
>::
value
&&
std
::
is_same
<
typename
VectorAbstraction
<
YType
>::
S
,
EpsType
>::
value
,
bool
>::
type
cmp_ge
(
const
XType
&
xx
,
const
YType
&
yy
,
const
EpsType
&
eps
)
{
const
auto
sz
=
xx
.
size
();
if
(
yy
.
size
()
!=
sz
)
return
false
;
for
(
size_t
ii
=
0
;
ii
<
sz
;
++
ii
)
if
(
!
(
cmp_ge
<
style
>
(
xx
[
ii
],
yy
[
ii
],
eps
)))
return
false
;
return
true
;
}
// ... cmp_ge(...)
template
<
Dune
::
FloatCmp
::
CmpStyle
style
,
class
XType
,
class
YType
,
class
EpsType
>
typename
std
::
enable_if
<
is_matrix
<
XType
>::
value
&&
is_matrix
<
YType
>::
value
&&
std
::
is_same
<
typename
MatrixAbstraction
<
XType
>::
S
,
EpsType
>::
value
&&
std
::
is_same
<
typename
MatrixAbstraction
<
YType
>::
S
,
EpsType
>::
value
,
bool
>::
type
cmp_ge
(
const
XType
&
xx
,
const
YType
&
yy
,
const
EpsType
&
eps
)
{
const
auto
rows
=
MatrixAbstraction
<
XType
>::
rows
(
xx
);
const
auto
cols
=
MatrixAbstraction
<
XType
>::
cols
(
xx
);
if
(
MatrixAbstraction
<
YType
>::
rows
(
yy
)
!=
rows
||
MatrixAbstraction
<
YType
>::
cols
(
yy
)
!=
cols
)
return
false
;
for
(
size_t
ii
=
0
;
ii
<
rows
;
++
ii
)
for
(
size_t
jj
=
0
;
jj
<
cols
;
++
jj
)
if
(
!
cmp_ge
<
style
>
(
MatrixAbstraction
<
XType
>::
get_entry
(
xx
,
ii
,
jj
),
MatrixAbstraction
<
YType
>::
get_entry
(
yy
,
ii
,
jj
),
eps
))
return
false
;
return
true
;
}
// ... cmp_ge(...)
template
<
Dune
::
FloatCmp
::
CmpStyle
style
,
class
T
>
typename
std
::
enable_if
<
is_arithmetic
<
T
>::
value
,
bool
>::
type
cmp_le
(
const
T
&
xx
,
const
T
&
yy
,
const
T
&
eps
)
{
return
std
::
less
<
T
>
()(
xx
,
yy
)
||
Dune
::
FloatCmp
::
eq
<
T
,
style
>
(
xx
,
yy
,
eps
);
}
template
<
Dune
::
FloatCmp
::
CmpStyle
style
,
class
T
>
bool
cmp_le
(
const
std
::
complex
<
T
>&
xx
,
const
std
::
complex
<
T
>&
yy
,
const
T
&
eps
)
{
return
cmp_le
<
style
>
(
real
(
xx
),
real
(
yy
),
eps
)
&&
cmp_le
<
style
>
(
imag
(
xx
),
imag
(
yy
),
eps
);
}
template
<
Dune
::
FloatCmp
::
CmpStyle
style
,
class
XType
,
class
YType
,
class
EpsType
>
typename
std
::
enable_if
<
is_vector
<
XType
>::
value
&&
is_vector
<
YType
>::
value
&&
std
::
is_same
<
typename
VectorAbstraction
<
XType
>::
S
,
EpsType
>::
value
&&
std
::
is_same
<
typename
VectorAbstraction
<
YType
>::
S
,
EpsType
>::
value
,
bool
>::
type
cmp_le
(
const
XType
&
xx
,
const
YType
&
yy
,
const
EpsType
&
eps
)
{
const
auto
sz
=
xx
.
size
();
if
(
yy
.
size
()
!=
sz
)
return
false
;
for
(
size_t
ii
=
0
;
ii
<
sz
;
++
ii
)
if
(
!
(
cmp_le
<
style
>
(
xx
[
ii
],
yy
[
ii
],
eps
)))
return
false
;
return
true
;
}
// ... cmp_le(...)
template
<
Dune
::
FloatCmp
::
CmpStyle
style
,
class
XType
,
class
YType
,
class
EpsType
>
typename
std
::
enable_if
<
is_matrix
<
XType
>::
value
&&
is_matrix
<
YType
>::
value
&&
std
::
is_same
<
typename
MatrixAbstraction
<
XType
>::
S
,
EpsType
>::
value
&&
std
::
is_same
<
typename
MatrixAbstraction
<
YType
>::
S
,
EpsType
>::
value
,
bool
>::
type
cmp_le
(
const
XType
&
xx
,
const
YType
&
yy
,
const
EpsType
&
eps
)
{
const
auto
rows
=
MatrixAbstraction
<
XType
>::
rows
(
xx
);
const
auto
cols
=
MatrixAbstraction
<
XType
>::
cols
(
xx
);
if
(
MatrixAbstraction
<
YType
>::
rows
(
yy
)
!=
rows
||
MatrixAbstraction
<
YType
>::
cols
(
yy
)
!=
cols
)
return
false
;
for
(
size_t
ii
=
0
;
ii
<
rows
;
++
ii
)
for
(
size_t
jj
=
0
;
jj
<
cols
;
++
jj
)
if
(
!
cmp_le
<
style
>
(
MatrixAbstraction
<
XType
>::
get_entry
(
xx
,
ii
,
jj
),
MatrixAbstraction
<
YType
>::
get_entry
(
yy
,
ii
,
jj
),
eps
))
return
false
;
return
true
;
}
// ... cmp_le(...)
template
<
class
T
>
typename
std
::
enable_if
<
is_arithmetic
<
T
>::
value
,
bool
>::
type
cmp_lt
(
const
T
&
xx
,
const
T
&
yy
)
{
...
...
@@ -245,7 +339,6 @@ cmp_lt(const XType& xx, const YType& yy)
return
true
;
}
// ... cmp_gt(...)
template
<
class
FirstType
,
class
SecondType
,
class
ToleranceType
,
Style
style
>
struct
Call
{
...
...
@@ -271,12 +364,12 @@ struct Call
static
bool
ge
(
const
FirstType
&
first
,
const
SecondType
&
second
,
const
ToleranceType
&
rtol
,
const
ToleranceType
&
/**/
)
{
return
dune_float_
cmp_e
q
<
internal
::
ConvertStyle
<
style
>::
value
>
(
first
,
second
,
rtol
)
||
cmp_gt
(
first
,
second
)
;
return
cmp_
g
e
<
internal
::
ConvertStyle
<
style
>::
value
>
(
first
,
second
,
rtol
);
}
static
bool
le
(
const
FirstType
&
first
,
const
SecondType
&
second
,
const
ToleranceType
&
rtol
,
const
ToleranceType
&
/**/
)
{
return
dune_float_
cmp_e
q
<
internal
::
ConvertStyle
<
style
>::
value
>
(
first
,
second
,
rtol
)
||
cmp_lt
(
first
,
second
)
;
return
cmp_
l
e
<
internal
::
ConvertStyle
<
style
>::
value
>
(
first
,
second
,
rtol
);
}
};
...
...
@@ -303,14 +396,14 @@ struct Call<FirstType, SecondType, ToleranceType, Style::numpy>
return
!
float_cmp_eq
(
first
,
second
,
rtol
,
atol
)
&&
cmp_lt
(
first
,
second
);
}
static
bool
ge
(
const
FirstType
&
first
,
const
SecondType
&
second
,
const
ToleranceType
&
rtol
,
const
ToleranceType
&
atol
)
static
bool
ge
(
const
FirstType
&
first
,
const
SecondType
&
second
,
const
ToleranceType
&
rtol
,
const
ToleranceType
&
/**/
)
{
return
float_
cmp_e
q
(
first
,
second
,
rtol
,
atol
)
||
cmp_gt
(
first
,
second
);
return
cmp_
g
e
(
first
,
second
,
rtol
);
}
static
bool
le
(
const
FirstType
&
first
,
const
SecondType
&
second
,
const
ToleranceType
&
rtol
,
const
ToleranceType
&
atol
)
static
bool
le
(
const
FirstType
&
first
,
const
SecondType
&
second
,
const
ToleranceType
&
rtol
,
const
ToleranceType
&
/**/
)
{
return
float_
cmp_e
q
(
first
,
second
,
rtol
,
atol
)
||
cmp_lt
(
first
,
second
);
return
cmp_
l
e
(
first
,
second
,
rtol
);
}
};
...
...
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