Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
d9a93fdc
Commit
d9a93fdc
authored
Aug 08, 2013
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added is_finite() for matrix objects.
parent
fe410de2
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
20 deletions
+66
-20
algs.h
dlib/algs.h
+22
-20
matrix_utilities.h
dlib/matrix/matrix_utilities.h
+18
-0
matrix_utilities_abstract.h
dlib/matrix/matrix_utilities_abstract.h
+11
-0
matrix.cpp
dlib/test/matrix.cpp
+15
-0
No files found.
dlib/algs.h
View file @
d9a93fdc
...
...
@@ -451,26 +451,6 @@ namespace dlib
template
<>
struct
is_float_type
<
double
>
{
const
static
bool
value
=
true
;
};
template
<>
struct
is_float_type
<
long
double
>
{
const
static
bool
value
=
true
;
};
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
bool
is_finite
(
const
T
&
value
)
/*!
ensures
- returns true if value is a finite value (e.g. not infinity or NaN) and false
otherwise.
!*/
{
if
(
is_float_type
<
T
>::
value
)
return
-
std
::
numeric_limits
<
T
>::
infinity
()
<
value
&&
value
<
std
::
numeric_limits
<
T
>::
infinity
();
else
return
true
;
}
// ----------------------------------------------------------------------------------------
/*!A is_convertible
...
...
@@ -650,6 +630,28 @@ namespace dlib
template
<>
struct
is_built_in_scalar_type
<
wchar_t
>
{
const
static
bool
value
=
true
;
};
#endif
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
typename
enable_if
<
is_built_in_scalar_type
<
T
>
,
bool
>::
type
is_finite
(
const
T
&
value
)
/*!
requires
- value must be some kind of scalar type such as int or double
ensures
- returns true if value is a finite value (e.g. not infinity or NaN) and false
otherwise.
!*/
{
if
(
is_float_type
<
T
>::
value
)
return
-
std
::
numeric_limits
<
T
>::
infinity
()
<
value
&&
value
<
std
::
numeric_limits
<
T
>::
infinity
();
else
return
true
;
}
// ----------------------------------------------------------------------------------------
/*!A promote
...
...
dlib/matrix/matrix_utilities.h
View file @
d9a93fdc
...
...
@@ -63,6 +63,24 @@ namespace dlib
const
matrix_exp
<
EXP
>&
m
)
{
return
is_row_vector
(
m
)
||
is_col_vector
(
m
);
}
// ----------------------------------------------------------------------------------------
template
<
typename
EXP
>
inline
bool
is_finite
(
const
matrix_exp
<
EXP
>&
m
)
{
for
(
long
r
=
0
;
r
<
m
.
nr
();
++
r
)
{
for
(
long
c
=
0
;
c
<
m
.
nc
();
++
c
)
{
if
(
!
is_finite
(
m
(
r
,
c
)))
return
false
;
}
}
return
true
;
}
// ----------------------------------------------------------------------------------------
namespace
impl
...
...
dlib/matrix/matrix_utilities_abstract.h
View file @
d9a93fdc
...
...
@@ -1041,6 +1041,17 @@ namespace dlib
- returns false
!*/
// ----------------------------------------------------------------------------------------
bool
is_finite
(
const
matrix_exp
&
m
);
/*!
ensures
- returns true if all the values in m are finite values and also not any kind
of NaN value.
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// Thresholding relational operators
...
...
dlib/test/matrix.cpp
View file @
d9a93fdc
...
...
@@ -1208,6 +1208,7 @@ namespace
m1
=
1
;
m2
=
1
;
m1
=
m1
*
subm
(
m2
,
0
,
0
,
3
,
3
);
DLIB_TEST
(
is_finite
(
m1
));
}
{
matrix
<
double
,
3
,
1
>
m1
;
...
...
@@ -1253,7 +1254,21 @@ namespace
DLIB_TEST
(
m
(
0
)
==
6
);
DLIB_TEST
(
m
(
1
)
==
6
);
DLIB_TEST
(
is_finite
(
m
));
}
{
matrix
<
double
>
m
(
3
,
3
);
m
=
3
;
m
(
1
,
1
)
=
std
::
numeric_limits
<
double
>::
infinity
();
DLIB_TEST
(
is_finite
(
m
)
==
false
);
m
(
1
,
1
)
=
-
std
::
numeric_limits
<
double
>::
infinity
();
DLIB_TEST
(
is_finite
(
m
)
==
false
);
m
(
1
,
1
)
=
2
;
DLIB_TEST
(
is_finite
(
m
));
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment