data_aux.h

00001 /* MLPACK 0.2
00002  *
00003  * Copyright (c) 2008, 2009 Alexander Gray,
00004  *                          Garry Boyer,
00005  *                          Ryan Riegel,
00006  *                          Nikolaos Vasiloglou,
00007  *                          Dongryeol Lee,
00008  *                          Chip Mappus, 
00009  *                          Nishant Mehta,
00010  *                          Hua Ouyang,
00011  *                          Parikshit Ram,
00012  *                          Long Tran,
00013  *                          Wee Chin Wong
00014  *
00015  * Copyright (c) 2008, 2009 Georgia Institute of Technology
00016  *
00017  * This program is free software; you can redistribute it and/or
00018  * modify it under the terms of the GNU General Public License as
00019  * published by the Free Software Foundation; either version 2 of the
00020  * License, or (at your option) any later version.
00021  *
00022  * This program is distributed in the hope that it will be useful, but
00023  * WITHOUT ANY WARRANTY; without even the implied warranty of
00024  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00025  * General Public License for more details.
00026  *
00027  * You should have received a copy of the GNU General Public License
00028  * along with this program; if not, write to the Free Software
00029  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00030  * 02110-1301, USA.
00031  */
00032 #ifndef DATA_AUX_H
00033 #define DATA_AUX_H
00034 
00035 #include "fastlib/fastlib.h"
00036 
00037 namespace data_aux {
00038 
00053   template<typename T>
00054   static success_t Load(const char *fname, GenMatrix<T> *matrix) {
00055     Matrix tmp_matrix;
00056     success_t result = data::Load(fname, &tmp_matrix);
00057 
00058     // Allocate the matrix that is to be returned and copy all
00059     // entries.
00060     matrix->StaticInit(tmp_matrix.n_rows(), tmp_matrix.n_cols());
00061     for(index_t c = 0; c < tmp_matrix.n_cols(); c++) {
00062       for(index_t r = 0; r < tmp_matrix.n_rows(); r++) {
00063         matrix->set(r, c, STATIC_CAST(T, tmp_matrix.get(r, c)));
00064       }
00065     }
00066 
00067     return result;
00068   }
00069 
00084   template<typename T>
00085   static success_t LoadTranspose(const char *fname, GenMatrix<T> *matrix) {
00086     Matrix tmp_matrix;
00087     success_t result = data::Load(fname, &tmp_matrix);
00088 
00089     // Allocate the matrix that is to be returned and copy all
00090     // entries.
00091     matrix->StaticInit(tmp_matrix.n_cols(), tmp_matrix.n_rows());
00092     for(index_t c = 0; c < tmp_matrix.n_cols(); c++) {
00093       for(index_t r = 0; r < tmp_matrix.n_rows(); r++) {
00094         matrix->set(c, r, STATIC_CAST(T, tmp_matrix.get(r, c)));
00095       }
00096     }
00097 
00098     return result;
00099   }
00100 
00101 };
00102 
00103 #endif
Generated on Mon Jan 24 12:04:38 2011 for FASTlib by  doxygen 1.6.3