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