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
4103be8b
Commit
4103be8b
authored
Nov 18, 2016
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added min_pointwise() and max_pointwise().
parent
30c62962
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
138 additions
and
0 deletions
+138
-0
matrix_utilities.h
dlib/matrix/matrix_utilities.h
+78
-0
matrix_utilities_abstract.h
dlib/matrix/matrix_utilities_abstract.h
+38
-0
matrix.cpp
dlib/test/matrix.cpp
+22
-0
No files found.
dlib/matrix/matrix_utilities.h
View file @
4103be8b
...
@@ -314,6 +314,84 @@ namespace dlib
...
@@ -314,6 +314,84 @@ namespace dlib
return
val
;
return
val
;
}
}
// ----------------------------------------------------------------------------------------
template
<
typename
M1
,
typename
M2
>
struct
op_binary_min
:
basic_op_mm
<
M1
,
M2
>
{
op_binary_min
(
const
M1
&
m1_
,
const
M2
&
m2_
)
:
basic_op_mm
<
M1
,
M2
>
(
m1_
,
m2_
){}
typedef
typename
M1
::
type
type
;
typedef
const
type
const_ret_type
;
const
static
long
cost
=
M1
::
cost
+
M2
::
cost
+
1
;
const_ret_type
apply
(
long
r
,
long
c
)
const
{
return
std
::
min
(
this
->
m1
(
r
,
c
),
this
->
m2
(
r
,
c
));
}
};
template
<
typename
EXP1
,
typename
EXP2
>
inline
const
matrix_op
<
op_binary_min
<
EXP1
,
EXP2
>
>
min_pointwise
(
const
matrix_exp
<
EXP1
>&
a
,
const
matrix_exp
<
EXP2
>&
b
)
{
COMPILE_TIME_ASSERT
((
is_same_type
<
typename
EXP1
::
type
,
typename
EXP2
::
type
>::
value
==
true
));
COMPILE_TIME_ASSERT
(
EXP1
::
NR
==
EXP2
::
NR
||
EXP1
::
NR
==
0
||
EXP2
::
NR
==
0
);
COMPILE_TIME_ASSERT
(
EXP1
::
NC
==
EXP2
::
NC
||
EXP1
::
NC
==
0
||
EXP2
::
NC
==
0
);
DLIB_ASSERT
(
a
.
nr
()
==
b
.
nr
()
&&
a
.
nc
()
==
b
.
nc
(),
"
\t
const matrix_exp min_pointwise(const matrix_exp& a, const matrix_exp& b)"
<<
"
\n\t
a.nr(): "
<<
a
.
nr
()
<<
"
\n\t
a.nc(): "
<<
a
.
nc
()
<<
"
\n\t
b.nr(): "
<<
b
.
nr
()
<<
"
\n\t
b.nc(): "
<<
b
.
nc
()
);
typedef
op_binary_min
<
EXP1
,
EXP2
>
op
;
return
matrix_op
<
op
>
(
op
(
a
.
ref
(),
b
.
ref
()));
}
// ----------------------------------------------------------------------------------------
template
<
typename
M1
,
typename
M2
>
struct
op_binary_max
:
basic_op_mm
<
M1
,
M2
>
{
op_binary_max
(
const
M1
&
m1_
,
const
M2
&
m2_
)
:
basic_op_mm
<
M1
,
M2
>
(
m1_
,
m2_
){}
typedef
typename
M1
::
type
type
;
typedef
const
type
const_ret_type
;
const
static
long
cost
=
M1
::
cost
+
M2
::
cost
+
1
;
const_ret_type
apply
(
long
r
,
long
c
)
const
{
return
std
::
max
(
this
->
m1
(
r
,
c
),
this
->
m2
(
r
,
c
));
}
};
template
<
typename
EXP1
,
typename
EXP2
>
inline
const
matrix_op
<
op_binary_max
<
EXP1
,
EXP2
>
>
max_pointwise
(
const
matrix_exp
<
EXP1
>&
a
,
const
matrix_exp
<
EXP2
>&
b
)
{
COMPILE_TIME_ASSERT
((
is_same_type
<
typename
EXP1
::
type
,
typename
EXP2
::
type
>::
value
==
true
));
COMPILE_TIME_ASSERT
(
EXP1
::
NR
==
EXP2
::
NR
||
EXP1
::
NR
==
0
||
EXP2
::
NR
==
0
);
COMPILE_TIME_ASSERT
(
EXP1
::
NC
==
EXP2
::
NC
||
EXP1
::
NC
==
0
||
EXP2
::
NC
==
0
);
DLIB_ASSERT
(
a
.
nr
()
==
b
.
nr
()
&&
a
.
nc
()
==
b
.
nc
(),
"
\t
const matrix_exp max_pointwise(const matrix_exp& a, const matrix_exp& b)"
<<
"
\n\t
a.nr(): "
<<
a
.
nr
()
<<
"
\n\t
a.nc(): "
<<
a
.
nc
()
<<
"
\n\t
b.nr(): "
<<
b
.
nr
()
<<
"
\n\t
b.nc(): "
<<
b
.
nc
()
);
typedef
op_binary_max
<
EXP1
,
EXP2
>
op
;
return
matrix_op
<
op
>
(
op
(
a
.
ref
(),
b
.
ref
()));
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
template
<
...
...
dlib/matrix/matrix_utilities_abstract.h
View file @
4103be8b
...
@@ -1361,6 +1361,25 @@ namespace dlib
...
@@ -1361,6 +1361,25 @@ namespace dlib
according to std::norm().
according to std::norm().
!*/
!*/
// ----------------------------------------------------------------------------------------
const
matrix_exp
min_pointwise
(
const
matrix_exp
&
a
,
const
matrix_exp
&
b
);
/*!
requires
- a.nr() == b.nr()
- a.nc() == b.nc()
- a and b both contain the same type of element
ensures
- returns a matrix R such that:
- R::type == the same type that was in a and b.
- R has the same dimensions as a and b.
- for all valid r and c:
R(r,c) == std::min(a(r,c), b(r,c))
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
const
matrix_exp
::
type
max
(
const
matrix_exp
::
type
max
(
...
@@ -1375,6 +1394,25 @@ namespace dlib
...
@@ -1375,6 +1394,25 @@ namespace dlib
according to std::norm().
according to std::norm().
!*/
!*/
// ----------------------------------------------------------------------------------------
const
matrix_exp
max_pointwise
(
const
matrix_exp
&
a
,
const
matrix_exp
&
b
);
/*!
requires
- a.nr() == b.nr()
- a.nc() == b.nc()
- a and b both contain the same type of element
ensures
- returns a matrix R such that:
- R::type == the same type that was in a and b.
- R has the same dimensions as a and b.
- for all valid r and c:
R(r,c) == std::max(a(r,c), b(r,c))
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
void
find_min_and_max
(
void
find_min_and_max
(
...
...
dlib/test/matrix.cpp
View file @
4103be8b
...
@@ -1063,6 +1063,28 @@ namespace
...
@@ -1063,6 +1063,28 @@ namespace
}
}
{
matrix
<
double
>
a
=
randm
(
3
,
4
);
matrix
<
double
>
b
=
randm
(
3
,
4
);
matrix
<
double
>
m1
,
m2
;
m1
=
max_pointwise
(
a
,
b
);
m2
=
min_pointwise
(
a
,
b
);
DLIB_TEST
(
m1
.
nr
()
==
a
.
nr
());
DLIB_TEST
(
m1
.
nc
()
==
a
.
nc
());
DLIB_TEST
(
m2
.
nr
()
==
a
.
nr
());
DLIB_TEST
(
m2
.
nc
()
==
a
.
nc
());
for
(
long
r
=
0
;
r
<
a
.
nr
();
++
r
)
{
for
(
long
c
=
0
;
c
<
a
.
nc
();
++
c
)
{
DLIB_TEST_MSG
(
m1
(
r
,
c
)
==
std
::
max
(
a
(
r
,
c
),
b
(
r
,
c
)),
m1
(
r
,
c
)
<<
" : "
<<
a
(
r
,
c
)
<<
" "
<<
b
(
r
,
c
));
DLIB_TEST
(
m2
(
r
,
c
)
==
std
::
min
(
a
(
r
,
c
),
b
(
r
,
c
)));
}
}
}
{
{
matrix
<
double
,
4
,
5
>
m
;
matrix
<
double
,
4
,
5
>
m
;
set_subm
(
m
,
range
(
0
,
3
),
range
(
0
,
4
))
=
4
;
set_subm
(
m
,
range
(
0
,
3
),
range
(
0
,
4
))
=
4
;
...
...
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