SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DecompressString.cpp
Go to the documentation of this file.
2 
3 namespace shogun
4 {
5 
7 template <class ST>
9 {
10  compressor=NULL;
11 }
12 
13 template <class ST>
15 {
16  compressor=new CCompressor(ct);
17 }
18 
19 template <class ST>
21 {
22  delete compressor;
23 }
24 
25 template <class ST>
27 {
29  return true;
30 }
31 
32 template <class ST>
34 {
35 }
36 
37 template <class ST>
39 {
42  return false;
43 }
44 
45 template <class ST>
47 {
50  return false;
51 }
52 
53 template <class ST>
55 {
56  int32_t i;
57  int32_t num_vec=((CStringFeatures<ST>*)f)->get_num_vectors();
58 
59  for (i=0; i<num_vec; i++)
60  {
61  int32_t len=0;
62  bool free_vec;
63  ST* vec=((CStringFeatures<ST>*)f)->
64  get_feature_vector(i, len, free_vec);
65 
66  ST* decompressed=apply_to_string(vec, len);
67  ((CStringFeatures<ST>*)f)->
68  free_feature_vector(vec, i, free_vec);
69  ((CStringFeatures<ST>*)f)->
70  cleanup_feature_vector(i);
71  ((CStringFeatures<ST>*)f)->
72  set_feature_vector(i, decompressed, len);
73  }
74  return true;
75 }
76 
77 template <class ST>
79 {
80  uint64_t compressed_size=((int32_t*) f)[0];
81  uint64_t uncompressed_size=((int32_t*) f)[1];
82 
83  int32_t offs=CMath::ceil(2.0*sizeof(int32_t)/sizeof(ST));
84  ASSERT(uint64_t(len)==uint64_t(offs)+compressed_size);
85 
86  len=uncompressed_size;
87  uncompressed_size*=sizeof(ST);
88  ST* vec=SG_MALLOC(ST, len);
89  compressor->decompress((uint8_t*) (&f[offs]), compressed_size,
90  (uint8_t*) vec, uncompressed_size);
91 
92  ASSERT(uncompressed_size==((uint64_t) len)*sizeof(ST));
93  return vec;
94 }
95 
96 template <class ST>
98 {
99  return P_DECOMPRESSSTRING;
100 }
101 
102 template class CDecompressString<bool>;
103 template class CDecompressString<char>;
104 template class CDecompressString<int8_t>;
105 template class CDecompressString<uint8_t>;
106 template class CDecompressString<int16_t>;
107 template class CDecompressString<uint16_t>;
108 template class CDecompressString<int32_t>;
109 template class CDecompressString<uint32_t>;
110 template class CDecompressString<int64_t>;
111 template class CDecompressString<uint64_t>;
112 template class CDecompressString<float32_t>;
113 template class CDecompressString<float64_t>;
114 template class CDecompressString<floatmax_t>;
115 }
#define SG_RESET_LOCALE
Definition: SGIO.h:67
EPreprocessorType
Definition: Preprocessor.h:30
static float64_t ceil(float64_t d)
Definition: Math.h:207
virtual ST * apply_to_string(ST *f, int32_t &len)
apply preproc on single feature vector
bool load(FILE *f)
initialize preprocessor from file
Compression library for compressing and decompressing buffers using one of the standard compression a...
Definition: Compressor.h:49
bool save(FILE *f)
save preprocessor init-data to file
#define SG_SET_LOCALE_C
Definition: SGIO.h:66
#define ASSERT(x)
Definition: SGIO.h:102
Template class StringFeatures implements a list of strings.
Definition: WDSVMOcas.h:23
virtual EFeatureClass get_feature_class()=0
Template class StringPreprocessor, base class for preprocessors (cf. CPreprocessor) that apply to CSt...
virtual bool apply_to_string_features(CFeatures *f)
E_COMPRESSION_TYPE
Definition: Compressor.h:26
The class Features is the base class of all feature objects.
Definition: Features.h:56
virtual void cleanup()
cleanup
Preprocessor that decompresses compressed strings.
virtual EPreprocessorType get_type() const
return a type of preprocessor TODO: template specification of get_type
#define SG_MALLOC(type, len)
Definition: memory.h:36

SHOGUN Machine Learning Toolbox - Documentation