PLearn 0.1
UnaryVariable.cc
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // PLearn (A C++ Machine Learning Library)
00004 // Copyright (C) 1998 Pascal Vincent
00005 // Copyright (C) 1999-2002 Pascal Vincent, Yoshua Bengio, Rejean Ducharme and University of Montreal
00006 // Copyright (C) 2001-2002 Nicolas Chapados, Ichiro Takeuchi, Jean-Sebastien Senecal
00007 // Copyright (C) 2002 Xiangdong Wang, Christian Dorion
00008 
00009 // Redistribution and use in source and binary forms, with or without
00010 // modification, are permitted provided that the following conditions are met:
00011 // 
00012 //  1. Redistributions of source code must retain the above copyright
00013 //     notice, this list of conditions and the following disclaimer.
00014 // 
00015 //  2. Redistributions in binary form must reproduce the above copyright
00016 //     notice, this list of conditions and the following disclaimer in the
00017 //     documentation and/or other materials provided with the distribution.
00018 // 
00019 //  3. The name of the authors may not be used to endorse or promote
00020 //     products derived from this software without specific prior written
00021 //     permission.
00022 // 
00023 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
00024 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00025 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
00026 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00027 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00028 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00029 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00030 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00031 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00032 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 // 
00034 // This file is part of the PLearn library. For more information on the PLearn
00035 // library, go to the PLearn Web site at www.plearn.org
00036 
00037 
00038 /* *******************************************************      
00039  * $Id: UnaryVariable.cc 9094 2008-06-03 21:08:22Z plearner $
00040  * This file is part of the PLearn library.
00041  ******************************************************* */
00042 
00043 #include "UnaryVariable.h"
00044 
00045 namespace PLearn {
00046 using namespace std;
00047 
00048 PLEARN_IMPLEMENT_OBJECT(
00049     UnaryVariable,
00050     "Variable that has a single parent.",
00051     ""
00052 );
00053 
00055 // UnaryVariable //
00057 UnaryVariable::UnaryVariable(Variable* v, int thelength, int thewidth,
00058                              bool call_build_):
00059     Variable(thelength, thewidth, call_build_),
00060     input(v) 
00061 {
00062     if (call_build_)
00063         build_();
00064 }
00065 
00067 // build //
00069 void UnaryVariable::build()
00070 {
00071     inherited::build();
00072     build_();
00073 }
00074 
00076 // build_ //
00078 void UnaryVariable::build_()
00079 {
00080     // Nothing to do here.
00081 }
00082 
00083 
00085 // setParents //
00087 void UnaryVariable::setParents(const VarArray& parents)
00088 {
00089     if(parents.length() != 1)
00090         PLERROR("In UnaryVariable::setParents  VarArray length must be 1;"
00091                 " you are trying to set %d parents for this BinaryVariable...", parents.length());
00092 
00093     input= parents[0];
00094   
00095     // int dummy_l, dummy_w;
00096     //recomputeSize(dummy_l, dummy_w);
00097     sizeprop();
00098 }
00099 
00100 
00101 void UnaryVariable::declareOptions(OptionList& ol)
00102 {
00103     declareOption(ol, "input", &UnaryVariable::input, OptionBase::buildoption, 
00104                   "The parent variable that this one depends on\n");
00105 
00106     inherited::declareOptions(ol);
00107 }
00108 
00109 #ifdef __INTEL_COMPILER
00110 #pragma warning(disable:1419)  // Get rid of compiler warning.
00111 #endif
00112 extern void varDeepCopyField(Var& field, CopiesMap& copies);
00113 #ifdef __INTEL_COMPILER
00114 #pragma warning(default:1419)
00115 #endif
00116 
00117 void UnaryVariable::makeDeepCopyFromShallowCopy(CopiesMap& copies)
00118 {
00119     inherited::makeDeepCopyFromShallowCopy(copies);
00120     //deepCopyField(input, copies);
00121     varDeepCopyField(input, copies); // a cause d'une bug du compilateur
00122 }
00123 
00124 bool UnaryVariable::markPath()
00125 {
00126     if(!marked)
00127         marked = input->markPath();
00128     return marked;
00129 }
00130 
00131 
00132 void UnaryVariable::buildPath(VarArray& proppath)
00133 {
00134     if(marked)
00135     {
00136         input->buildPath(proppath);
00137         //cout<<"add :"<<this->getName()<<endl;
00138         proppath.append(Var(this));
00139         clearMark();
00140     }
00141 }
00142 
00143 void UnaryVariable::checkContiguity() const
00144 {
00145     if(matValue.isNotContiguous() 
00146        || input->matValue.isNotContiguous()
00147        || matGradient.isNotContiguous() 
00148        || input->matGradient.isNotContiguous())
00149         PLERROR("operation not currently implemented for non-contiguous matrix data");
00150 }
00151 
00152 VarArray UnaryVariable::sources() 
00153 { 
00154     if (marked)
00155         return VarArray(0,0);
00156     marked = true;
00157     return input->sources(); 
00158 }
00159 
00160 VarArray UnaryVariable::random_sources() 
00161 { 
00162     if (marked)
00163         return VarArray(0,0);
00164     marked = true;
00165     return input->random_sources(); 
00166 }
00167 
00168 
00169 VarArray UnaryVariable::ancestors() 
00170 { 
00171     if (marked)
00172         return VarArray(0,0);
00173     marked = true;
00174     return input->ancestors() & (VarArray)Var(this);
00175 }
00176 
00177 
00178 void UnaryVariable::unmarkAncestors()
00179 { 
00180     if (marked)
00181     {
00182         marked = false;
00183         input->unmarkAncestors();
00184     }
00185 }
00186 
00187 
00188 VarArray UnaryVariable::parents() 
00189 { 
00190     if (input->marked)
00191         return VarArray(0,0);
00192     else
00193         return input;
00194 }
00195 
00196 
00197 void UnaryVariable::resizeRValue()
00198 {
00199     inherited::resizeRValue();
00200     if (!input->rvaluedata) input->resizeRValue();
00201 }
00202 
00204 // setInput //
00206 void UnaryVariable::setInput(Var the_input)
00207 {
00208     this->input = the_input;
00209     build();
00210 }
00211 
00212 } // end of namespace PLearn
00213 
00214 
00215 /*
00216   Local Variables:
00217   mode:c++
00218   c-basic-offset:4
00219   c-file-style:"stroustrup"
00220   c-file-offsets:((innamespace . 0)(inline-open . 0))
00221   indent-tabs-mode:nil
00222   fill-column:79
00223   End:
00224 */
00225 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines