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
8c1d1b08
Commit
8c1d1b08
authored
Mar 29, 2012
by
Davis King
Browse files
Added lowerbound() and upperbound() routines.
parent
28215b40
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
135 additions
and
0 deletions
+135
-0
dlib/matrix/matrix_utilities.h
dlib/matrix/matrix_utilities.h
+74
-0
dlib/matrix/matrix_utilities_abstract.h
dlib/matrix/matrix_utilities_abstract.h
+36
-0
dlib/test/matrix4.cpp
dlib/test/matrix4.cpp
+25
-0
No files found.
dlib/matrix/matrix_utilities.h
View file @
8c1d1b08
...
@@ -2872,6 +2872,80 @@ namespace dlib
...
@@ -2872,6 +2872,80 @@ namespace dlib
return
matrix_op
<
op
>
(
op
(
m
.
ref
(),
lower
,
upper
));
return
matrix_op
<
op
>
(
op
(
m
.
ref
(),
lower
,
upper
));
}
}
// ----------------------------------------------------------------------------------------
template
<
typename
M
>
struct
op_lowerbound
:
basic_op_m
<
M
>
{
typedef
typename
M
::
type
type
;
op_lowerbound
(
const
M
&
m_
,
const
type
&
thresh_
)
:
basic_op_m
<
M
>
(
m_
),
thresh
(
thresh_
){}
const
type
&
thresh
;
typedef
const
typename
M
::
type
const_ret_type
;
const
static
long
cost
=
M
::
cost
+
2
;
const_ret_type
apply
(
long
r
,
long
c
)
const
{
const
type
temp
=
this
->
m
(
r
,
c
);
if
(
temp
>=
thresh
)
return
temp
;
else
return
thresh
;
}
};
template
<
typename
EXP
>
const
matrix_op
<
op_lowerbound
<
EXP
>
>
lowerbound
(
const
matrix_exp
<
EXP
>&
m
,
const
typename
EXP
::
type
&
thresh
)
{
typedef
op_lowerbound
<
EXP
>
op
;
return
matrix_op
<
op
>
(
op
(
m
.
ref
(),
thresh
));
}
// ----------------------------------------------------------------------------------------
template
<
typename
M
>
struct
op_upperbound
:
basic_op_m
<
M
>
{
typedef
typename
M
::
type
type
;
op_upperbound
(
const
M
&
m_
,
const
type
&
thresh_
)
:
basic_op_m
<
M
>
(
m_
),
thresh
(
thresh_
){}
const
type
&
thresh
;
typedef
const
typename
M
::
type
const_ret_type
;
const
static
long
cost
=
M
::
cost
+
2
;
const_ret_type
apply
(
long
r
,
long
c
)
const
{
const
type
temp
=
this
->
m
(
r
,
c
);
if
(
temp
<=
thresh
)
return
temp
;
else
return
thresh
;
}
};
template
<
typename
EXP
>
const
matrix_op
<
op_upperbound
<
EXP
>
>
upperbound
(
const
matrix_exp
<
EXP
>&
m
,
const
typename
EXP
::
type
&
thresh
)
{
typedef
op_upperbound
<
EXP
>
op
;
return
matrix_op
<
op
>
(
op
(
m
.
ref
(),
thresh
));
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
M
>
template
<
typename
M
>
...
...
dlib/matrix/matrix_utilities_abstract.h
View file @
8c1d1b08
...
@@ -1707,6 +1707,42 @@ namespace dlib
...
@@ -1707,6 +1707,42 @@ namespace dlib
- R(r,c) == m(r,c)
- R(r,c) == m(r,c)
!*/
!*/
// ----------------------------------------------------------------------------------------
const
matrix_exp
lowerbound
(
const
matrix_exp
&
m
,
const
matrix_exp
::
type
&
thresh
);
/*!
ensures
- returns a matrix R such that:
- R::type == the same type that was in m
- R has the same dimensions as m
- for all valid r and c:
- if (m(r,c) >= thresh) then
- R(r,c) == m(r,c)
- else
- R(r,c) == thresh
!*/
// ----------------------------------------------------------------------------------------
const
matrix_exp
upperbound
(
const
matrix_exp
&
m
,
const
matrix_exp
::
type
&
thresh
);
/*!
ensures
- returns a matrix R such that:
- R::type == the same type that was in m
- R has the same dimensions as m
- for all valid r and c:
- if (m(r,c) <= thresh) then
- R(r,c) == m(r,c)
- else
- R(r,c) == thresh
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
}
}
...
...
dlib/test/matrix4.cpp
View file @
8c1d1b08
...
@@ -607,6 +607,31 @@ namespace
...
@@ -607,6 +607,31 @@ namespace
DLIB_TEST
(
equal
(
0.0
/
m
,
zeros_matrix
<
double
>
(
3
,
4
)));
DLIB_TEST
(
equal
(
0.0
/
m
,
zeros_matrix
<
double
>
(
3
,
4
)));
}
}
}
}
{
matrix
<
int
>
m
(
2
,
3
);
m
=
1
,
2
,
3
,
4
,
5
,
6
;
matrix
<
int
>
M
(
2
,
3
);
M
=
m
;
DLIB_TEST
(
upperbound
(
m
,
6
)
==
M
);
DLIB_TEST
(
upperbound
(
m
,
60
)
==
M
);
DLIB_TEST
(
lowerbound
(
m
,
-
2
)
==
M
);
DLIB_TEST
(
lowerbound
(
m
,
0
)
==
M
);
M
=
2
,
2
,
3
,
4
,
5
,
6
;
DLIB_TEST
(
lowerbound
(
m
,
2
)
==
M
);
M
=
0
,
0
,
0
,
0
,
0
,
0
;
DLIB_TEST
(
upperbound
(
m
,
0
)
==
M
);
M
=
1
,
2
,
3
,
3
,
3
,
3
;
DLIB_TEST
(
upperbound
(
m
,
3
)
==
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