00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
#include "BinaryVariable.h"
00044
00045
namespace PLearn {
00046
00047
using namespace std;
00048
00051 BinaryVariable::BinaryVariable(
Variable* v1,
Variable* v2,
int thelength,
int thewidth)
00052 :
Variable(thelength,thewidth), input1(v1), input2(v2)
00053 {
00054
input1->disallowPartialUpdates();
00055
input2->disallowPartialUpdates();
00056 }
00057
00058
00059
PLEARN_IMPLEMENT_ABSTRACT_OBJECT(
BinaryVariable,
"ONE LINE DESCR",
"NO HELP");
00060
00061 void BinaryVariable::declareOptions(
OptionList& ol)
00062 {
00063
declareOption(ol,
"input1", &BinaryVariable::input1, OptionBase::buildoption,
00064
"The first parent variable that this one depends on\n");
00065
00066
declareOption(ol,
"input2", &BinaryVariable::input2, OptionBase::buildoption,
00067
"The second parent variable that this one depends on\n");
00068
00069 inherited::declareOptions(ol);
00070 }
00071
00072 void BinaryVariable::setParents(
const VarArray& parents)
00073 {
00074
if(parents.
length() != 2)
00075
PLERROR(
"In BinaryVariable::setParents VarArray length must be 2;"
00076
" you are trying to set %d parents for this BinaryVariable...", parents.
length());
00077
00078
input1= parents[0];
00079
input2= parents[1];
00080
00081
int dummy_l, dummy_w;
00082 recomputeSize(dummy_l, dummy_w);
00083 }
00084
00085
00086
00087
00088
00089
00090
00091
00092
extern void varDeepCopyField(
Var& field, CopiesMap& copies);
00093
00094 void BinaryVariable::makeDeepCopyFromShallowCopy(map<const void*, void*>& copies)
00095 {
00096 Variable::makeDeepCopyFromShallowCopy(copies);
00097
00098
varDeepCopyField(
input1, copies);
00099
00100
varDeepCopyField(
input2, copies);
00101 }
00102
00103
00104 bool BinaryVariable::markPath()
00105 {
00106
if(!marked)
00107 marked =
input1->markPath() |
input2->markPath();
00108
return marked;
00109 }
00110
00111
00112 void BinaryVariable::buildPath(
VarArray& proppath)
00113 {
00114
if(marked)
00115 {
00116
input1->buildPath(proppath);
00117
input2->buildPath(proppath);
00118 proppath &=
Var(
this);
00119
00120
clearMark();
00121 }
00122 }
00123
00124
00125 VarArray BinaryVariable::sources()
00126 {
00127
if (marked)
00128
return VarArray(0,0);
00129 marked =
true;
00130
return input1->sources() &
input2->sources();
00131 }
00132
00133
00134 VarArray BinaryVariable::random_sources()
00135 {
00136
if (marked)
00137
return VarArray(0,0);
00138 marked =
true;
00139
return input1->random_sources() &
input2->random_sources();
00140 }
00141
00142
00143 VarArray BinaryVariable::ancestors()
00144 {
00145
if (marked)
00146
return VarArray(0,0);
00147 marked =
true;
00148
return input1->ancestors() &
input2->ancestors() &
Var(
this) ;
00149 }
00150
00151
00152 void BinaryVariable::unmarkAncestors()
00153 {
00154
if (marked)
00155 {
00156 marked =
false;
00157
input1->unmarkAncestors();
00158
input2->unmarkAncestors();
00159 }
00160 }
00161
00162
00163 VarArray BinaryVariable::parents()
00164 {
00165
VarArray unmarked_parents;
00166
if (!
input1->marked)
00167 unmarked_parents.
append(
input1);
00168
if (!
input2->marked)
00169 unmarked_parents.
append(
input2);
00170
return unmarked_parents;
00171 }
00172
00173
00174 void BinaryVariable::resizeRValue()
00175 {
00176 inherited::resizeRValue();
00177
if (!
input1->rvaluedata)
input1->resizeRValue();
00178
if (!
input2->rvaluedata)
input2->resizeRValue();
00179 }
00180
00181
00182
00183 }
00184
00185