curfil  ..
 All Classes Functions Variables Typedefs Friends Groups Pages
Public Member Functions | Friends | List of all members
cuv::ndarray_view< V, M, L > Class Template Reference

primarily used as result of ndarray::operator[] More...

#include <ndarray.hpp>

Inheritance diagram for cuv::ndarray_view< V, M, L >:
cuv::ndarray< V, M, L >

Public Member Functions

 ndarray_view (const boost::shared_ptr< allocator > &allocator)
 default constructor does nothing
ndarray_viewassign (const ndarray< V, M, L > &o, cudaStream_t stream=0)
 /always/ try to copy memory
ndarray_viewassign (const ndarray_view< V, M, L > &o, cudaStream_t stream=0)
 /always/ try to copy memory
template<class OM >
ndarray_viewassign (const ndarray< V, OM, L > &o, cudaStream_t stream=0)
 assignment operator for other memory space type
template<class OM >
ndarray_viewassign (const ndarray_view< V, OM, L > &o, cudaStream_t stream=0)
 assignment operator for views in other memory space types
ndarray_viewoperator= (const ndarray< V, M, L > &o)
 /always/ try to copy memory
ndarray_viewoperator= (const ndarray_view< V, M, L > &o)
 /always/ try to copy memory
template<class _V >
boost::enable_if_c
< boost::is_convertible< _V, V >
::value, ndarray_view & >
::type 
operator= (const _V &scalar)
 assign from value (sets all elements equal to one scalar)
template<class OM >
ndarray_viewoperator= (const ndarray< V, OM, L > &o)
 assignment operator for other memory space type
template<class OM >
ndarray_viewoperator= (const ndarray_view< V, OM, L > &o)
 assignment operator for views in other memory space types
template<int D, int E>
 ndarray_view (const ndarray< V, M, L > &o, const index_gen< D, E > &idx)
 construct ndarray_view
template<int D, int E>
 ndarray_view (const index_gen< D, E > &idx, const ndarray< V, M, L > &o)
 different order of arguments as above, all else being equal.
- Public Member Functions inherited from cuv::ndarray< V, M, L >
template<size_t D>
size_type index_of (const extent_gen< D > &eg) const
 determine linear index in memory of an index array
template<class T >
ndarray copy (T tag=linear_memory_tag(), cudaStream_t stream=0) const
 copy memory using given allocator tag (linear/pitched)
ndarray copy () const
 copy memory using linear memory
template<int D, int E>
ndarray_view< V, M, L > operator[] (const index_gen< D, E > &idx) const
 create a sub-ndarray of the current ndarray
template<size_t D>
void reshape (const extent_gen< D > &eg)
 reshape the ndarray (in place)
void reshape (const std::vector< size_type > &shape)
 reshape the ndarray (in place)
void reshape (size_type r, size_type c)
 convenience wrapper for reshape(extents[r][c])
void resize (const std::vector< size_type > &shape)
 resize the ndarray (deallocates memory if product changes, otherwise equivalent to reshape)
template<size_t D>
void resize (const extent_gen< D > &eg)
 resize the ndarray (deallocates memory if product changes, otherwise equivalent to reshape)
void resize (size_type size)
 convenience wrapper for resize(extents[size])
void resize (size_type r, size_type c)
 convenience wrapper for resize(extents[r][c])
void dealloc ()
 force deallocation of memory if possible
template<class OM , class OL >
bool copy_memory (const ndarray< V, OM, OL > &src, bool force_dst_contiguous, cudaStream_t stream)
 tries to copy memory, succeeds if shapes match AND both ndarrays are c_contiguous or 2d-copyable.
template<class OM , class OL >
void copy_memory (const ndarray< V, OM, OL > &src, linear_memory_tag, cudaStream_t stream)
 copies between different memory spaces
template<class OM , class OL >
void copy_memory (const ndarray< V, OM, OL > &src, pitched_memory_tag, cudaStream_t stream)
 copies between different memory spaces
index_type ndim () const
 return the number of dimensions
size_type shape (const size_t i) const
 return the size of the i-th dimension
index_type stride (const size_t i) const
 return the stride of the i-th dimension
V * ptr ()
const V * ptr () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void set_ptr_offset (long int i)
 set the pointer offset (used in deserialization)
boost::shared_ptr< memory_type > & mem ()
const boost::shared_ptr
< memory_type > & 
mem () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
size_type size () const
size_type memsize () const
 determine size in bytes
std::vector< size_typeshape () const
 return the shape of the ndarray (as a vector for backward compatibility)
std::vector< size_typeeffective_shape () const
 return the effective shape of the ndarray (as a vector for backward compatibility)
const info_typeinfo () const
info_typeinfo ()
bool is_c_contiguous () const
 true iff there are no "holes" in memory
bool is_2dcopyable () const
 true iff it can be copied as a 2d array (only one dimension is pitched)
reference_type operator[] (index_type idx)
 member access: "flat" access as if memory was linear
const_reference_type operator[] (index_type idx) const
reference_type operator() (index_type i0)
 get a reference to the datum at an index
const_reference_type operator() (index_type i0) const
const_reference_type operator() (index_type i0, index_type i1) const
reference_type operator() (index_type i0, index_type i1)
const_reference_type operator() (index_type i0, index_type i1, index_type i2) const
reference_type operator() (index_type i0, index_type i1, index_type i2)
const_reference_type operator() (index_type i0, index_type i1, index_type i2, index_type i3) const
reference_type operator() (index_type i0, index_type i1, index_type i2, index_type i3)
const_reference_type operator() (index_type i0, index_type i1, index_type i2, index_type i3, index_type i4) const
reference_type operator() (index_type i0, index_type i1, index_type i2, index_type i3, index_type i4)
 ndarray (const boost::shared_ptr< allocator > _allocator=boost::make_shared< default_allocator >())
 default constructor (does nothing)
 ndarray (const ndarray &o)
 construct ndarray from ndarray of exact same type
template<class OM >
 ndarray (const ndarray< value_type, OM, L > &o, cudaStream_t stream=0)
 construct ndarray from ndarray of other memory space in (dense) /linear/ memory.
 ndarray (const ndarray &o, pitched_memory_tag, cudaStream_t stream=0)
 construct ndarray from ndarray of same memory space in /pitched/ memory.
template<class OM >
 ndarray (const ndarray< value_type, OM, L > &o, pitched_memory_tag, cudaStream_t stream=0)
 construct ndarray from ndarray of other memory space in /pitched/ memory.
 ndarray (const ndarray &o, linear_memory_tag, cudaStream_t stream=0)
 construct ndarray from ndarray of same memory space in (dense) /linear/ memory.
template<class OM >
 ndarray (const ndarray< value_type, OM, L > &o, linear_memory_tag, cudaStream_t stream=0)
 construct ndarray from ndarray of other memory space in (dense) /linear/ memory.
template<class OL >
 ndarray (const ndarray< value_type, M, OL > &o)
 construct ndarray from other memory layout
 ndarray (const size_type i, const boost::shared_ptr< allocator > _allocator=boost::make_shared< default_allocator >())
 construct one-dimensional ndarray
 ndarray (const size_type i, const int j, const boost::shared_ptr< allocator > _allocator=boost::make_shared< default_allocator >())
 construct two-dimensional ndarray
template<size_t D>
 ndarray (const extent_gen< D > &eg, const boost::shared_ptr< allocator > _allocator=boost::make_shared< default_allocator >())
 construct ndarray from a shape
 ndarray (const std::vector< size_type > &eg, const boost::shared_ptr< allocator > _allocator=boost::make_shared< default_allocator >())
 construct ndarray from a shape
 ndarray (const std::vector< size_type > &eg, pitched_memory_tag, const boost::shared_ptr< allocator > _allocator=boost::make_shared< default_allocator >())
 construct ndarray from a shape
template<size_t D>
 ndarray (const extent_gen< D > &eg, pitched_memory_tag, const boost::shared_ptr< allocator > _allocator=boost::make_shared< default_allocator >())
 construct ndarray from a shape (pitched)
template<size_t D>
 ndarray (const extent_gen< D > &eg, value_type *ptr, const boost::shared_ptr< allocator > _allocator=boost::make_shared< default_allocator >())
 construct ndarray from a shape and a pointer (does not copy memory)
 ndarray (const std::vector< size_type > &shape, value_type *ptr, const boost::shared_ptr< allocator > _allocator=boost::make_shared< default_allocator >())
template<int D, int E>
 ndarray (const index_gen< D, E > &idx, value_type *ptr, const boost::shared_ptr< allocator > _allocator=boost::make_shared< default_allocator >())
 construct ndarray from a shape and a pointer (does not copy memory)
template<class _M , class _L >
ndarrayassign (const ndarray< V, _M, _L > &o, cudaStream_t stream=0)
 explicitly assign by copying memory
template<class OM >
ndarrayassign (const ndarray< value_type, OM, L > &o, cudaStream_t stream=0)
 assign from ndarray of different memory space type.
template<class OM >
ndarrayoperator= (const ndarray< value_type, OM, L > &o)
 assign from ndarray of different memory space type.
template<class OL >
ndarrayoperator= (const ndarray< value_type, M, OL > &o)
 assign from ndarray of different memory layout type.

Friends

class ndarray

Additional Inherited Members

- Public Types inherited from cuv::ndarray< V, M, L >
typedef memory< V, M > memory_type
 type of stored memory
typedef memory_type::reference_type reference_type
 values returned by operator() and []
typedef
memory_type::const_reference_type 
const_reference_type
 values returned by operator()
typedef
memory_type::memory_space_type 
memory_space_type
 dev/host
typedef memory_type::value_type value_type
 type of stored values
typedef memory_type::size_type size_type
 type shapes
typedef memory_type::index_type index_type
 type strides
typedef L memory_layout_type
 column/row major
typedef ndarray_info< M, L > info_type
 type of shape info struct
typedef ndarray_view< V, M, L > view_type
 type of views on this ndarray
- Public Attributes inherited from cuv::ndarray< V, M, L >
boost::shared_ptr< allocatorm_allocator
- Protected Member Functions inherited from cuv::ndarray< V, M, L >
size_type index_of (int D, index_type *arr) const
 determine linear index in memory of an index array
void allocate (ndarray &t, linear_memory_tag)
 allocate linear memory (c-contiguous version)
void allocate (ndarray &t, pitched_memory_tag)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. pitched version.
- Protected Attributes inherited from cuv::ndarray< V, M, L >
info_type m_info
 information about shape, strides
boost::shared_ptr< memory_typem_memory
 points to (possibly shared) memory
V * m_ptr
 points to start of actually referenced memory (within m_memory)

Detailed Description

template<class V, class M, class L = row_major>
class cuv::ndarray_view< V, M, L >

primarily used as result of ndarray::operator[]

Definition at line 1243 of file ndarray.hpp.

Constructor & Destructor Documentation

template<class V, class M, class L = row_major>
template<int D, int E>
cuv::ndarray_view< V, M, L >::ndarray_view ( const ndarray< V, M, L > &  o,
const index_gen< D, E > &  idx 
)
inlineexplicit

construct ndarray_view

Warning
if a dimension has size 1, the resulting ndarray has fewer dimensions than the original one.
most operations in CUV on ndarrays currently only work if the sub-ndarray is a connected area in memory. Basically this means that you can only slice in the first dimension which has size>1.
Parameters
idxthe indices of the sub-ndarray
othe original ndarray

Example:

ndarray<float,host_memory_space> v(extents[5][10]);
// these are equivalent:
ndarray<float,host_memory_space> w0(v,indices[index_range(2,3)][index_range(0,10)]);
ndarray<float,host_memory_space> w0(v,indices[index_range(2,3)][index_range()]);
ndarray<float,host_memory_space> w0(v,indices[index_range(2,3)][index_range() < index(10)]);
ndarray<float,host_memory_space> w0(v,indices[index_range(2,3)][index(0) < index_range() < index(10)]);
// yields a 1D-ndarray corresponding to the 2nd slice in the 1st dimension:
ndarray<float,host_memory_space> w0(indices[1][index_range()]);

Definition at line 1377 of file ndarray.hpp.

template<class V, class M, class L = row_major>
template<int D, int E>
cuv::ndarray_view< V, M, L >::ndarray_view ( const index_gen< D, E > &  idx,
const ndarray< V, M, L > &  o 
)
inlineexplicit

different order of arguments as above, all else being equal.

Deprecated:
Parameters
idxa set of index ranges into o
oother ndarray

Definition at line 1420 of file ndarray.hpp.

Member Function Documentation

template<class V, class M, class L = row_major>
template<class OM >
ndarray_view& cuv::ndarray_view< V, M, L >::assign ( const ndarray< V, OM, L > &  o,
cudaStream_t  stream = 0 
)
inline

assignment operator for other memory space type

Parameters
oa ndarray of another memory space type

Definition at line 1285 of file ndarray.hpp.

template<class V, class M, class L = row_major>
template<class OM >
ndarray_view& cuv::ndarray_view< V, M, L >::assign ( const ndarray_view< V, OM, L > &  o,
cudaStream_t  stream = 0 
)
inline

assignment operator for views in other memory space types

Parameters
oa ndarray_view of another memory space type

Definition at line 1297 of file ndarray.hpp.

template<class V, class M, class L = row_major>
template<class _V >
boost::enable_if_c<boost::is_convertible<_V, V>::value, ndarray_view&>::type cuv::ndarray_view< V, M, L >::operator= ( const _V &  scalar)
inline

assign from value (sets all elements equal to one scalar)

Parameters
scalarvalue which should be assigned to all elements

Reimplemented from cuv::ndarray< V, M, L >.

Definition at line 1323 of file ndarray.hpp.

template<class V, class M, class L = row_major>
template<class OM >
ndarray_view& cuv::ndarray_view< V, M, L >::operator= ( const ndarray< V, OM, L > &  o)
inline

assignment operator for other memory space type

Parameters
oa ndarray of another memory space type

Definition at line 1335 of file ndarray.hpp.

template<class V, class M, class L = row_major>
template<class OM >
ndarray_view& cuv::ndarray_view< V, M, L >::operator= ( const ndarray_view< V, OM, L > &  o)
inline

assignment operator for views in other memory space types

Parameters
oa ndarray_view of another memory space type

Definition at line 1345 of file ndarray.hpp.


The documentation for this class was generated from the following file: