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
ce3ed659
Commit
ce3ed659
authored
Aug 26, 2017
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added overloads of max_pointwise() and min_pointwise() that take 3 arguments.
parent
678728dc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
122 additions
and
0 deletions
+122
-0
matrix_utilities.h
dlib/matrix/matrix_utilities.h
+104
-0
matrix_utilities_abstract.h
dlib/matrix/matrix_utilities_abstract.h
+18
-0
No files found.
dlib/matrix/matrix_utilities.h
View file @
ce3ed659
...
...
@@ -353,6 +353,58 @@ namespace dlib
return
matrix_op
<
op
>
(
op
(
a
.
ref
(),
b
.
ref
()));
}
// ----------------------------------------------------------------------------------------
template
<
typename
M1
,
typename
M2
,
typename
M3
>
struct
op_min_pointwise3
:
basic_op_mmm
<
M1
,
M2
,
M3
>
{
op_min_pointwise3
(
const
M1
&
m1_
,
const
M2
&
m2_
,
const
M3
&
m3_
)
:
basic_op_mmm
<
M1
,
M2
,
M3
>
(
m1_
,
m2_
,
m3_
){}
typedef
typename
M1
::
type
type
;
typedef
const
typename
M1
::
type
const_ret_type
;
const
static
long
cost
=
M1
::
cost
+
M2
::
cost
+
M3
::
cost
+
2
;
const_ret_type
apply
(
long
r
,
long
c
)
const
{
return
std
::
min
(
this
->
m1
(
r
,
c
),
std
::
min
(
this
->
m2
(
r
,
c
),
this
->
m3
(
r
,
c
)));
}
};
template
<
typename
EXP1
,
typename
EXP2
,
typename
EXP3
>
inline
const
matrix_op
<
op_min_pointwise3
<
EXP1
,
EXP2
,
EXP3
>
>
min_pointwise
(
const
matrix_exp
<
EXP1
>&
a
,
const
matrix_exp
<
EXP2
>&
b
,
const
matrix_exp
<
EXP3
>&
c
)
{
COMPILE_TIME_ASSERT
((
is_same_type
<
typename
EXP1
::
type
,
typename
EXP2
::
type
>::
value
==
true
));
COMPILE_TIME_ASSERT
((
is_same_type
<
typename
EXP2
::
type
,
typename
EXP3
::
type
>::
value
==
true
));
COMPILE_TIME_ASSERT
(
EXP1
::
NR
==
EXP2
::
NR
||
EXP1
::
NR
==
0
||
EXP2
::
NR
==
0
);
COMPILE_TIME_ASSERT
(
EXP1
::
NC
==
EXP2
::
NC
||
EXP1
::
NR
==
0
||
EXP2
::
NC
==
0
);
COMPILE_TIME_ASSERT
(
EXP2
::
NR
==
EXP3
::
NR
||
EXP2
::
NR
==
0
||
EXP3
::
NR
==
0
);
COMPILE_TIME_ASSERT
(
EXP2
::
NC
==
EXP3
::
NC
||
EXP2
::
NC
==
0
||
EXP3
::
NC
==
0
);
DLIB_ASSERT
(
a
.
nr
()
==
b
.
nr
()
&&
a
.
nc
()
==
b
.
nc
()
&&
b
.
nr
()
==
c
.
nr
()
&&
b
.
nc
()
==
c
.
nc
(),
"
\t
const matrix_exp min_pointwise(a,b,c)"
<<
"
\n\t
You can only make a do a pointwise min between equally sized matrices"
<<
"
\n\t
a.nr(): "
<<
a
.
nr
()
<<
"
\n\t
a.nc(): "
<<
a
.
nc
()
<<
"
\n\t
b.nr(): "
<<
b
.
nr
()
<<
"
\n\t
b.nc(): "
<<
b
.
nc
()
<<
"
\n\t
c.nr(): "
<<
c
.
nr
()
<<
"
\n\t
c.nc(): "
<<
c
.
nc
()
);
typedef
op_min_pointwise3
<
EXP1
,
EXP2
,
EXP3
>
op
;
return
matrix_op
<
op
>
(
op
(
a
.
ref
(),
b
.
ref
(),
c
.
ref
()));
}
// ----------------------------------------------------------------------------------------
template
<
typename
M1
,
typename
M2
>
...
...
@@ -392,6 +444,58 @@ namespace dlib
return
matrix_op
<
op
>
(
op
(
a
.
ref
(),
b
.
ref
()));
}
// ----------------------------------------------------------------------------------------
template
<
typename
M1
,
typename
M2
,
typename
M3
>
struct
op_max_pointwise3
:
basic_op_mmm
<
M1
,
M2
,
M3
>
{
op_max_pointwise3
(
const
M1
&
m1_
,
const
M2
&
m2_
,
const
M3
&
m3_
)
:
basic_op_mmm
<
M1
,
M2
,
M3
>
(
m1_
,
m2_
,
m3_
){}
typedef
typename
M1
::
type
type
;
typedef
const
typename
M1
::
type
const_ret_type
;
const
static
long
cost
=
M1
::
cost
+
M2
::
cost
+
M3
::
cost
+
2
;
const_ret_type
apply
(
long
r
,
long
c
)
const
{
return
std
::
max
(
this
->
m1
(
r
,
c
),
std
::
max
(
this
->
m2
(
r
,
c
),
this
->
m3
(
r
,
c
)));
}
};
template
<
typename
EXP1
,
typename
EXP2
,
typename
EXP3
>
inline
const
matrix_op
<
op_max_pointwise3
<
EXP1
,
EXP2
,
EXP3
>
>
max_pointwise
(
const
matrix_exp
<
EXP1
>&
a
,
const
matrix_exp
<
EXP2
>&
b
,
const
matrix_exp
<
EXP3
>&
c
)
{
COMPILE_TIME_ASSERT
((
is_same_type
<
typename
EXP1
::
type
,
typename
EXP2
::
type
>::
value
==
true
));
COMPILE_TIME_ASSERT
((
is_same_type
<
typename
EXP2
::
type
,
typename
EXP3
::
type
>::
value
==
true
));
COMPILE_TIME_ASSERT
(
EXP1
::
NR
==
EXP2
::
NR
||
EXP1
::
NR
==
0
||
EXP2
::
NR
==
0
);
COMPILE_TIME_ASSERT
(
EXP1
::
NC
==
EXP2
::
NC
||
EXP1
::
NR
==
0
||
EXP2
::
NC
==
0
);
COMPILE_TIME_ASSERT
(
EXP2
::
NR
==
EXP3
::
NR
||
EXP2
::
NR
==
0
||
EXP3
::
NR
==
0
);
COMPILE_TIME_ASSERT
(
EXP2
::
NC
==
EXP3
::
NC
||
EXP2
::
NC
==
0
||
EXP3
::
NC
==
0
);
DLIB_ASSERT
(
a
.
nr
()
==
b
.
nr
()
&&
a
.
nc
()
==
b
.
nc
()
&&
b
.
nr
()
==
c
.
nr
()
&&
b
.
nc
()
==
c
.
nc
(),
"
\t
const matrix_exp max_pointwise(a,b,c)"
<<
"
\n\t
You can only make a do a pointwise max between equally sized matrices"
<<
"
\n\t
a.nr(): "
<<
a
.
nr
()
<<
"
\n\t
a.nc(): "
<<
a
.
nc
()
<<
"
\n\t
b.nr(): "
<<
b
.
nr
()
<<
"
\n\t
b.nc(): "
<<
b
.
nc
()
<<
"
\n\t
c.nr(): "
<<
c
.
nr
()
<<
"
\n\t
c.nc(): "
<<
c
.
nc
()
);
typedef
op_max_pointwise3
<
EXP1
,
EXP2
,
EXP3
>
op
;
return
matrix_op
<
op
>
(
op
(
a
.
ref
(),
b
.
ref
(),
c
.
ref
()));
}
// ----------------------------------------------------------------------------------------
template
<
...
...
dlib/matrix/matrix_utilities_abstract.h
View file @
ce3ed659
...
...
@@ -1380,6 +1380,15 @@ namespace dlib
R(r,c) == std::min(a(r,c), b(r,c))
!*/
const
matrix_exp
min_pointwise
(
const
matrix_exp
&
a
,
const
matrix_exp
&
b
,
const
matrix_exp
&
c
);
/*!
performs min_pointwise(a,min_pointwise(b,c));
!*/
// ----------------------------------------------------------------------------------------
const
matrix_exp
::
type
max
(
...
...
@@ -1413,6 +1422,15 @@ namespace dlib
R(r,c) == std::max(a(r,c), b(r,c))
!*/
const
matrix_exp
max_pointwise
(
const
matrix_exp
&
a
,
const
matrix_exp
&
b
,
const
matrix_exp
&
c
);
/*!
performs max_pointwise(a,max_pointwise(b,c));
!*/
// ----------------------------------------------------------------------------------------
void
find_min_and_max
(
...
...
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