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
e9fa6539
"vscode:/vscode.git/clone" did not exist on "17b48b97bb5719b961ed546f524b6aa8d3763ece"
Commit
e9fa6539
authored
Apr 18, 2016
by
Davis King
Browse files
Added a matrix constructor that takes an initializer list.
parent
13bc3880
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
0 deletions
+76
-0
dlib/matrix/matrix.h
dlib/matrix/matrix.h
+52
-0
dlib/matrix/matrix_abstract.h
dlib/matrix/matrix_abstract.h
+24
-0
No files found.
dlib/matrix/matrix.h
View file @
e9fa6539
...
...
@@ -16,6 +16,9 @@
#include "matrix_assign_fwd.h"
#include "matrix_op.h"
#include <utility>
#ifdef DLIB_HAS_RVALUE_REFERENCES
#include <initializer_list>
#endif
#ifdef MATLAB_MEX_FILE
#include <mex.h>
...
...
@@ -1112,6 +1115,55 @@ namespace dlib
}
#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
)
{
#ifdef MATLAB_MEX_FILE
...
...
dlib/matrix/matrix_abstract.h
View file @
e9fa6539
...
...
@@ -337,6 +337,30 @@ namespace dlib
- #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
()
(
long
r
,
long
c
...
...
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