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
e3307db4
Commit
e3307db4
authored
Mar 10, 2012
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added some more convenient overloads of the zeros_matrix(), ones_matrix(),
and identity_matrix() functions.
parent
17565cfb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
102 additions
and
0 deletions
+102
-0
matrix_utilities.h
dlib/matrix/matrix_utilities.h
+58
-0
matrix_utilities_abstract.h
dlib/matrix/matrix_utilities_abstract.h
+39
-0
matrix.cpp
dlib/test/matrix.cpp
+5
-0
No files found.
dlib/matrix/matrix_utilities.h
View file @
e3307db4
...
...
@@ -1882,6 +1882,26 @@ namespace dlib
return
matrix_op
<
op
>
(
op
(
nr
,
nc
,
0
));
}
// ----------------------------------------------------------------------------------------
template
<
typename
EXP
>
const
matrix_op
<
op_uniform_matrix_3
<
typename
EXP
::
type
>
>
zeros_matrix
(
const
matrix_exp
<
EXP
>&
mat
)
{
DLIB_ASSERT
(
mat
.
nr
()
>
0
&&
mat
.
nc
()
>
0
,
"
\t
const matrix_exp zeros_matrix(mat)"
<<
"
\n\t
nr and nc have to be bigger than 0"
<<
"
\n\t
mat.nr(): "
<<
mat
.
nr
()
<<
"
\n\t
mat.nc(): "
<<
mat
.
nc
()
);
typedef
typename
EXP
::
type
T
;
typedef
op_uniform_matrix_3
<
T
>
op
;
return
matrix_op
<
op
>
(
op
(
mat
.
nr
(),
mat
.
nc
(),
0
));
}
// ----------------------------------------------------------------------------------------
template
<
...
...
@@ -1902,6 +1922,26 @@ namespace dlib
return
matrix_op
<
op
>
(
op
(
nr
,
nc
,
1
));
}
// ----------------------------------------------------------------------------------------
template
<
typename
EXP
>
const
matrix_op
<
op_uniform_matrix_3
<
typename
EXP
::
type
>
>
ones_matrix
(
const
matrix_exp
<
EXP
>&
mat
)
{
DLIB_ASSERT
(
mat
.
nr
()
>
0
&&
mat
.
nc
()
>
0
,
"
\t
const matrix_exp ones_matrix(mat)"
<<
"
\n\t
nr and nc have to be bigger than 0"
<<
"
\n\t
mat.nr(): "
<<
mat
.
nr
()
<<
"
\n\t
mat.nc(): "
<<
mat
.
nc
()
);
typedef
typename
EXP
::
type
T
;
typedef
op_uniform_matrix_3
<
T
>
op
;
return
matrix_op
<
op
>
(
op
(
mat
.
nr
(),
mat
.
nc
(),
1
));
}
// ----------------------------------------------------------------------------------------
template
<
...
...
@@ -2051,6 +2091,24 @@ namespace dlib
return
matrix_diag_op
<
op
>
(
op
(
size
));
}
template
<
typename
EXP
>
const
matrix_diag_op
<
op_identity_matrix_2
<
typename
EXP
::
type
>
>
identity_matrix
(
const
matrix_exp
<
EXP
>&
mat
)
{
DLIB_ASSERT
(
mat
.
nr
()
==
mat
.
nc
(),
"
\t
const matrix_exp identity_matrix(mat)"
<<
"
\n\t
mat must be a square matrix."
<<
"
\n\t
mat.nr(): "
<<
mat
.
nr
()
<<
"
\n\t
mat.nc(): "
<<
mat
.
nc
()
);
typedef
typename
EXP
::
type
T
;
typedef
op_identity_matrix_2
<
T
>
op
;
return
matrix_diag_op
<
op
>
(
op
(
mat
.
nr
()));
}
// ----------------------------------------------------------------------------------------
template
<
...
...
dlib/matrix/matrix_utilities_abstract.h
View file @
e3307db4
...
...
@@ -245,6 +245,19 @@ namespace dlib
- returns an nr by nc matrix with elements of type T and all set to val.
!*/
// ----------------------------------------------------------------------------------------
const
matrix_exp
ones_matrix
(
const
matrix_exp
&
mat
);
/*!
requires
- mat.nr() > 0 && mat.nc() > 0
ensures
- Let T denote the type of element in mat. Then this function
returns uniform_matrix<T>(mat.nr(), mat.nc(), 1)
!*/
// ----------------------------------------------------------------------------------------
template
<
...
...
@@ -261,6 +274,19 @@ namespace dlib
- returns uniform_matrix<T>(nr, nc, 1)
!*/
// ----------------------------------------------------------------------------------------
const
matrix_exp
zeros_matrix
(
const
matrix_exp
&
mat
);
/*!
requires
- mat.nr() > 0 && mat.nc() > 0
ensures
- Let T denote the type of element in mat. Then this function
returns uniform_matrix<T>(mat.nr(), mat.nc(), 0)
!*/
// ----------------------------------------------------------------------------------------
template
<
...
...
@@ -277,6 +303,19 @@ namespace dlib
- returns uniform_matrix<T>(nr, nc, 0)
!*/
// ----------------------------------------------------------------------------------------
const
matrix_exp
identity_matrix
(
const
matrix_exp
&
mat
);
/*!
requires
- mat.nr() == mat.nc()
ensures
- returns an identity matrix with the same dimensions as mat and
containing the same type of elements as mat.
!*/
// ----------------------------------------------------------------------------------------
template
<
...
...
dlib/test/matrix.cpp
View file @
e3307db4
...
...
@@ -65,6 +65,8 @@ namespace
DLIB_TEST
(
mi
.
nc
()
==
m
.
nr
());
DLIB_TEST
((
equal
(
round_zeros
(
mi
*
m
,
0.000001
)
,
identity_matrix
<
double
,
5
>
())));
DLIB_TEST
((
equal
(
round_zeros
(
m
*
mi
,
0.000001
)
,
identity_matrix
<
double
,
5
>
())));
DLIB_TEST
((
equal
(
round_zeros
(
mi
*
m
,
0.000001
)
,
identity_matrix
(
m
))));
DLIB_TEST
((
equal
(
round_zeros
(
m
*
mi
,
0.000001
)
,
identity_matrix
(
m
))));
}
{
matrix
<
double
,
5
,
0
,
MM
>
m
(
5
,
5
);
...
...
@@ -1041,8 +1043,11 @@ namespace
}
{
matrix
<
double
>
mat
(
4
,
5
);
DLIB_TEST
((
uniform_matrix
<
double
>
(
4
,
5
,
1
)
==
ones_matrix
<
double
>
(
4
,
5
)));
DLIB_TEST
((
uniform_matrix
<
double
>
(
4
,
5
,
1
)
==
ones_matrix
(
mat
)));
DLIB_TEST
((
uniform_matrix
<
double
>
(
4
,
5
,
0
)
==
zeros_matrix
<
double
>
(
4
,
5
)));
DLIB_TEST
((
uniform_matrix
<
double
>
(
4
,
5
,
0
)
==
zeros_matrix
(
mat
)));
DLIB_TEST
((
uniform_matrix
<
float
>
(
4
,
5
,
1
)
==
ones_matrix
<
float
>
(
4
,
5
)));
DLIB_TEST
((
uniform_matrix
<
float
>
(
4
,
5
,
0
)
==
zeros_matrix
<
float
>
(
4
,
5
)));
DLIB_TEST
((
uniform_matrix
<
complex
<
double
>
>
(
4
,
5
,
1
)
==
ones_matrix
<
complex
<
double
>
>
(
4
,
5
)));
...
...
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