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
2a4e62f2
Commit
2a4e62f2
authored
Nov 17, 2013
by
Davis King
Browse files
Added sign() for matrix objects.
parent
31727df7
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
0 deletions
+43
-0
dlib/matrix/matrix_math_functions.h
dlib/matrix/matrix_math_functions.h
+10
-0
dlib/matrix/matrix_math_functions_abstract.h
dlib/matrix/matrix_math_functions_abstract.h
+18
-0
dlib/test/matrix3.cpp
dlib/test/matrix3.cpp
+15
-0
No files found.
dlib/matrix/matrix_math_functions.h
View file @
2a4e62f2
...
...
@@ -79,6 +79,15 @@ namespace dlib
return
val
*
val
;
}
template
<
typename
type
>
inline
type
sign
(
const
type
&
val
)
{
if
(
val
>=
0
)
return
+
1
;
else
return
-
1
;
}
template
<
typename
type
>
type
cubed
(
const
type
&
val
)
{
...
...
@@ -153,6 +162,7 @@ namespace dlib
DLIB_DEFINE_FUNCTION_M
(
op_round_zeros2
,
round_zeros
,
impl
::
round_zeros
,
7
);
DLIB_DEFINE_FUNCTION_M
(
op_cubed
,
cubed
,
impl
::
cubed
,
7
);
DLIB_DEFINE_FUNCTION_M
(
op_squared
,
squared
,
impl
::
squared
,
6
);
DLIB_DEFINE_FUNCTION_M
(
op_sign
,
sign
,
impl
::
sign
,
6
);
DLIB_DEFINE_FUNCTION_MS
(
op_pow1
,
pow
,
impl
::
pow1
,
7
);
DLIB_DEFINE_FUNCTION_SM
(
op_pow2
,
pow
,
impl
::
pow2
,
7
);
DLIB_DEFINE_FUNCTION_M
(
op_reciprocal
,
reciprocal
,
impl
::
reciprocal
,
6
);
...
...
dlib/matrix/matrix_math_functions_abstract.h
View file @
2a4e62f2
...
...
@@ -136,6 +136,24 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// Miscellaneous
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
const
matrix_exp
sign
(
const
matrix_exp
&
m
);
/*!
ensures
- returns a matrix that tells the sign of each element in m. In particular:
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) >= 0) then
- R(r,c) == +1
- else
- R(r,c) == -1
!*/
// ----------------------------------------------------------------------------------------
const
matrix_exp
sigmoid
(
...
...
dlib/test/matrix3.cpp
View file @
2a4e62f2
...
...
@@ -997,6 +997,21 @@ namespace
DLIB_TEST
(
sum_rows
(
a
)
==
c
);
}
{
matrix
<
int
>
m
(
3
,
4
),
s
(
3
,
4
);
m
=
-
2
,
1
,
5
,
-
5
,
5
,
5
,
5
,
5
,
9
,
0
,
-
4
,
-
2
;
s
=
-
1
,
1
,
1
,
-
1
,
1
,
1
,
1
,
1
,
1
,
1
,
-
1
,
-
1
;
DLIB_TEST
(
sign
(
m
)
==
s
);
DLIB_TEST
(
sign
(
matrix_cast
<
double
>
(
m
))
==
matrix_cast
<
double
>
(
s
));
}
}
...
...
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