PLearn 0.1
Public Member Functions | Private Attributes
PLearn::TTensorSubTensorIterator< T > Class Template Reference

#include <Tensor.h>

Collaboration diagram for PLearn::TTensorSubTensorIterator< T >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 TTensorSubTensorIterator (TTensor< T > *tensor_, const IVec &dim)
 TTensorSubTensorIterator ()
IVec position () const
TTensorSubTensorIterator< T > & operator++ ()
TTensor< T > operator* () const
bool end () const

Private Attributes

TTensor< T > * tensor
IVec position_
IVec dimensions_
bool end_met

Detailed Description

template<class T>
class PLearn::TTensorSubTensorIterator< T >

Definition at line 114 of file Tensor.h.


Constructor & Destructor Documentation

template<class T>
PLearn::TTensorSubTensorIterator< T >::TTensorSubTensorIterator ( TTensor< T > *  tensor_,
const IVec dim 
) [inline]

Definition at line 126 of file Tensor.h.

References i.

        :tensor(tensor_),dimensions_(dim),end_met(false)
    {
        position_=IVec((unsigned)tensor->ndims(),0);
        for(int i=0;i<tensor->ndims();i++)
            if(dimensions_[i]!=0)
                position_[i]=-1;
    }
template<class T>
PLearn::TTensorSubTensorIterator< T >::TTensorSubTensorIterator ( ) [inline]

Definition at line 135 of file Tensor.h.

        :tensor(NULL),end_met(false){}

Member Function Documentation

template<class T>
bool PLearn::TTensorSubTensorIterator< T >::end ( ) const [inline]

Definition at line 161 of file Tensor.h.

{return end_met;}
template<class T>
TTensor<T> PLearn::TTensorSubTensorIterator< T >::operator* ( ) const [inline]

Definition at line 142 of file Tensor.h.

References i.

    {
        IVec from(tensor->ndims()),length(tensor->ndims());
        for(int i=0;i<tensor->ndims();i++)
        {
            if(position_[i]==-1)
            {
                from[i]=0;
                length[i]=tensor->width_[i];
            }
            else
            {
                from[i]=position_[i];
                length[i]=1;
            }
        }
        return tensor->subTensor(from,length);
    }
template<class T >
TTensorSubTensorIterator< T > & PLearn::TTensorSubTensorIterator< T >::operator++ ( ) [inline]

Definition at line 440 of file Tensor.h.

References i.

{
    bool found=false;
    int idx=-1;
    // find the lowest index of the position vector we can increment
    while(!found && idx<(signed int)(tensor->ndims()-1))
    {
        idx++;
        found = position_[idx]!=-1 && position_[idx]<tensor->width_[idx]-1;
    }
    if(found)
    {
        position_[idx]++;
        for(int i=0;i<idx;i++)
            if(position_[i]!=-1)
                position_[i]=0;
    }
    else 
        // all subTensors of the tensor have been visited           
        end_met=true;
    
    return *this;
}
template<class T>
IVec PLearn::TTensorSubTensorIterator< T >::position ( ) const [inline]

Definition at line 138 of file Tensor.h.

{return position_;}

Member Data Documentation

template<class T>
IVec PLearn::TTensorSubTensorIterator< T >::dimensions_ [private]

Definition at line 120 of file Tensor.h.

template<class T>
bool PLearn::TTensorSubTensorIterator< T >::end_met [private]

Definition at line 122 of file Tensor.h.

template<class T>
IVec PLearn::TTensorSubTensorIterator< T >::position_ [private]

Definition at line 119 of file Tensor.h.

template<class T>
TTensor<T>* PLearn::TTensorSubTensorIterator< T >::tensor [private]

Definition at line 118 of file Tensor.h.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines