PLearn 0.1
|
Variable that is the element of the input1 VarArray indexed by the input2 variable. More...
#include <VarArrayElementVariable.h>
Public Member Functions | |
VarArrayElementVariable () | |
protected default constructor for persistence | |
VarArrayElementVariable (VarArray &input1, const Var &input2) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual VarArrayElementVariable * | deepCopy (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 PPath & | declaringFile () |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Protected Member Functions | |
void | build_ () |
Object-specific post-constructor. | |
Private Types | |
typedef NaryVariable | inherited |
Variable that is the element of the input1 VarArray indexed by the input2 variable.
Definition at line 55 of file VarArrayElementVariable.h.
typedef NaryVariable PLearn::VarArrayElementVariable::inherited [private] |
Reimplemented from PLearn::NaryVariable.
Definition at line 57 of file VarArrayElementVariable.h.
PLearn::VarArrayElementVariable::VarArrayElementVariable | ( | ) | [inline] |
protected default constructor for persistence
Definition at line 61 of file VarArrayElementVariable.h.
{}
string PLearn::VarArrayElementVariable::_classname_ | ( | ) | [static] |
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.
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]; }
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_().
{ inherited::build(); build_(); }
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"); } }
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]; }
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.
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.
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.
Reimplemented from PLearn::NaryVariable.
Definition at line 64 of file VarArrayElementVariable.h.