Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
6e4c77cd
Commit
6e4c77cd
authored
Feb 28, 2012
by
Davis King
Browse files
Updated the min and max functions so that they work with complex
numbers in the same manner as MATLAB.
parent
7f5dbb71
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
8 deletions
+20
-8
dlib/matrix/matrix_utilities.h
dlib/matrix/matrix_utilities.h
+14
-6
dlib/matrix/matrix_utilities_abstract.h
dlib/matrix/matrix_utilities_abstract.h
+6
-2
No files found.
dlib/matrix/matrix_utilities.h
View file @
6e4c77cd
...
@@ -64,6 +64,14 @@ namespace dlib
...
@@ -64,6 +64,14 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
namespace
impl
{
template
<
typename
T
>
const
T
&
magnitude
(
const
T
&
item
)
{
return
item
;
}
template
<
typename
T
>
T
magnitude
(
const
std
::
complex
<
T
>&
item
)
{
return
std
::
norm
(
item
);
}
}
template
<
template
<
typename
EXP
typename
EXP
>
>
...
@@ -87,9 +95,9 @@ namespace dlib
...
@@ -87,9 +95,9 @@ namespace dlib
for
(
long
c
=
0
;
c
<
m
.
nc
();
++
c
)
for
(
long
c
=
0
;
c
<
m
.
nc
();
++
c
)
{
{
type
temp
=
m
(
r
,
c
);
type
temp
=
m
(
r
,
c
);
if
(
temp
>
max_val
)
if
(
dlib
::
impl
::
magnitude
(
temp
)
>
dlib
::
impl
::
magnitude
(
max_val
)
)
max_val
=
temp
;
max_val
=
temp
;
if
(
temp
<
min_val
)
if
(
dlib
::
impl
::
magnitude
(
temp
)
<
dlib
::
impl
::
magnitude
(
min_val
)
)
min_val
=
temp
;
min_val
=
temp
;
}
}
}
}
...
@@ -118,7 +126,7 @@ namespace dlib
...
@@ -118,7 +126,7 @@ namespace dlib
for
(
long
i
=
1
;
i
<
m
.
size
();
++
i
)
for
(
long
i
=
1
;
i
<
m
.
size
();
++
i
)
{
{
type
temp
=
m
(
i
);
type
temp
=
m
(
i
);
if
(
temp
>
val
)
if
(
dlib
::
impl
::
magnitude
(
temp
)
>
dlib
::
impl
::
magnitude
(
val
)
)
{
{
val
=
temp
;
val
=
temp
;
best_idx
=
i
;
best_idx
=
i
;
...
@@ -150,7 +158,7 @@ namespace dlib
...
@@ -150,7 +158,7 @@ namespace dlib
for
(
long
i
=
1
;
i
<
m
.
size
();
++
i
)
for
(
long
i
=
1
;
i
<
m
.
size
();
++
i
)
{
{
type
temp
=
m
(
i
);
type
temp
=
m
(
i
);
if
(
temp
<
val
)
if
(
dlib
::
impl
::
magnitude
(
temp
)
<
dlib
::
impl
::
magnitude
(
val
)
)
{
{
val
=
temp
;
val
=
temp
;
best_idx
=
i
;
best_idx
=
i
;
...
@@ -181,7 +189,7 @@ namespace dlib
...
@@ -181,7 +189,7 @@ namespace dlib
for
(
long
c
=
0
;
c
<
m
.
nc
();
++
c
)
for
(
long
c
=
0
;
c
<
m
.
nc
();
++
c
)
{
{
type
temp
=
m
(
r
,
c
);
type
temp
=
m
(
r
,
c
);
if
(
temp
>
val
)
if
(
dlib
::
impl
::
magnitude
(
temp
)
>
dlib
::
impl
::
magnitude
(
val
)
)
val
=
temp
;
val
=
temp
;
}
}
}
}
...
@@ -210,7 +218,7 @@ namespace dlib
...
@@ -210,7 +218,7 @@ namespace dlib
for
(
long
c
=
0
;
c
<
m
.
nc
();
++
c
)
for
(
long
c
=
0
;
c
<
m
.
nc
();
++
c
)
{
{
type
temp
=
m
(
r
,
c
);
type
temp
=
m
(
r
,
c
);
if
(
temp
<
val
)
if
(
dlib
::
impl
::
magnitude
(
temp
)
<
dlib
::
impl
::
magnitude
(
val
)
)
val
=
temp
;
val
=
temp
;
}
}
}
}
...
...
dlib/matrix/matrix_utilities_abstract.h
View file @
6e4c77cd
...
@@ -1355,7 +1355,9 @@ namespace dlib
...
@@ -1355,7 +1355,9 @@ namespace dlib
requires
requires
- m.size() > 0
- m.size() > 0
ensures
ensures
- returns the value of the smallest element of m
- returns the value of the smallest element of m. If m contains complex
elements then the element returned is the one with the smallest norm
according to std::norm().
!*/
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
@@ -1367,7 +1369,9 @@ namespace dlib
...
@@ -1367,7 +1369,9 @@ namespace dlib
requires
requires
- m.size() > 0
- m.size() > 0
ensures
ensures
- returns the value of the biggest element of m
- returns the value of the biggest element of m. If m contains complex
elements then the element returned is the one with the largest norm
according to std::norm().
!*/
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
...
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