CUV  0.9.201304091348
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | List of all members
cuv::tensor_view< V, M, L > Class Template Reference

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

#include <tensor.hpp>

Inheritance diagram for cuv::tensor_view< V, M, L >:
Inheritance graph
[legend]
Collaboration diagram for cuv::tensor_view< V, M, L >:
Collaboration graph
[legend]

Public Member Functions

 tensor_view ()
 default constructor does nothing
tensor_viewoperator= (const tensor< V, M, L > &o)
 /always/ try to copy memory
tensor_viewoperator= (const tensor_view< V, M, L > &o)
 /always/ try to copy memory
template<class _V >
boost::enable_if_c
< boost::is_convertible< _V, V >
::value, tensor_view & >::type 
operator= (const _V &scalar)
 assign from value (sets all elements equal to one scalar)
template<class OM >
tensor_viewoperator= (const tensor< V, OM, L > &o)
 assignment operator for other memory space type
template<class OM >
tensor_viewoperator= (const tensor_view< V, OM, L > &o)
 assignment operator for views in other memory space types
template<int D, int E>
 tensor_view (const tensor< V, M, L > &o, const index_gen< D, E > &idx)
 construct tensor_view
template<int D, int E>
 tensor_view (const index_gen< D, E > &idx, const tensor< V, M, L > &o)
 different order of arguments as above, all else being equal.
- Public Member Functions inherited from cuv::tensor< V, M, L >
template<std::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 >
tensor copy (T tag=linear_memory_tag()) const
 copy memory using given allocator tag (linear/pitched)
tensor copy () const
 copy memory using linear memory
template<int D, int E>
tensor_view< V, M, L > operator[] (const index_gen< D, E > &idx) const
 create a subtensor of the current tensor.
template<std::size_t D>
void reshape (const extent_gen< D > &eg)
 reshape the tensor (in place)
void reshape (const std::vector< size_type > &shape)
 reshape the tensor (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 tensor (deallocates memory if product changes, otherwise equivalent to reshape)
template<std::size_t D>
void resize (const extent_gen< D > &eg)
 resize the tensor (deallocates memory if product changes, otherwise equivalent to reshape)
void dealloc ()
 force deallocation of memory if possible
index_type ndim () const
 return the number of dimensions
size_type shape (const index_type &i) const
 return the size of the i-th dimension
index_type stride (const index_type &i) const
 return the stride of the i-th dimension
pointer_type ptr ()
const_pointer_type 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 tensor (as a vector for backward compatibility)
std::vector< size_typeeffective_shape () const
 return the effective shape of the tensor (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)
 scalar referecne 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)
 tensor ()
 default constructor (does nothing)
 tensor (const tensor &o)
 construct tensor from tensor of exact same type
template<class OM >
 tensor (const tensor< value_type, OM, L > &o)
 construct tensor from tensor of other memory space in (dense) /linear/ memory.
 tensor (const tensor &o, pitched_memory_tag)
 construct tensor from tensor of same memory space in /pitched/ memory.
template<class OM >
 tensor (const tensor< value_type, OM, L > &o, pitched_memory_tag)
 construct tensor from tensor of other memory space in /pitched/ memory.
 tensor (const tensor &o, linear_memory_tag)
 construct tensor from tensor of same memory space in (dense) /linear/ memory.
template<class OM >
 tensor (const tensor< value_type, OM, L > &o, linear_memory_tag)
 construct tensor from tensor of other memory space in (dense) /linear/ memory.
template<class OL >
 tensor (const tensor< value_type, M, OL > &o)
 construct tensor from other memory layout
 tensor (const size_type i)
 construct one-dimensional tensor
 tensor (const size_type i, const int j)
 construct two-dimensional tensor
template<std::size_t D>
 tensor (const extent_gen< D > &eg)
 construct tensor from a shape
 tensor (const std::vector< size_type > &eg)
 construct tensor from a shape
 tensor (const std::vector< size_type > &eg, pitched_memory_tag)
 construct tensor from a shape
template<std::size_t D>
 tensor (const extent_gen< D > &eg, pitched_memory_tag)
 construct tensor from a shape (pitched)
template<std::size_t D>
 tensor (const extent_gen< D > &eg, value_type *ptr)
 construct tensor from a shape and a pointer (does not copy memory)
 tensor (const std::vector< size_type > &shape, value_type *ptr)
template<int D, int E>
 tensor (const index_gen< D, E > &idx, value_type *ptr)
 construct tensor from a shape and a pointer (does not copy memory)
template<class _M , class _L >
tensorassign (const tensor< V, _M, _L > &o)
 explicitly assign by copying memory
template<class OM >
tensoroperator= (const tensor< value_type, OM, L > &o)
 assign from tensor of different memory space type.
template<class OL >
tensoroperator= (const tensor< value_type, M, OL > &o)
 assign from tensor of different memory layout type.

Additional Inherited Members

- Public Types inherited from cuv::tensor< 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 memory_type::pointer_type pointer_type
 type of data pointers
typedef
memory_type::const_pointer_type 
const_pointer_type
 type of const data pointers
typedef L memory_layout_type
 column/row major
typedef tensor_info< M, L > info_type
 type of shape info struct
typedef tensor_view< V, M, L > view_type
 type of views on this tensor
- Protected Member Functions inherited from cuv::tensor< V, M, L >
size_type index_of (int D, index_type *arr) const
 determine linear index in memory of an index array
void allocate (tensor &t, linear_memory_tag)
 allocate linear memory (c-contiguous version)
void allocate (tensor &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::tensor< 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::tensor_view< V, M, L >

primarily used as result of tensor::operator[]

Definition at line 1721 of file tensor.hpp.

Constructor & Destructor Documentation

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

construct tensor_view

Warning
if a dimension has size 1, the resulting tensor has fewer dimensions than the original one.
most operations in CUV on tensors currently only work if the subtensor 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 subtensor
othe original tensor

Example:

tensor<float,host_memory_space> v(extents[5][10]);
// these are equivalent:
tensor_view<float,host_memory_space> w0(v,indices[index_range(2,3)][index_range(0,10)]);
tensor_view<float,host_memory_space> w0(v,indices[index_range(2,3)][index_range()]);
tensor_view<float,host_memory_space> w0(v,indices[index_range(2,3)]);
tensor_view<float,host_memory_space> w0(v,indices[index_range(2,3)][index_range() < index(10)]);
tensor_view<float,host_memory_space> w0(v,indices[index_range(2,3)][index(0) < index_range() < index(10)]);
// In the previous example, all parameters to indices above are *ranges*.
// This causes the number of dimensions to stay the same in the view and the tensor.
// You can also provide a 'degenerate' range, which removes the respective dimension.
// These yields a 1D-tensor corresponding to the 2nd slice in the 1st dimension:
tensor<float,host_memory_space> w0(v, indices[1][index_range()]);
tensor<float,host_memory_space> w0(v, indices[1]);

Definition at line 1817 of file tensor.hpp.

template<class V, class M, class L = row_major>
template<int D, int E>
cuv::tensor_view< V, M, L >::tensor_view ( const index_gen< D, E > &  idx,
const tensor< 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 tensor

Definition at line 1862 of file tensor.hpp.

Member Function Documentation

template<class V, class M, class L = row_major>
template<class _V >
boost::enable_if_c<boost::is_convertible<_V,V>::value, tensor_view&>::type cuv::tensor_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::tensor< V, M, L >.

Definition at line 1756 of file tensor.hpp.

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

assignment operator for other memory space type

Parameters
oa tensor of another memory space type

Definition at line 1766 of file tensor.hpp.

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

assignment operator for views in other memory space types

Parameters
oa tensor_view of another memory space type

Definition at line 1778 of file tensor.hpp.


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