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
ee4e7aea
Commit
ee4e7aea
authored
Dec 24, 2012
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added STL style begin() and end() methods to matrix and matrix_exp.
parent
634f4db4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
159 additions
and
0 deletions
+159
-0
matrix.h
dlib/matrix/matrix.h
+35
-0
matrix_abstract.h
dlib/matrix/matrix_abstract.h
+40
-0
matrix_exp.h
dlib/matrix/matrix_exp.h
+61
-0
matrix_exp_abstract.h
dlib/matrix/matrix_exp_abstract.h
+23
-0
No files found.
dlib/matrix/matrix.h
View file @
ee4e7aea
...
...
@@ -996,6 +996,8 @@ namespace dlib
const
static
long
NR
=
matrix_traits
<
matrix
>::
NR
;
const
static
long
NC
=
matrix_traits
<
matrix
>::
NC
;
const
static
long
cost
=
matrix_traits
<
matrix
>::
cost
;
typedef
T
*
iterator
;
typedef
const
T
*
const_iterator
;
matrix
()
{
...
...
@@ -1551,6 +1553,39 @@ namespace dlib
const
matrix_exp
<
U
>&
)
const
{
return
false
;
}
iterator
begin
()
{
if
(
size
()
!=
0
)
return
&
data
(
0
,
0
);
else
return
0
;
}
iterator
end
()
{
if
(
size
()
!=
0
)
return
&
data
(
0
,
0
)
+
size
();
else
return
0
;
}
const_iterator
begin
()
const
{
if
(
size
()
!=
0
)
return
&
data
(
0
,
0
);
else
return
0
;
}
const_iterator
end
()
const
{
if
(
size
()
!=
0
)
return
&
data
(
0
,
0
)
+
size
();
else
return
0
;
}
private
:
struct
literal_assign_helper
{
...
...
dlib/matrix/matrix_abstract.h
View file @
ee4e7aea
...
...
@@ -253,6 +253,8 @@ namespace dlib
const
static
long
NR
=
num_rows
;
const
static
long
NC
=
num_cols
;
const
static
long
cost
=
1
;
typedef
T
*
iterator
;
typedef
const
T
*
const_iterator
;
matrix
(
);
...
...
@@ -601,6 +603,44 @@ namespace dlib
ensures
- swaps *this and item
!*/
iterator
begin
(
);
/*!
ensures
- returns a random access iterator pointing to the first element in this
matrix.
- The iterator will iterate over the elements of the matrix in row major
order if layout is row_major_layout or in column major order if layout is
column_major_layout.
!*/
iterator
end
(
);
/*!
ensures
- returns a random access iterator pointing to one past the end of the last
element in this matrix.
!*/
const_iterator
begin
(
)
const
;
/*!
ensures
- returns a random access iterator pointing to the first element in this
matrix.
- The iterator will iterate over the elements of the matrix in row major
order if layout is row_major_layout or in column major order if layout is
column_major_layout.
!*/
const_iterator
end
(
)
const
;
/*!
ensures
- returns a random access iterator pointing to one past the end of the last
element in this matrix.
!*/
};
// ----------------------------------------------------------------------------------------
...
...
dlib/matrix/matrix_exp.h
View file @
ee4e7aea
...
...
@@ -52,6 +52,62 @@ namespace dlib
const
static
long
cost
=
EXP
::
cost
;
};
// ----------------------------------------------------------------------------------------
template
<
typename
EXP
>
class
matrix_exp
;
template
<
typename
EXP
>
class
matrix_exp_iterator
{
friend
class
matrix_exp
<
EXP
>
;
matrix_exp_iterator
(
const
EXP
&
m_
,
long
r_
,
long
c_
)
{
r
=
r_
;
c
=
c_
;
nc
=
m_
.
nc
();
m
=
&
m_
;
}
public
:
matrix_exp_iterator
()
:
r
(
0
),
c
(
0
),
nc
(
0
),
m
(
0
)
{}
typedef
typename
matrix_traits
<
EXP
>::
type
type
;
typedef
type
value_type
;
typedef
typename
matrix_traits
<
EXP
>::
const_ret_type
const_ret_type
;
bool
operator
==
(
const
matrix_exp_iterator
&
itr
)
const
{
return
r
==
itr
.
r
&&
c
==
itr
.
c
;
}
bool
operator
!=
(
const
matrix_exp_iterator
&
itr
)
const
{
return
!
(
*
this
==
itr
);
}
matrix_exp_iterator
&
operator
++
()
{
++
c
;
if
(
c
==
nc
)
{
c
=
0
;
++
r
;
}
return
*
this
;
}
matrix_exp_iterator
operator
++
(
int
)
{
matrix_exp_iterator
temp
(
*
this
);
++
(
*
this
);
return
temp
;
}
const_ret_type
operator
*
()
const
{
return
(
*
m
)(
r
,
c
);
}
private
:
long
r
,
c
;
long
nc
;
const
EXP
*
m
;
};
// ----------------------------------------------------------------------------------------
template
<
...
...
@@ -77,6 +133,8 @@ namespace dlib
typedef
matrix
<
type
,
NR
,
NC
,
mem_manager_type
,
layout_type
>
matrix_type
;
typedef
EXP
exp_type
;
typedef
matrix_exp_iterator
<
EXP
>
iterator
;
typedef
matrix_exp_iterator
<
EXP
>
const_iterator
;
inline
const_ret_type
operator
()
(
long
r
,
...
...
@@ -165,6 +223,9 @@ namespace dlib
return
temp
(
0
);
}
const_iterator
begin
()
const
{
return
matrix_exp_iterator
<
EXP
>
(
ref
(),
0
,
0
);
}
const_iterator
end
()
const
{
return
matrix_exp_iterator
<
EXP
>
(
ref
(),
nr
(),
0
);
}
protected
:
matrix_exp
()
{}
matrix_exp
(
const
matrix_exp
&
)
{}
...
...
dlib/matrix/matrix_exp_abstract.h
View file @
ee4e7aea
...
...
@@ -57,6 +57,8 @@ namespace dlib
const
static
long
NC
=
EXP
::
NC
;
typedef
matrix
<
type
,
NR
,
NC
,
mem_manager_type
,
layout_type
>
matrix_type
;
typedef
EXP
exp_type
;
typedef
matrix_exp_iterator
<
EXP
>
iterator
;
typedef
matrix_exp_iterator
<
EXP
>
const_iterator
;
const_ret_type
operator
()
(
long
r
,
...
...
@@ -167,6 +169,27 @@ namespace dlib
(i.e. returns *static_cast<const exp_type*>(this) )
!*/
const_iterator
begin
(
)
const
;
/*!
ensures
- returns a forward access iterator pointing to the first element in this
matrix expression.
- Since matrix_exp objects represent immutable views of a matrix, the
returned iterator does not allow the user to modify the matrix
expression's elements.
- The iterator will iterate over the elements of the matrix in row major
order.
!*/
const_iterator
end
(
)
const
;
/*!
ensures
- returns a forward access iterator pointing to one past the end of the
last element in this matrix expression.
!*/
protected
:
// Only derived classes of matrix_exp may call the matrix_exp constructors.
...
...
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