SHOGUN
v3.2.0
|
00001 #include <shogun/preprocessor/DecompressString.h> 00002 00003 namespace shogun 00004 { 00005 00007 template <class ST> 00008 CDecompressString<ST>::CDecompressString() : CStringPreprocessor<ST>() 00009 { 00010 compressor=NULL; 00011 CSGObject::set_generic<ST>(); 00012 } 00013 00014 template <class ST> 00015 CDecompressString<ST>::CDecompressString(E_COMPRESSION_TYPE ct) : CStringPreprocessor<ST>() 00016 { 00017 compressor=new CCompressor(ct); 00018 CSGObject::set_generic<ST>(); 00019 } 00020 00021 template <class ST> 00022 CDecompressString<ST>::~CDecompressString() 00023 { 00024 delete compressor; 00025 } 00026 00027 template <class ST> 00028 bool CDecompressString<ST>::init(CFeatures* f) 00029 { 00030 ASSERT(f->get_feature_class()==C_STRING) 00031 return true; 00032 } 00033 00034 template <class ST> 00035 void CDecompressString<ST>::cleanup() 00036 { 00037 } 00038 00039 template <class ST> 00040 bool CDecompressString<ST>::load(FILE* f) 00041 { 00042 SG_SET_LOCALE_C; 00043 SG_RESET_LOCALE; 00044 return false; 00045 } 00046 00047 template <class ST> 00048 bool CDecompressString<ST>::save(FILE* f) 00049 { 00050 SG_SET_LOCALE_C; 00051 SG_RESET_LOCALE; 00052 return false; 00053 } 00054 00055 template <class ST> 00056 bool CDecompressString<ST>::apply_to_string_features(CFeatures* f) 00057 { 00058 int32_t i; 00059 int32_t num_vec=((CStringFeatures<ST>*)f)->get_num_vectors(); 00060 00061 for (i=0; i<num_vec; i++) 00062 { 00063 int32_t len=0; 00064 bool free_vec; 00065 ST* vec=((CStringFeatures<ST>*)f)-> 00066 get_feature_vector(i, len, free_vec); 00067 00068 ST* decompressed=apply_to_string(vec, len); 00069 ((CStringFeatures<ST>*)f)-> 00070 free_feature_vector(vec, i, free_vec); 00071 ((CStringFeatures<ST>*)f)-> 00072 cleanup_feature_vector(i); 00073 ((CStringFeatures<ST>*)f)-> 00074 set_feature_vector(i, decompressed, len); 00075 } 00076 return true; 00077 } 00078 00079 template <class ST> 00080 ST* CDecompressString<ST>::apply_to_string(ST* f, int32_t &len) 00081 { 00082 uint64_t compressed_size=((int32_t*) f)[0]; 00083 uint64_t uncompressed_size=((int32_t*) f)[1]; 00084 00085 int32_t offs=CMath::ceil(2.0*sizeof(int32_t)/sizeof(ST)); 00086 ASSERT(uint64_t(len)==uint64_t(offs)+compressed_size) 00087 00088 len=uncompressed_size; 00089 uncompressed_size*=sizeof(ST); 00090 ST* vec=SG_MALLOC(ST, len); 00091 compressor->decompress((uint8_t*) (&f[offs]), compressed_size, 00092 (uint8_t*) vec, uncompressed_size); 00093 00094 ASSERT(uncompressed_size==((uint64_t) len)*sizeof(ST)) 00095 return vec; 00096 } 00097 00098 template <class ST> 00099 EPreprocessorType CDecompressString<ST>::get_type() const 00100 { 00101 return P_DECOMPRESSSTRING; 00102 } 00103 00104 template class CDecompressString<bool>; 00105 template class CDecompressString<char>; 00106 template class CDecompressString<int8_t>; 00107 template class CDecompressString<uint8_t>; 00108 template class CDecompressString<int16_t>; 00109 template class CDecompressString<uint16_t>; 00110 template class CDecompressString<int32_t>; 00111 template class CDecompressString<uint32_t>; 00112 template class CDecompressString<int64_t>; 00113 template class CDecompressString<uint64_t>; 00114 template class CDecompressString<float32_t>; 00115 template class CDecompressString<float64_t>; 00116 template class CDecompressString<floatmax_t>; 00117 }