ECOCPAK v0.9
fn_sparse_to_dense.hpp
Go to the documentation of this file.
00001 // Copyright (C) 2011 the authors listed below
00002 // http://ecocpak.sourceforge.net
00003 // 
00004 // Authors:
00005 // - Dimitrios Bouzas (bouzas at ieee dot org)
00006 // - Nikolaos Arvanitopoulos (niarvani at ieee dot org)
00007 // - Anastasios Tefas (tefas at aiia dot csd dot auth dot gr)
00008 // 
00009 // This file is part of the ECOC PAK C++ library. It is 
00010 // provided without any warranty of fitness for any purpose.
00011 //
00012 // You can redistribute this file and/or modify it under 
00013 // the terms of the GNU Lesser General Public License (LGPL) 
00014 // as published by the Free Software Foundation, either 
00015 // version 3 of the License or (at your option) any later 
00016 // version.
00017 // (see http://www.opensource.org/licenses for more info)
00018 
00019 
00022 
00023 
00024 
00038 mat
00039 sparse_to_dense
00040   (
00041         struct svm_node** const X,
00042         const u32 n_rows,
00043         const u32 n_cols
00044   )
00045   {
00046   // allocate space for dense matrix representation
00047   mat dense_matrix = zeros<mat>(n_rows, n_cols);
00048   
00049   // for each row of X
00050   for(u32 i = 0; i < n_rows; i++)
00051     {  
00052     struct svm_node* tmp_node = const_cast<struct svm_node*>(X[i]);
00053     
00054     while(tmp_node->index != -1)
00055       {
00056       dense_matrix(i, tmp_node->index - 1) = tmp_node->value;
00057       tmp_node++;
00058       }
00059       
00060     }
00061  
00062   return dense_matrix; 
00063   }
00064 
00065 
00066 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerator Defines