SHOGUN
v2.0.0
|
00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 2011 Shashwat Lal Das 00008 * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society 00009 */ 00010 #ifndef __STREAMING_FILE_H__ 00011 #define __STREAMING_FILE_H__ 00012 00013 #include <shogun/lib/config.h> 00014 #include <shogun/base/DynArray.h> 00015 #include <shogun/lib/common.h> 00016 #include <shogun/io/File.h> 00017 #include <shogun/io/SGIO.h> 00018 #include <shogun/lib/DataType.h> 00019 #include <shogun/lib/SGSparseVector.h> 00020 #include <shogun/io/IOBuffer.h> 00021 #include <shogun/classifier/vw/vw_common.h> 00022 00023 #include <ctype.h> 00024 #include <fcntl.h> 00025 #include <unistd.h> 00026 00027 namespace shogun 00028 { 00039 class CStreamingFile: public CSGObject 00040 { 00041 public: 00043 CStreamingFile(); 00044 00050 CStreamingFile(const char* fname, char rw='r'); 00051 00053 virtual ~CStreamingFile(); 00054 00058 void close() 00059 { 00060 buf->close_file(); 00061 } 00062 00068 inline virtual bool is_seekable() { return false; } 00069 00073 virtual void reset_stream() { SG_ERROR("Unable to reset the input stream!\n"); } 00074 00084 virtual void get_vector(bool*& vector, int32_t& len); 00085 virtual void get_vector(uint8_t*& vector, int32_t& len); 00086 virtual void get_vector(char*& vector, int32_t& len); 00087 virtual void get_vector(int32_t*& vector, int32_t& len); 00088 virtual void get_vector(float32_t*& vector, int32_t& len); 00089 virtual void get_vector(float64_t*& vector, int32_t& len); 00090 virtual void get_vector(int16_t*& vector, int32_t& len); 00091 virtual void get_vector(uint16_t*& vector, int32_t& len); 00092 virtual void get_vector(int8_t*& vector, int32_t& len); 00093 virtual void get_vector(uint32_t*& vector, int32_t& len); 00094 virtual void get_vector(int64_t*& vector, int32_t& len); 00095 virtual void get_vector(uint64_t*& vector, int32_t& len); 00096 virtual void get_vector(floatmax_t*& vector, int32_t& len); 00098 00108 virtual void get_vector_and_label 00109 (bool*& vector, int32_t& len, float64_t& label); 00110 virtual void get_vector_and_label 00111 (uint8_t*& vector, int32_t& len, float64_t& label); 00112 virtual void get_vector_and_label 00113 (char*& vector, int32_t& len, float64_t& label); 00114 virtual void get_vector_and_label 00115 (int32_t*& vector, int32_t& len, float64_t& label); 00116 virtual void get_vector_and_label 00117 (float32_t*& vector, int32_t& len, float64_t& label); 00118 virtual void get_vector_and_label 00119 (float64_t*& vector, int32_t& len, float64_t& label); 00120 virtual void get_vector_and_label 00121 (int16_t*& vector, int32_t& len, float64_t& label); 00122 virtual void get_vector_and_label 00123 (uint16_t*& vector, int32_t& len, float64_t& label); 00124 virtual void get_vector_and_label 00125 (int8_t*& vector, int32_t& len, float64_t& label); 00126 virtual void get_vector_and_label 00127 (uint32_t*& vector, int32_t& len, float64_t& label); 00128 virtual void get_vector_and_label 00129 (int64_t*& vector, int32_t& len, float64_t& label); 00130 virtual void get_vector_and_label 00131 (uint64_t*& vector, int32_t& len, float64_t& label); 00132 virtual void get_vector_and_label 00133 (floatmax_t*& vector, int32_t& len, float64_t& label); 00135 00145 virtual void get_string(bool*& vector, int32_t& len); 00146 virtual void get_string(uint8_t*& vector, int32_t& len); 00147 virtual void get_string(char*& vector, int32_t& len); 00148 virtual void get_string(int32_t*& vector, int32_t& len); 00149 virtual void get_string(float32_t*& vector, int32_t& len); 00150 virtual void get_string(float64_t*& vector, int32_t& len); 00151 virtual void get_string(int16_t*& vector, int32_t& len); 00152 virtual void get_string(uint16_t*& vector, int32_t& len); 00153 virtual void get_string(int8_t*& vector, int32_t& len); 00154 virtual void get_string(uint32_t*& vector, int32_t& len); 00155 virtual void get_string(int64_t*& vector, int32_t& len); 00156 virtual void get_string(uint64_t*& vector, int32_t& len); 00157 virtual void get_string(floatmax_t*& vector, int32_t& len); 00159 00169 virtual void get_string_and_label 00170 (bool*& vector, int32_t& len, float64_t& label); 00171 virtual void get_string_and_label 00172 (uint8_t*& vector, int32_t& len, float64_t& label); 00173 virtual void get_string_and_label 00174 (char*& vector, int32_t& len, float64_t& label); 00175 virtual void get_string_and_label 00176 (int32_t*& vector, int32_t& len, float64_t& label); 00177 virtual void get_string_and_label 00178 (float32_t*& vector, int32_t& len, float64_t& label); 00179 virtual void get_string_and_label 00180 (float64_t*& vector, int32_t& len, float64_t& label); 00181 virtual void get_string_and_label 00182 (int16_t*& vector, int32_t& len, float64_t& label); 00183 virtual void get_string_and_label 00184 (uint16_t*& vector, int32_t& len, float64_t& label); 00185 virtual void get_string_and_label 00186 (int8_t*& vector, int32_t& len, float64_t& label); 00187 virtual void get_string_and_label 00188 (uint32_t*& vector, int32_t& len, float64_t& label); 00189 virtual void get_string_and_label 00190 (int64_t*& vector, int32_t& len, float64_t& label); 00191 virtual void get_string_and_label 00192 (uint64_t*& vector, int32_t& len, float64_t& label); 00193 virtual void get_string_and_label 00194 (floatmax_t*& vector, int32_t& len, float64_t& label); 00196 00206 virtual void get_sparse_vector 00207 (SGSparseVectorEntry<bool>*& vector, int32_t& len); 00208 virtual void get_sparse_vector 00209 (SGSparseVectorEntry<uint8_t>*& vector, int32_t& len); 00210 virtual void get_sparse_vector 00211 (SGSparseVectorEntry<char>*& vector, int32_t& len); 00212 virtual void get_sparse_vector 00213 (SGSparseVectorEntry<int32_t>*& vector, int32_t& len); 00214 virtual void get_sparse_vector 00215 (SGSparseVectorEntry<float32_t>*& vector, int32_t& len); 00216 virtual void get_sparse_vector 00217 (SGSparseVectorEntry<float64_t>*& vector, int32_t& len); 00218 virtual void get_sparse_vector 00219 (SGSparseVectorEntry<int16_t>*& vector, int32_t& len); 00220 virtual void get_sparse_vector 00221 (SGSparseVectorEntry<uint16_t>*& vector, int32_t& len); 00222 virtual void get_sparse_vector 00223 (SGSparseVectorEntry<int8_t>*& vector, int32_t& len); 00224 virtual void get_sparse_vector 00225 (SGSparseVectorEntry<uint32_t>*& vector, int32_t& len); 00226 virtual void get_sparse_vector 00227 (SGSparseVectorEntry<int64_t>*& vector, int32_t& len); 00228 virtual void get_sparse_vector 00229 (SGSparseVectorEntry<uint64_t>*& vector, int32_t& len); 00230 virtual void get_sparse_vector 00231 (SGSparseVectorEntry<floatmax_t>*& vector, int32_t& len); 00233 00243 virtual void get_sparse_vector_and_label 00244 (SGSparseVectorEntry<bool>*& vector, int32_t& len, float64_t& label); 00245 virtual void get_sparse_vector_and_label 00246 (SGSparseVectorEntry<uint8_t>*& vector, int32_t& len, float64_t& label); 00247 virtual void get_sparse_vector_and_label 00248 (SGSparseVectorEntry<char>*& vector, int32_t& len, float64_t& label); 00249 virtual void get_sparse_vector_and_label 00250 (SGSparseVectorEntry<int32_t>*& vector, int32_t& len, float64_t& label); 00251 virtual void get_sparse_vector_and_label 00252 (SGSparseVectorEntry<float32_t>*& vector, int32_t& len, float64_t& label); 00253 virtual void get_sparse_vector_and_label 00254 (SGSparseVectorEntry<float64_t>*& vector, int32_t& len, float64_t& label); 00255 virtual void get_sparse_vector_and_label 00256 (SGSparseVectorEntry<int16_t>*& vector, int32_t& len, float64_t& label); 00257 virtual void get_sparse_vector_and_label 00258 (SGSparseVectorEntry<uint16_t>*& vector, int32_t& len, float64_t& label); 00259 virtual void get_sparse_vector_and_label 00260 (SGSparseVectorEntry<int8_t>*& vector, int32_t& len, float64_t& label); 00261 virtual void get_sparse_vector_and_label 00262 (SGSparseVectorEntry<uint32_t>*& vector, int32_t& len, float64_t& label); 00263 virtual void get_sparse_vector_and_label 00264 (SGSparseVectorEntry<int64_t>*& vector, int32_t& len, float64_t& label); 00265 virtual void get_sparse_vector_and_label 00266 (SGSparseVectorEntry<uint64_t>*& vector, int32_t& len, float64_t& label); 00267 virtual void get_sparse_vector_and_label 00268 (SGSparseVectorEntry<floatmax_t>*& vector, int32_t& len, float64_t& label); 00269 00271 00278 virtual void get_vector(VwExample*& ex, int32_t& len); 00279 00287 virtual void get_vector_and_label(VwExample*& ex, int32_t& len, float64_t& label); 00288 00290 inline virtual const char* get_name() const { return "StreamingFile"; } 00291 00292 protected: 00293 00295 CIOBuffer* buf; 00297 char task; 00299 char* filename; 00300 00301 }; 00302 } 00303 #endif //__STREAMING_FILE_H__