PLearn 0.1
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Types
PLearn::VarArrayElementVariable Class Reference

Variable that is the element of the input1 VarArray indexed by the input2 variable. More...

#include <VarArrayElementVariable.h>

Inheritance diagram for PLearn::VarArrayElementVariable:
Inheritance graph
[legend]
Collaboration diagram for PLearn::VarArrayElementVariable:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 VarArrayElementVariable ()
 protected default constructor for persistence
 VarArrayElementVariable (VarArray &input1, const Var &input2)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual VarArrayElementVariabledeepCopy (CopiesMap &copies) const
virtual void build ()
 Post-constructor.
virtual void recomputeSize (int &l, int &w) const
 Recomputes the length l and width w that this variable should have, according to its parent variables.
virtual void fprop ()
 compute output given input
virtual void bprop ()
virtual void symbolicBprop ()
 compute a piece of new Var graph that represents the symbolic derivative of this Var

Static Public Member Functions

static string _classname_ ()
 VarArrayElementVariable.
static OptionList_getOptionList_ ()
static RemoteMethodMap_getRemoteMethodMap_ ()
static Object_new_instance_for_typemap_ ()
static bool _isa_ (const Object *o)
static void _static_initialize_ ()
static const PPathdeclaringFile ()

Static Public Attributes

static StaticInitializer _static_initializer_

Protected Member Functions

void build_ ()
 Object-specific post-constructor.

Private Types

typedef NaryVariable inherited

Detailed Description

Variable that is the element of the input1 VarArray indexed by the input2 variable.

Definition at line 55 of file VarArrayElementVariable.h.


Member Typedef Documentation

Reimplemented from PLearn::NaryVariable.

Definition at line 57 of file VarArrayElementVariable.h.


Constructor & Destructor Documentation

PLearn::VarArrayElementVariable::VarArrayElementVariable ( ) [inline]

protected default constructor for persistence

Definition at line 61 of file VarArrayElementVariable.h.

{}
PLearn::VarArrayElementVariable::VarArrayElementVariable ( VarArray input1,
const Var input2 
)

Definition at line 57 of file VarArrayElementVariable.cc.

References build_().

    : inherited(input1 & (VarArray)input2, input1[0]->length(), input1[0]->width())
{
    build_();
}

Here is the call graph for this function:


Member Function Documentation

string PLearn::VarArrayElementVariable::_classname_ ( ) [static]

VarArrayElementVariable.

Reimplemented from PLearn::NaryVariable.

Definition at line 54 of file VarArrayElementVariable.cc.

OptionList & PLearn::VarArrayElementVariable::_getOptionList_ ( ) [static]

Reimplemented from PLearn::NaryVariable.

Definition at line 54 of file VarArrayElementVariable.cc.

RemoteMethodMap & PLearn::VarArrayElementVariable::_getRemoteMethodMap_ ( ) [static]

Reimplemented from PLearn::NaryVariable.

Definition at line 54 of file VarArrayElementVariable.cc.

bool PLearn::VarArrayElementVariable::_isa_ ( const Object o) [static]

Reimplemented from PLearn::NaryVariable.

Definition at line 54 of file VarArrayElementVariable.cc.

Object * PLearn::VarArrayElementVariable::_new_instance_for_typemap_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 54 of file VarArrayElementVariable.cc.

StaticInitializer VarArrayElementVariable::_static_initializer_ & PLearn::VarArrayElementVariable::_static_initialize_ ( ) [static]

Reimplemented from PLearn::NaryVariable.

Definition at line 54 of file VarArrayElementVariable.cc.

void PLearn::VarArrayElementVariable::bprop ( ) [virtual]

Implements PLearn::Variable.

Definition at line 107 of file VarArrayElementVariable.cc.

References PLearn::Variable::gradientdata, i, PLearn::TVec< T >::last(), PLearn::Variable::nelems(), and PLearn::NaryVariable::varray.

{
    int index = (int)(varray.last()->valuedata[0]);
    for (int i=0;i<nelems();i++)
        varray[index]->gradientdata[i] += gradientdata[i];
}

Here is the call graph for this function:

void PLearn::VarArrayElementVariable::build ( ) [virtual]

Post-constructor.

The normal implementation should call simply inherited::build(), then this class's build_(). This method should be callable again at later times, after modifying some option fields to change the "architecture" of the object.

Reimplemented from PLearn::NaryVariable.

Definition at line 64 of file VarArrayElementVariable.cc.

References PLearn::NaryVariable::build(), and build_().

Here is the call graph for this function:

void PLearn::VarArrayElementVariable::build_ ( ) [protected]

Object-specific post-constructor.

This method should be redefined in subclasses and do the actual building of the object according to previously set option fields. Constructors can just set option fields, and then call build_. This method is NOT virtual, and will typically be called only from three places: a constructor, the public virtual build() method, and possibly the public virtual read method (which calls its parent's read). build_() can assume that its parent's build_() has already been called.

Reimplemented from PLearn::NaryVariable.

Definition at line 71 of file VarArrayElementVariable.cc.

References i, PLearn::Variable::length(), PLearn::TVec< T >::length(), PLERROR, PLearn::TVec< T >::size(), PLearn::NaryVariable::varray, and w.

Referenced by build(), and VarArrayElementVariable().

{
    if (varray.size() >= 2) {// && varray[0] && varray[1] && varray[1].size()) {
        int l = varray[0]->length();
        int w = varray[0]->width();
        for (int i = 1; i < varray.size() - 1; i++)
            if (varray[i]->length() != l || varray[i]->width() != w)
                PLERROR("VarArrayElementVairables expect all the elements of input1 array to have the same size");
        if (!varray[varray.size() - 1]->isScalar())
            PLERROR("VarArrayElementVariable expect an index Var (input2) of length 1");
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

string PLearn::VarArrayElementVariable::classname ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 54 of file VarArrayElementVariable.cc.

static const PPath& PLearn::VarArrayElementVariable::declaringFile ( ) [inline, static]

Reimplemented from PLearn::NaryVariable.

Definition at line 64 of file VarArrayElementVariable.h.

:
    void build_();
VarArrayElementVariable * PLearn::VarArrayElementVariable::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::NaryVariable.

Definition at line 54 of file VarArrayElementVariable.cc.

void PLearn::VarArrayElementVariable::fprop ( ) [virtual]

compute output given input

Implements PLearn::Variable.

Definition at line 94 of file VarArrayElementVariable.cc.

References i, PLearn::TVec< T >::last(), PLearn::Variable::nelems(), PLERROR, PLearn::TVec< T >::size(), PLearn::Variable::valuedata, and PLearn::NaryVariable::varray.

{
    int index = (int)(varray.last()->valuedata[0]);
#ifdef BOUNDCHECK
    if (index<0 || index>=varray.size()-1)
        PLERROR("VarArrayElementVariable::fprop, out of bound access of array(%d) at %d",
                varray.size()-1,index);
#endif
    for (int i=0;i<nelems();i++)
        valuedata[i] = varray[index]->valuedata[i];
}

Here is the call graph for this function:

OptionList & PLearn::VarArrayElementVariable::getOptionList ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 54 of file VarArrayElementVariable.cc.

OptionMap & PLearn::VarArrayElementVariable::getOptionMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 54 of file VarArrayElementVariable.cc.

RemoteMethodMap & PLearn::VarArrayElementVariable::getRemoteMethodMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 54 of file VarArrayElementVariable.cc.

void PLearn::VarArrayElementVariable::recomputeSize ( int l,
int w 
) const [virtual]

Recomputes the length l and width w that this variable should have, according to its parent variables.

This is used for ex. by sizeprop() The default version stupidly returns the current dimensions, so make sure to overload it in subclasses if this is not appropriate.

Reimplemented from PLearn::Variable.

Definition at line 85 of file VarArrayElementVariable.cc.

References PLearn::TVec< T >::length(), PLearn::TVec< T >::size(), and PLearn::NaryVariable::varray.

{
    if (varray.size()) {
        l = varray[0]->length();
        w = varray[0]->width();
    } else
        l = w = 0;
}

Here is the call graph for this function:

void PLearn::VarArrayElementVariable::symbolicBprop ( ) [virtual]

compute a piece of new Var graph that represents the symbolic derivative of this Var

Reimplemented from PLearn::Variable.

Definition at line 115 of file VarArrayElementVariable.cc.

References PLearn::Variable::g, PLearn::TVec< T >::last(), and PLearn::NaryVariable::varray.

{
    int index = (int)(varray.last()->valuedata[0]);
    varray[index]->accg(g);
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::NaryVariable.

Definition at line 64 of file VarArrayElementVariable.h.


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