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
7f5dbb71
"...api/git@developer.sourcefind.cn:renzhc/diffusers_dcu.git" did not exist on "a85b34e7fdc0a5fceb11aa0fa6199bd9afaca396"
Commit
7f5dbb71
authored
Feb 28, 2012
by
Davis King
Browse files
Made sum() and mean() work with complex numbers.
parent
2cfe8f93
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
1 deletion
+25
-1
dlib/matrix/matrix_utilities.h
dlib/matrix/matrix_utilities.h
+14
-1
dlib/test/matrix4.cpp
dlib/test/matrix4.cpp
+11
-0
No files found.
dlib/matrix/matrix_utilities.h
View file @
7f5dbb71
...
@@ -1669,13 +1669,26 @@ namespace dlib
...
@@ -1669,13 +1669,26 @@ namespace dlib
template
<
template
<
typename
EXP
typename
EXP
>
>
inline
const
typename
matrix_exp
<
EXP
>::
type
mean
(
inline
const
typename
disable_if
<
is_complex
<
typename
EXP
::
type
>
,
typename
matrix_exp
<
EXP
>::
type
>::
type
mean
(
const
matrix_exp
<
EXP
>&
m
const
matrix_exp
<
EXP
>&
m
)
)
{
{
return
sum
(
m
)
/
(
m
.
nr
()
*
m
.
nc
());
return
sum
(
m
)
/
(
m
.
nr
()
*
m
.
nc
());
}
}
// ----------------------------------------------------------------------------------------
template
<
typename
EXP
>
inline
const
typename
enable_if
<
is_complex
<
typename
EXP
::
type
>
,
typename
matrix_exp
<
EXP
>::
type
>::
type
mean
(
const
matrix_exp
<
EXP
>&
m
)
{
typedef
typename
EXP
::
type
::
value_type
type
;
return
sum
(
m
)
/
(
type
)(
m
.
nr
()
*
m
.
nc
());
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
template
<
...
...
dlib/test/matrix4.cpp
View file @
7f5dbb71
...
@@ -775,6 +775,15 @@ namespace
...
@@ -775,6 +775,15 @@ namespace
}
}
}
}
void
test_complex
()
{
matrix
<
complex
<
double
>
>
a
,
b
;
a
=
complex_matrix
(
linspace
(
1
,
7
,
7
),
linspace
(
2
,
8
,
7
));
b
=
complex_matrix
(
linspace
(
4
,
10
,
7
),
linspace
(
2
,
8
,
7
));
DLIB_TEST
(
mean
(
a
)
==
complex
<
double
>
(
4
,
5
));
}
class
matrix_tester
:
public
tester
class
matrix_tester
:
public
tester
...
@@ -795,6 +804,8 @@ namespace
...
@@ -795,6 +804,8 @@ namespace
test_stuff
();
test_stuff
();
for
(
int
i
=
0
;
i
<
10
;
++
i
)
for
(
int
i
=
0
;
i
<
10
;
++
i
)
matrix_test
();
matrix_test
();
test_complex
();
}
}
}
a
;
}
a
;
...
...
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