Made a tensor iterable

This commit is contained in:
Davis King 2015-11-09 17:56:25 -05:00
parent 00e18a8d59
commit 9cbbe7b75b
2 changed files with 18 additions and 0 deletions

View File

@ -35,6 +35,13 @@ namespace dlib
long nc() const { return m_nc; } long nc() const { return m_nc; }
size_t size() const { return data.size(); } size_t size() const { return data.size(); }
typedef float* iterator;
typedef const float* const_iterator;
iterator begin() { return host(); }
const_iterator begin() const { return host(); }
iterator end() { return host()+size(); }
const_iterator end() const { return host()+size(); }
void async_copy_to_device() const void async_copy_to_device() const
{ {
data.async_copy_to_device(); data.async_copy_to_device();

View File

@ -98,6 +98,17 @@ namespace dlib
async_copy_to_device() and then immediately call device(). async_copy_to_device() and then immediately call device().
!*/ !*/
typedef float* iterator;
typedef const float* const_iterator;
iterator begin() { return host(); }
const_iterator begin() const { return host(); }
iterator end() { return host()+size(); }
const_iterator end() const { return host()+size(); }
/*!
ensures
- makes a tensor iterable just like the STL containers.
!*/
const float* host( const float* host(
) const; ) const;
/*! /*!