PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // ForwardVMatrix.cc 00004 // Copyright (C) 2002 Pascal Vincent 00005 // 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 00036 00037 00038 /* ******************************************************* 00039 * $Id: ForwardVMatrix.cc 8247 2007-11-12 20:22:12Z nouiz $ 00040 * This file is part of the PLearn library. 00041 ******************************************************* */ 00042 00043 00046 #include "ForwardVMatrix.h" 00047 00048 namespace PLearn { 00049 using namespace std; 00050 00051 PLEARN_IMPLEMENT_OBJECT(ForwardVMatrix, 00052 "Forward all calls to an underlying VMatrix.", 00053 "" 00054 ); 00055 00056 ForwardVMatrix::ForwardVMatrix() 00057 {} 00058 00059 ForwardVMatrix::ForwardVMatrix(VMat the_vm) 00060 : vm(the_vm) 00061 { 00062 } 00063 00064 void 00065 ForwardVMatrix::build() 00066 { 00067 inherited::build(); 00068 build_(); 00069 } 00070 00071 void 00072 ForwardVMatrix::build_() 00073 { 00074 if (vm) { 00075 length_ = vm->length(); 00076 width_ = vm->width(); 00077 writable = vm->isWritable(); 00078 setMetaInfoFrom(vm); 00079 if (vm->hasMetaDataDir() && !this->hasMetaDataDir()) 00080 setMetaDataDir(vm->getMetaDataDir()); 00081 00082 } else { 00083 length_ = 0; 00084 width_ = 0; 00085 } 00086 } 00087 00088 void ForwardVMatrix::setVMat(VMat the_vm) 00089 { 00090 if(the_vm) 00091 vm = the_vm; 00092 else 00093 vm = VMat(); 00094 build_(); 00095 } 00096 00097 void 00098 ForwardVMatrix::declareOptions(OptionList &ol) 00099 { 00100 declareOption(ol, "vm", &ForwardVMatrix::vm, OptionBase::buildoption, 00101 "The underlying VMat to which all calls are forwarded."); 00102 00103 inherited::declareOptions(ol); 00104 00105 // Hide unused options (automatically defined at build time). 00106 00107 declareOption(ol, "writable", &ForwardVMatrix::writable, OptionBase::nosave, ""); 00108 declareOption(ol, "length", &ForwardVMatrix::length_, OptionBase::nosave, ""); 00109 declareOption(ol, "width", &ForwardVMatrix::width_, OptionBase::nosave, ""); 00110 } 00111 00112 string ForwardVMatrix::getValString(int col, real val) const 00113 { return vm->getValString(col, val); } 00114 00115 00116 real ForwardVMatrix::getStringVal(int col, const string& str) const 00117 { return vm->getStringVal(col, str); } 00118 00119 00120 string ForwardVMatrix::getString(int row,int col) const 00121 { return vm->getString(row,col); } 00122 00123 map<string,real> ForwardVMatrix::getStringMapping(int col) const 00124 { 00125 PLERROR("ForwardVMatrix::getStringMapping not implemented yet"); 00126 // making the compiler happy: 00127 return map<string,real>(); 00128 00129 // return vm->getStringMapping(col); 00130 } 00131 00133 // getStringToRealMapping // 00135 const map<string,real>& ForwardVMatrix::getStringToRealMapping(int col) const { 00136 return vm->getStringToRealMapping(col); 00137 } 00138 00140 // getRealToStringMapping // 00142 const map<real,string>& ForwardVMatrix::getRealToStringMapping(int col) const { 00143 return vm->getRealToStringMapping(col); 00144 } 00145 00146 void ForwardVMatrix::computeStats() 00147 { vm->computeStats(); } 00148 00149 00150 void ForwardVMatrix::save(const PPath& filename) const 00151 { vm->save(filename); } 00152 00153 void ForwardVMatrix::savePMAT(const PPath& pmatfile) const 00154 { vm->savePMAT(pmatfile); } 00155 void ForwardVMatrix::saveDMAT(const PPath& dmatdir) const 00156 { vm->saveDMAT(dmatdir); } 00157 00159 // saveAMAT // 00161 void ForwardVMatrix::saveAMAT(const PPath& amatfile, bool verbose, bool no_header, bool save_strings) const 00162 { vm->saveAMAT(amatfile, verbose, no_header, save_strings); } 00163 00164 real ForwardVMatrix::get(int i, int j) const 00165 { return vm->get(i, j); } 00166 00167 00168 void ForwardVMatrix::put(int i, int j, real value) 00169 { vm->put(i, j, value); } 00170 00171 void ForwardVMatrix::getSubRow(int i, int j, Vec v) const 00172 { vm->getSubRow(i, j, v); } 00173 00174 void ForwardVMatrix::putSubRow(int i, int j, Vec v) 00175 { vm->putSubRow(i, j, v); } 00176 00177 void ForwardVMatrix::appendRow(Vec v) 00178 { vm->appendRow(v); } 00179 00180 void ForwardVMatrix::getRow(int i, Vec v) const 00181 { 00182 PLASSERT( v.length() == width() ); 00183 vm->getRow(i, v); 00184 } 00185 00186 void ForwardVMatrix::putRow(int i, Vec v) 00187 { vm->putRow(i, v); } 00188 void ForwardVMatrix::fill(real value) 00189 { vm->fill(value); } 00190 void ForwardVMatrix::getMat(int i, int j, Mat m) const 00191 { vm->getMat(i, j, m); } 00192 void ForwardVMatrix::putMat(int i, int j, Mat m) 00193 { vm->putMat(i, j, m); } 00194 00195 00196 void ForwardVMatrix::getColumn(int i, Vec v) const 00197 { vm->getColumn(i, v); } 00198 00199 Mat ForwardVMatrix::toMat() const 00200 { return vm->toMat(); } 00201 00202 00203 00204 void ForwardVMatrix::compacify() 00205 { vm->compacify(); } 00206 00207 00208 void ForwardVMatrix::reset_dimensions() 00209 { 00210 if (vm) { 00211 vm->reset_dimensions(); 00212 length_ = vm->length(); 00213 width_ = vm->width(); 00214 inputsize_ = vm->inputsize(); 00215 targetsize_ = vm->targetsize(); 00216 weightsize_ = vm->weightsize(); 00217 } 00218 } 00219 00220 VMat ForwardVMatrix::subMat(int i, int j, int l, int w) 00221 { return vm->subMat(i,j,l,w); } 00222 00223 real ForwardVMatrix::dot(int i1, int i2, int inputsize) const 00224 { return vm->dot(i1, i2, inputsize); } 00225 00226 00227 real ForwardVMatrix::dot(int i, const Vec& v) const 00228 { return vm->dot(i, v); } 00229 00230 void ForwardVMatrix::accumulateXtY(int X_startcol, int X_ncols, int Y_startcol, int Y_ncols, 00231 Mat& result, int startrow, int nrows, int ignore_this_row) const 00232 { vm->accumulateXtY(X_startcol, X_ncols, Y_startcol, Y_ncols, 00233 result, startrow, nrows, ignore_this_row); } 00234 00235 void ForwardVMatrix::accumulateXtX(int X_startcol, int X_ncols, 00236 Mat& result, int startrow, int nrows, int ignore_this_row) const 00237 { vm->accumulateXtX(X_startcol, X_ncols, 00238 result, startrow, nrows, ignore_this_row); } 00239 00240 void ForwardVMatrix::makeDeepCopyFromShallowCopy(CopiesMap& copies) 00241 { 00242 inherited::makeDeepCopyFromShallowCopy(copies); 00243 deepCopyField(vm, copies); 00244 } 00245 00246 } 00247 00248 00249 /* 00250 Local Variables: 00251 mode:c++ 00252 c-basic-offset:4 00253 c-file-style:"stroustrup" 00254 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00255 indent-tabs-mode:nil 00256 fill-column:79 00257 End: 00258 */ 00259 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :