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

IndexedVMatrix.cc

Go to the documentation of this file.
00001 // -*- C++ -*- 00002 00003 // PLearn (A C++ Machine Learning Library) 00004 // Copyright (C) 2003 Pascal Vincent, Olivier Delalleau 00005 // 00006 // Redistribution and use in source and binary forms, with or without 00007 // modification, are permitted provided that the following conditions are met: 00008 // 00009 // 1. Redistributions of source code must retain the above copyright 00010 // notice, this list of conditions and the following disclaimer. 00011 // 00012 // 2. Redistributions in binary form must reproduce the above copyright 00013 // notice, this list of conditions and the following disclaimer in the 00014 // documentation and/or other materials provided with the distribution. 00015 // 00016 // 3. The name of the authors may not be used to endorse or promote 00017 // products derived from this software without specific prior written 00018 // permission. 00019 // 00020 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00021 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00022 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00023 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00024 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00025 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00026 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00027 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00028 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 // 00031 // This file is part of the PLearn library. For more information on the PLearn 00032 // library, go to the PLearn Web site at www.plearn.org 00033 00034 00035 /* ******************************************************* 00036 * $Id: IndexedVMatrix.cc,v 1.5 2004/04/05 22:54:50 morinf Exp $ 00037 ******************************************************* */ 00038 00039 #include "IndexedVMatrix.h" 00040 00041 namespace PLearn { 00042 using namespace std; 00043 00044 PLEARN_IMPLEMENT_OBJECT(IndexedVMatrix, "ONE LINE DESCR", 00045 " VMat class that sees a matrix as a collection of triplets (row, column, value)\n" 00046 "Thus it is a N x 3 matrix, with N = the number of elements in the original matrix.\n"); 00047 00048 void IndexedVMatrix::declareOptions(OptionList& ol) 00049 { 00050 declareOption(ol, "m", &IndexedVMatrix::m, OptionBase::buildoption, 00051 " The matrix viewed by the IndexedVMatrix\n"); 00052 inherited::declareOptions(ol); 00053 } 00054 00055 void IndexedVMatrix::makeDeepCopyFromShallowCopy(map<const void*, void*>& copies) 00056 { 00057 inherited::makeDeepCopyFromShallowCopy(copies); 00058 deepCopyField(m, copies); 00059 } 00060 00061 void IndexedVMatrix::build() 00062 { 00063 inherited::build(); 00064 build_(); 00065 } 00066 00068 // build_ // 00070 void IndexedVMatrix::build_() 00071 { 00072 if (m) { 00073 width_ = 3; 00074 length_ = m->length() * m->width(); 00075 // TODO Get Field Infos ? 00076 } 00077 } 00078 00080 // get // 00082 real IndexedVMatrix::get(int i, int j) const { 00083 int w = m->width(); 00084 int i_ = i / w; // the value of the first column at row i 00085 int j_ = i % w; // the value of the second column at row i 00086 switch (j) { 00087 case 0: 00088 return i_; 00089 case 1: 00090 return j_; 00091 case 2: 00092 return m->get(i_, j_); 00093 default: 00094 PLERROR("In IndexedVMatrix::get An IndexedVMatrix has only 3 columns\n"); 00095 return 0; 00096 } 00097 } 00098 00100 // put // 00102 void IndexedVMatrix::put(int i, int j, real value) { 00103 if (j != 2) { 00104 PLERROR("In IndexedVMatrix::put You can only modify the third column\n"); 00105 } 00106 int w = m->width(); 00107 int i_ = i / w; // the value of the first column at row i 00108 int j_ = i % w; // the value of the second column at row i 00109 m->put(i_, j_, value); 00110 } 00111 00112 00113 } // end of namespcae PLearn

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