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
f0dff5fc
Commit
f0dff5fc
authored
Aug 27, 2016
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added alias_tensor_const_instance
parent
7c6a800b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
2 deletions
+65
-2
tensor.h
dlib/dnn/tensor.h
+29
-0
tensor_abstract.h
dlib/dnn/tensor_abstract.h
+35
-1
dnn.cpp
dlib/test/dnn.cpp
+1
-1
No files found.
dlib/dnn/tensor.h
View file @
f0dff5fc
...
...
@@ -478,6 +478,7 @@ namespace dlib
return
sum
;
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
class
alias_tensor_instance
:
public
tensor
...
...
@@ -487,6 +488,7 @@ namespace dlib
public
:
friend
class
alias_tensor
;
friend
class
alias_tensor_const_instance
;
alias_tensor_instance
&
operator
=
(
float
val
)
{
...
...
@@ -529,6 +531,23 @@ namespace dlib
virtual
const
gpu_data
&
data
()
const
{
return
*
data_instance
;
}
};
// ----------------------------------------------------------------------------------------
class
alias_tensor_const_instance
{
public
:
const
tensor
&
get
()
const
{
return
inst
;
}
operator
const
tensor
&
()
{
return
inst
;
}
private
:
alias_tensor_instance
inst
;
friend
class
alias_tensor
;
alias_tensor_const_instance
()
{}
};
// ----------------------------------------------------------------------------------------
class
alias_tensor
{
public
:
...
...
@@ -586,6 +605,16 @@ namespace dlib
return
inst
;
}
alias_tensor_const_instance
operator
()
(
const
tensor
&
t
,
size_t
offset
)
{
alias_tensor_const_instance
temp
;
temp
.
inst
=
(
*
this
)(
const_cast
<
tensor
&>
(
t
),
offset
);
return
temp
;
}
private
:
alias_tensor_instance
inst
;
};
...
...
dlib/dnn/tensor_abstract.h
View file @
f0dff5fc
...
...
@@ -575,6 +575,28 @@ namespace dlib
);
};
class
alias_tensor_const_instance
{
/*!
WHAT THIS OBJECT REPRESENTS
This is essentially a const version of alias_tensor_instance and therefore
represents a tensor. However, due to the mechanics of C++, this object
can't inherit from tensor. So instead it provides a get() and an implicit
conversion to const tensor.
!*/
public
:
// Methods that cast the alias to a tensor.
const
tensor
&
get
()
const
;
operator
const
tensor
&
();
private
:
// You can't default initialize this object. You can only get instances of it from
// alias_tensor::operator().
alias_tensor_const_instance
();
};
class
alias_tensor
{
/*!
...
...
@@ -629,7 +651,7 @@ namespace dlib
requires
- offset+size() <= t.size()
ensures
- Return a tensor that simply aliases the elements of t beginning with t's
- Return
s
a tensor that simply aliases the elements of t beginning with t's
offset'th element. Specifically, this function returns an aliasing
tensor T such that:
- T.size() == size()
...
...
@@ -641,6 +663,18 @@ namespace dlib
- T.device() == t.device()+offset
- &T.annotation() == &t.annotation()
!*/
alias_tensor_const_instance
operator
()
(
const
tensor
&
t
,
size_t
offset
);
/*!
requires
- offset+size() <= t.size()
ensures
- This function is identical to the above version of operator() except that
it takes and returns const tensors instead of non-const tensors.
!*/
};
void
serialize
(
const
alias_tensor
&
item
,
std
::
ostream
&
out
);
...
...
dlib/test/dnn.cpp
View file @
f0dff5fc
...
...
@@ -387,7 +387,7 @@ namespace
alias_tensor
at
(
2
,
2
);
auto
A0
=
at
(
A
,
0
);
auto
A4
=
at
(
A
,
4
);
auto
A8
=
at
(
A
,
8
);
auto
A8
=
at
(
const_cast
<
const
resizable_tensor
&>
(
A
)
,
8
);
DLIB_TEST
(
mat
(
A0
)
==
truth1
);
DLIB_TEST
(
mat
(
at
(
A
,
4
))
==
truth2
);
DLIB_TEST
(
mat
(
A8
)
==
truth3
);
...
...
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