PLearn 0.1
IndexedVMatrixTest.cc
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // IndexedVMatrixTest.cc
00004 //
00005 // Copyright (C) 2006 Pascal Lamblin
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: Pascal Lamblin
00036 
00040 #include "IndexedVMatrixTest.h"
00041 #include <plearn/vmat/AutoVMatrix.h>
00042 #include <plearn/vmat/IndexedVMatrix.h>
00043 #include <plearn/io/pl_log.h>
00044 
00045 namespace PLearn {
00046 using namespace std;
00047 
00048 PLEARN_IMPLEMENT_OBJECT(
00049     IndexedVMatrixTest,
00050     "Tests IndexedVMatrixTest behaviour, especially with NaN and strings",
00051     ""
00052 );
00053 
00055 // IndexedVMatrixTest //
00057 IndexedVMatrixTest::IndexedVMatrixTest()
00058 {
00059 }
00060 
00062 // build //
00064 void IndexedVMatrixTest::build()
00065 {
00066     inherited::build();
00067     build_();
00068 }
00069 
00071 // makeDeepCopyFromShallowCopy //
00073 void IndexedVMatrixTest::makeDeepCopyFromShallowCopy(CopiesMap& copies)
00074 {
00075     inherited::makeDeepCopyFromShallowCopy(copies);
00076 }
00077 
00079 // declareOptions //
00081 void IndexedVMatrixTest::declareOptions(OptionList& ol)
00082 {
00083     // declareOption(ol, "myoption", &IndexedVMatrixTest::myoption, OptionBase::buildoption,
00084     //               "Help text describing this option");
00085     declareOption(ol, "source_matrix", &IndexedVMatrixTest::source_matrix,
00086                   OptionBase::buildoption,
00087                   "Source matrix of the IndexedVMatrix being tested");
00088 
00089     // Now call the parent class' declareOptions
00090     inherited::declareOptions(ol);
00091 }
00092 
00094 // build_ //
00096 void IndexedVMatrixTest::build_()
00097 {
00098 }
00099 
00101 // perform //
00103 void IndexedVMatrixTest::perform()
00104 {
00105     // ### The test code should go here.
00106     if( source_matrix == "" )
00107         PLERROR( "In RowBufferedVMatrixTest::perform - You must provide"
00108                  " 'source_matrix' option" );
00109 
00110     VMat source_vmat = new AutoVMatrix( source_matrix );
00111     source_vmat->build();
00112 
00113     VMat indexed_vmat = new IndexedVMatrix( source_vmat, true, true );
00114 
00115     int n = indexed_vmat->length();
00116 
00117     MAND_LOG << "source_matrix = " << source_matrix.canonical() << endl;
00118     MAND_LOG << "Column 2 (value) of indexed_vmat as strings:" << endl;
00119     for( int i=0 ; i<n ; i++ )
00120     {
00121         MAND_LOG << indexed_vmat->getString(i,2) << endl;
00122     }
00123     MAND_LOG << endl;
00124 
00125     MAND_LOG << "Underlying (real) values:" << endl;
00126     for( int i=0 ; i<n ; i++ )
00127     {
00128         MAND_LOG << indexed_vmat(i,2) << endl;
00129     }
00130 }
00131 
00132 } // end of namespace PLearn
00133 
00134 
00135 /*
00136   Local Variables:
00137   mode:c++
00138   c-basic-offset:4
00139   c-file-style:"stroustrup"
00140   c-file-offsets:((innamespace . 0)(inline-open . 0))
00141   indent-tabs-mode:nil
00142   fill-column:79
00143   End:
00144 */
00145 // 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