Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-istl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
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
Show more breadcrumbs
Core Modules
dune-istl
Commits
3e23fcab
Commit
3e23fcab
authored
9 years ago
by
Elias Pipping
Browse files
Options
Downloads
Patches
Plain Diff
bvector: Fix NaN behaviour of infinity_norm()
parent
2dd5da45
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!10
flyspray/FS#1147: Fix NaN behaviour of infinity_norm() for istl classes
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dune/istl/bvector.hh
+60
-10
60 additions, 10 deletions
dune/istl/bvector.hh
dune/istl/test/bvectortest.cc
+78
-0
78 additions, 0 deletions
dune/istl/test/bvectortest.cc
with
138 additions
and
10 deletions
dune/istl/bvector.hh
+
60
−
10
View file @
3e23fcab
...
...
@@ -196,19 +196,69 @@ namespace Dune {
}
//! infinity norm (maximum of absolute values of entries)
typename
FieldTraits
<
field_type
>::
real_type
infinity_norm
()
const
{
typename
FieldTraits
<
field_type
>::
real_type
max
=
0
;
for
(
size_type
i
=
0
;
i
<
this
->
n
;
++
i
)
max
=
std
::
max
(
max
,(
*
this
)[
i
].
infinity_norm
());
return
max
;
template
<
typename
ft
=
field_type
,
typename
std
::
enable_if
<!
has_nan
<
ft
>
::
value
,
int
>::
type
=
0
>
typename
FieldTraits
<
ft
>::
real_type
infinity_norm
()
const
{
using
real_type
=
typename
FieldTraits
<
ft
>::
real_type
;
using
std
::
max
;
real_type
norm
=
0
;
for
(
auto
const
&
x
:
*
this
)
{
real_type
const
a
=
x
.
infinity_norm
();
norm
=
max
(
a
,
norm
);
}
return
norm
;
}
//! simplified infinity norm (uses Manhattan norm for complex values)
typename
FieldTraits
<
field_type
>::
real_type
infinity_norm_real
()
const
{
typename
FieldTraits
<
field_type
>::
real_type
max
=
0
;
for
(
size_type
i
=
0
;
i
<
this
->
n
;
++
i
)
max
=
std
::
max
(
max
,(
*
this
)[
i
].
infinity_norm_real
());
return
max
;
template
<
typename
ft
=
field_type
,
typename
std
::
enable_if
<!
has_nan
<
ft
>
::
value
,
int
>::
type
=
0
>
typename
FieldTraits
<
ft
>::
real_type
infinity_norm_real
()
const
{
using
real_type
=
typename
FieldTraits
<
ft
>::
real_type
;
using
std
::
max
;
real_type
norm
=
0
;
for
(
auto
const
&
x
:
*
this
)
{
real_type
const
a
=
x
.
infinity_norm_real
();
norm
=
max
(
a
,
norm
);
}
return
norm
;
}
//! infinity norm (maximum of absolute values of entries)
template
<
typename
ft
=
field_type
,
typename
std
::
enable_if
<
has_nan
<
ft
>
::
value
,
int
>::
type
=
0
>
typename
FieldTraits
<
ft
>::
real_type
infinity_norm
()
const
{
using
real_type
=
typename
FieldTraits
<
ft
>::
real_type
;
using
std
::
max
;
real_type
norm
=
0
;
real_type
isNaN
=
1
;
for
(
auto
const
&
x
:
*
this
)
{
real_type
const
a
=
x
.
infinity_norm
();
norm
=
max
(
a
,
norm
);
isNaN
+=
a
;
}
isNaN
/=
isNaN
;
return
norm
*
isNaN
;
}
//! simplified infinity norm (uses Manhattan norm for complex values)
template
<
typename
ft
=
field_type
,
typename
std
::
enable_if
<
has_nan
<
ft
>
::
value
,
int
>::
type
=
0
>
typename
FieldTraits
<
ft
>::
real_type
infinity_norm_real
()
const
{
using
real_type
=
typename
FieldTraits
<
ft
>::
real_type
;
using
std
::
max
;
real_type
norm
=
0
;
real_type
isNaN
=
1
;
for
(
auto
const
&
x
:
*
this
)
{
real_type
const
a
=
x
.
infinity_norm_real
();
norm
=
max
(
a
,
norm
);
isNaN
+=
a
;
}
isNaN
/=
isNaN
;
return
norm
*
isNaN
;
}
//===== sizes
...
...
This diff is collapsed.
Click to expand it.
dune/istl/test/bvectortest.cc
+
78
−
0
View file @
3e23fcab
...
...
@@ -5,6 +5,7 @@
#include
<dune/common/fvector.hh>
#include
<dune/common/poolallocator.hh>
#include
<dune/common/debugallocator.hh>
#include
<dune/common/classname.hh>
template
<
typename
T
,
int
BS
>
void
assign
(
Dune
::
FieldVector
<
T
,
BS
>&
b
,
const
T
&
i
)
...
...
@@ -120,6 +121,74 @@ void testCapacity()
vec1
.
reserve
(
0
,
false
);
}
template
<
class
V
>
void
checkNormNAN
(
V
const
&
v
,
int
line
)
{
if
(
!
std
::
isnan
(
v
.
one_norm
()))
{
std
::
cerr
<<
"error: norm not NaN: one_norm() on line "
<<
line
<<
" (type: "
<<
Dune
::
className
(
v
[
0
][
0
])
<<
")"
<<
std
::
endl
;
std
::
exit
(
-
1
);
}
if
(
!
std
::
isnan
(
v
.
two_norm
()))
{
std
::
cerr
<<
"error: norm not NaN: two_norm() on line "
<<
line
<<
" (type: "
<<
Dune
::
className
(
v
[
0
][
0
])
<<
")"
<<
std
::
endl
;
std
::
exit
(
-
1
);
}
if
(
!
std
::
isnan
(
v
.
infinity_norm
()))
{
std
::
cerr
<<
"error: norm not NaN: infinity_norm() on line "
<<
line
<<
" (type: "
<<
Dune
::
className
(
v
[
0
][
0
])
<<
")"
<<
std
::
endl
;
std
::
exit
(
-
1
);
}
}
// Make sure that vectors with NaN entries have norm NaN.
// See also bug flyspray/FS#1147
template
<
typename
T
>
void
test_nan
(
T
const
&
mynan
)
{
using
FV
=
Dune
::
FieldVector
<
T
,
2
>
;
using
V
=
Dune
::
BlockVector
<
FV
>
;
T
n
(
0
);
{
V
v
=
{
{
mynan
,
n
},
{
n
,
n
}
};
checkNormNAN
(
v
,
__LINE__
);
}
{
V
v
=
{
{
n
,
mynan
},
{
n
,
n
}
};
checkNormNAN
(
v
,
__LINE__
);
}
{
V
v
=
{
{
n
,
n
},
{
mynan
,
n
}
};
checkNormNAN
(
v
,
__LINE__
);
}
{
V
v
=
{
{
n
,
n
},
{
n
,
mynan
}
};
checkNormNAN
(
v
,
__LINE__
);
}
{
V
v
=
{
{
mynan
,
mynan
},
{
mynan
,
mynan
}
};
checkNormNAN
(
v
,
__LINE__
);
}
}
int
main
()
{
typedef
std
::
complex
<
double
>
value_type
;
...
...
@@ -141,6 +210,15 @@ int main()
assert
(
fromInitializerList
[
1
]
==
value_type
(
1
));
assert
(
fromInitializerList
[
2
]
==
value_type
(
2
));
{
double
nan
=
std
::
nan
(
""
);
test_nan
(
nan
);
}
{
std
::
complex
<
double
>
nan
(
std
::
nan
(
""
),
17
);
test_nan
(
nan
);
}
int
ret
=
0
;
ret
+=
testVector
<
1
>
();
...
...
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