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
e9fa6539
Commit
e9fa6539
authored
Apr 18, 2016
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a matrix constructor that takes an initializer list.
parent
13bc3880
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
0 deletions
+76
-0
matrix.h
dlib/matrix/matrix.h
+52
-0
matrix_abstract.h
dlib/matrix/matrix_abstract.h
+24
-0
No files found.
dlib/matrix/matrix.h
View file @
e9fa6539
...
@@ -16,6 +16,9 @@
...
@@ -16,6 +16,9 @@
#include "matrix_assign_fwd.h"
#include "matrix_assign_fwd.h"
#include "matrix_op.h"
#include "matrix_op.h"
#include <utility>
#include <utility>
#ifdef DLIB_HAS_RVALUE_REFERENCES
#include <initializer_list>
#endif
#ifdef MATLAB_MEX_FILE
#ifdef MATLAB_MEX_FILE
#include <mex.h>
#include <mex.h>
...
@@ -1112,6 +1115,55 @@ namespace dlib
...
@@ -1112,6 +1115,55 @@ namespace dlib
}
}
#ifdef DLIB_HAS_RVALUE_REFERENCES
#ifdef DLIB_HAS_RVALUE_REFERENCES
matrix
(
const
std
::
initializer_list
<
T
>&
l
)
{
if
(
NR
*
NC
!=
0
)
{
DLIB_ASSERT
(
l
.
size
()
==
NR
*
NC
,
"
\t
matrix::matrix(const std::initializer_list& l)"
<<
"
\n\t
You are trying to initialize a statically sized matrix with a list that doesn't have a matching size."
<<
"
\n\t
l.size(): "
<<
l
.
size
()
<<
"
\n\t
NR*NC: "
<<
NR
*
NC
);
data
.
set_size
(
NR
,
NC
);
}
else
if
(
NR
!=
0
)
{
DLIB_ASSERT
(
l
.
size
()
%
NR
==
0
,
"
\t
matrix::matrix(const std::initializer_list& l)"
<<
"
\n\t
You are trying to initialize a statically sized matrix with a list that doesn't have a compatible size."
<<
"
\n\t
l.size(): "
<<
l
.
size
()
<<
"
\n\t
NR: "
<<
NR
);
if
(
l
.
size
()
!=
0
)
data
.
set_size
(
NR
,
l
.
size
()
/
NR
);
}
else
if
(
NC
!=
0
)
{
DLIB_ASSERT
(
l
.
size
()
%
NC
==
0
,
"
\t
matrix::matrix(const std::initializer_list& l)"
<<
"
\n\t
You are trying to initialize a statically sized matrix with a list that doesn't have a compatible size."
<<
"
\n\t
l.size(): "
<<
l
.
size
()
<<
"
\n\t
NC: "
<<
NC
);
if
(
l
.
size
()
!=
0
)
data
.
set_size
(
l
.
size
()
/
NC
,
NC
);
}
else
if
(
l
.
size
()
!=
0
)
{
data
.
set_size
(
l
.
size
(),
1
);
}
if
(
l
.
size
()
!=
0
)
{
T
*
d
=
&
data
(
0
,
0
);
for
(
auto
&&
v
:
l
)
*
d
++
=
v
;
}
}
matrix
(
matrix
&&
item
)
matrix
(
matrix
&&
item
)
{
{
#ifdef MATLAB_MEX_FILE
#ifdef MATLAB_MEX_FILE
...
...
dlib/matrix/matrix_abstract.h
View file @
e9fa6539
...
@@ -336,6 +336,30 @@ namespace dlib
...
@@ -336,6 +336,30 @@ namespace dlib
- #aliases(*this) == true
- #aliases(*this) == true
- #ref().aliases(*this) == true
- #ref().aliases(*this) == true
!*/
!*/
matrix
(
const
std
::
initializer_list
<
T
>&
l
);
/*!
requires
- This matrix is capable of having a size() == l.size(). Therefore, if
NR*NC != 0 then l.size() must equal NR*NC. Alternatively, if NR or NC is
!= 0 then l.size() must be a multiple of the non-zero NR or NC.
ensures
- #size() == l.size()
- The contents of l are enumerated and read into the matrix in row major order.
- if (NR != 0) then
- #nr() == NR
- #nc() == l.size()/NR
- if (NC != 0) then
- #nr() == l.size()/NC
- #nc() == NC
- if (NR*NC==0) then
- #nr() == l.size()
- #nc() == 1
- #aliases(*this) == true
- #ref().aliases(*this) == true
!*/
T
&
operator
()
(
T
&
operator
()
(
long
r
,
long
r
,
...
...
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