PLearn 0.1
PutSubVMatrix.cc
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // PutSubVMatrix.cc
00004 //
00005 // Copyright (C) 2008 Olivier Delalleau
00006 //
00007 // Redistribution and use in source and binary forms, with or without
00008 // modification, are permitted provided that the following conditions are met:
00009 //
00010 //  1. Redistributions of source code must retain the above copyright
00011 //     notice, this list of conditions and the following disclaimer.
00012 //
00013 //  2. Redistributions in binary form must reproduce the above copyright
00014 //     notice, this list of conditions and the following disclaimer in the
00015 //     documentation and/or other materials provided with the distribution.
00016 //
00017 //  3. The name of the authors may not be used to endorse or promote
00018 //     products derived from this software without specific prior written
00019 //     permission.
00020 //
00021 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
00022 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00023 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
00024 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00025 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00026 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00027 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00028 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00029 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031 //
00032 // This file is part of the PLearn library. For more information on the PLearn
00033 // library, go to the PLearn Web site at www.plearn.org
00034 
00035 // Authors: Olivier Delalleau
00036 
00040 #include "PutSubVMatrix.h"
00041 
00042 namespace PLearn {
00043 using namespace std;
00044 
00045 PLEARN_IMPLEMENT_OBJECT(
00046     PutSubVMatrix,
00047     "Replace a sub-matrix of its source by another VMat.",
00048     "Keep in mind that field names and string mappings of the imputed submat\n"
00049     "will be ignored."
00050 );
00051 
00053 // PutSubVMatrix //
00055 PutSubVMatrix::PutSubVMatrix():
00056     istart(0),
00057     jstart(0)
00058 {}
00059 
00061 // declareOptions //
00063 void PutSubVMatrix::declareOptions(OptionList& ol)
00064 {
00065     declareOption(ol, "submat", &PutSubVMatrix::submat,
00066                   OptionBase::buildoption,
00067         "The data matrix to put in the source.");
00068 
00069     declareOption(ol, "istart", &PutSubVMatrix::istart,
00070                   OptionBase::buildoption,
00071         "Row index where 'submat' will be put.");
00072 
00073     declareOption(ol, "jstart", &PutSubVMatrix::jstart,
00074                   OptionBase::buildoption,
00075         "Column index where 'submat' will be put.");
00076 
00077     // Now call the parent class' declareOptions
00078     inherited::declareOptions(ol);
00079 }
00080 
00082 // build //
00084 void PutSubVMatrix::build()
00085 {
00086     inherited::build();
00087     build_();
00088 }
00089 
00091 // build_ //
00093 void PutSubVMatrix::build_()
00094 {
00095     if (!source)
00096         return;
00097 
00098     if (submat) {
00099         updateMtime(submat);
00100         PLCHECK( istart + submat.length() <= source->length() );
00101         PLCHECK( jstart + submat.width() <= source->width() );
00102         subrow.resize(submat->width());
00103     }
00104 
00105     setMetaInfoFromSource();
00106 }
00107 
00109 // getNewRow //
00111 void PutSubVMatrix::getNewRow(int i, const Vec& v) const
00112 {
00113     source->getRow(i, v);
00114     if (submat && submat->length() > 0 && subrow.length() > 0) {
00115         if (i >= istart && i < istart + submat->length()) {
00116             submat->getRow(i - istart, subrow);
00117             for (int j = 0; j < subrow.length(); j++)
00118                 v[jstart + j] = subrow[j];
00119         }
00120     }
00121 }
00122 
00124 // makeDeepCopyFromShallowCopy //
00126 void PutSubVMatrix::makeDeepCopyFromShallowCopy(CopiesMap& copies)
00127 {
00128     inherited::makeDeepCopyFromShallowCopy(copies);
00129 
00130     // ### Call deepCopyField on all "pointer-like" fields
00131     // ### that you wish to be deepCopied rather than
00132     // ### shallow-copied.
00133     // ### ex:
00134     // deepCopyField(trainvec, copies);
00135 
00136     // ### Remove this line when you have fully implemented this method.
00137     PLERROR("PutSubVMatrix::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!");
00138 }
00139 
00140 } // end of namespace PLearn
00141 
00142 
00143 /*
00144   Local Variables:
00145   mode:c++
00146   c-basic-offset:4
00147   c-file-style:"stroustrup"
00148   c-file-offsets:((innamespace . 0)(inline-open . 0))
00149   indent-tabs-mode:nil
00150   fill-column:79
00151   End:
00152 */
00153 // 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