Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

ConcatRowsSubVMatrix.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-2001 Pascal Vincent, Yoshua Bengio, Rejean Ducharme and University of Montreal 00006 // Copyright (C) 2002 Pascal Vincent, Julien Keable, Xavier Saint-Mleux 00007 // 00008 // Redistribution and use in source and binary forms, with or without 00009 // modification, are permitted provided that the following conditions are met: 00010 // 00011 // 1. Redistributions of source code must retain the above copyright 00012 // notice, this list of conditions and the following disclaimer. 00013 // 00014 // 2. Redistributions in binary form must reproduce the above copyright 00015 // notice, this list of conditions and the following disclaimer in the 00016 // documentation and/or other materials provided with the distribution. 00017 // 00018 // 3. The name of the authors may not be used to endorse or promote 00019 // products derived from this software without specific prior written 00020 // permission. 00021 // 00022 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00023 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00024 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00025 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00026 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00027 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00028 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00029 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00030 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00031 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 // 00033 // This file is part of the PLearn library. For more information on the PLearn 00034 // library, go to the PLearn Web site at www.plearn.org 00035 00036 00037 /* ******************************************************* 00038 * $Id: ConcatRowsSubVMatrix.cc,v 1.4 2004/04/05 22:49:56 morinf Exp $ 00039 ******************************************************* */ 00040 00041 #include "ConcatRowsSubVMatrix.h" 00042 00043 namespace PLearn { 00044 using namespace std; 00045 00046 00049 PLEARN_IMPLEMENT_OBJECT(ConcatRowsSubVMatrix, "ONE LINE DESC", "ONE LINE HELP"); 00050 00051 ConcatRowsSubVMatrix::ConcatRowsSubVMatrix() 00052 { 00053 } 00054 00055 ConcatRowsSubVMatrix::ConcatRowsSubVMatrix(VMat the_distr, TVec<int>& the_start, TVec<int>& the_len) 00056 : inherited(-1,the_distr->width()), distr(the_distr), start(the_start), len(the_len) 00057 { 00059 /* 00060 fieldinfos = the_distr->getFieldInfos(); 00061 00062 check(); 00063 */ 00064 build(); 00065 } 00066 00067 ConcatRowsSubVMatrix::ConcatRowsSubVMatrix(VMat the_distr, int start1, int len1, int start2, int len2) 00068 : inherited(-1,the_distr->width()), distr(the_distr), start(2), len(2) 00069 { 00071 //fieldinfos = the_distr->getFieldInfos(); 00072 00073 start[0]=start1; 00074 start[1]=start2; 00075 len[0]=len1; 00076 len[1]=len2; 00077 //check(); 00078 build(); 00079 } 00080 /* 00081 void ConcatRowsSubVMatrix::check() 00082 { 00083 length_=0; 00084 for (int i=0;i<start.length();i++) 00085 { 00086 if (start[i]<0 || start[i]+len[i]>distr->length()) 00087 PLERROR("ConcatRowsSubVMatrix: out-of-range specs for sub-distr %d, " 00088 "start=%d, len=%d, underlying distr length=%d",i,start[i],len[i], 00089 distr->length()); 00090 length_ += len[i]; 00091 } 00092 } 00093 */ 00094 00095 void ConcatRowsSubVMatrix::getpositions(int i, int& whichvm, int& rowofvm) const 00096 { 00097 #ifdef BOUNDCHECK 00098 if(i<0 || i>=length()) 00099 PLERROR("In ConcatRowsSubVMatrix::getpositions OUT OF BOUNDS"); 00100 #endif 00101 00102 int pos = 0; 00103 int k=0; 00104 while(i>=pos+len[k]) 00105 { 00106 pos += len[k]; 00107 k++; 00108 } 00109 00110 whichvm = k; 00111 rowofvm = i-pos; 00112 } 00113 00114 real ConcatRowsSubVMatrix::get(int i, int j) const 00115 { 00116 int whichvm, rowofvm; 00117 getpositions(i,whichvm,rowofvm); 00118 return distr->get(start[whichvm]+rowofvm,j); 00119 } 00120 00121 void ConcatRowsSubVMatrix::getSubRow(int i, int j, Vec v) const 00122 { 00123 int whichvm, rowofvm; 00124 getpositions(i,whichvm,rowofvm); 00125 distr->getSubRow(start[whichvm]+rowofvm, j, v); 00126 } 00127 00128 real ConcatRowsSubVMatrix::dot(int i1, int i2, int inputsize) const 00129 { 00130 int whichvm1, rowofvm1; 00131 getpositions(i1,whichvm1,rowofvm1); 00132 int whichvm2, rowofvm2; 00133 getpositions(i2,whichvm2,rowofvm2); 00134 return distr->dot(start[whichvm1]+rowofvm1, start[whichvm2]+rowofvm2, inputsize); 00135 } 00136 00137 real ConcatRowsSubVMatrix::dot(int i, const Vec& v) const 00138 { 00139 int whichvm, rowofvm; 00140 getpositions(i,whichvm,rowofvm); 00141 return distr->dot(start[whichvm]+rowofvm,v); 00142 } 00143 00144 void 00145 ConcatRowsSubVMatrix::declareOptions(OptionList &ol) 00146 { 00147 declareOption(ol, "distr", &ConcatRowsSubVMatrix::distr, OptionBase::buildoption, ""); 00148 declareOption(ol, "start", &ConcatRowsSubVMatrix::start, OptionBase::buildoption, ""); 00149 declareOption(ol, "len", &ConcatRowsSubVMatrix::len, OptionBase::buildoption, ""); 00150 inherited::declareOptions(ol); 00151 } 00152 00153 void 00154 ConcatRowsSubVMatrix::build() 00155 { 00156 inherited::build(); 00157 build_(); 00158 } 00159 00160 void 00161 ConcatRowsSubVMatrix::build_() 00162 { 00163 if (distr) { 00164 fieldinfos = distr->getFieldInfos(); 00165 length_=0; 00166 for (int i = 0; i < start.length(); i++) { 00167 if (start[i]<0 || start[i]+len[i]>distr->length()) 00168 PLERROR("ConcatRowsSubVMatrix: out-of-range specs for sub-distr %d, " 00169 "start=%d, len=%d, underlying distr length=%d",i,start[i],len[i], 00170 distr->length()); 00171 length_ += len[i]; 00172 } 00173 } 00174 } 00175 00176 } // end of namespcae PLearn

Generated on Tue Aug 17 15:49:49 2004 for PLearn by doxygen 1.3.7