SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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  CSGObject::set_generic<ST>();
12 }
13 
14 template <class ST>
16 {
17  compressor=new CCompressor(ct);
18  CSGObject::set_generic<ST>();
19 }
20 
21 template <class ST>
23 {
24  delete compressor;
25 }
26 
27 template <class ST>
29 {
31  return true;
32 }
33 
34 template <class ST>
36 {
37 }
38 
39 template <class ST>
41 {
44  return false;
45 }
46 
47 template <class ST>
49 {
52  return false;
53 }
54 
55 template <class ST>
57 {
58  int32_t i;
59  int32_t num_vec=((CStringFeatures<ST>*)f)->get_num_vectors();
60 
61  for (i=0; i<num_vec; i++)
62  {
63  int32_t len=0;
64  bool free_vec;
65  ST* vec=((CStringFeatures<ST>*)f)->
66  get_feature_vector(i, len, free_vec);
67 
68  ST* decompressed=apply_to_string(vec, len);
69  ((CStringFeatures<ST>*)f)->
70  free_feature_vector(vec, i, free_vec);
71  ((CStringFeatures<ST>*)f)->
72  cleanup_feature_vector(i);
73  ((CStringFeatures<ST>*)f)->
74  set_feature_vector(i, decompressed, len);
75  }
76  return true;
77 }
78 
79 template <class ST>
81 {
82  uint64_t compressed_size=((int32_t*) f)[0];
83  uint64_t uncompressed_size=((int32_t*) f)[1];
84 
85  int32_t offs=CMath::ceil(2.0*sizeof(int32_t)/sizeof(ST));
86  ASSERT(uint64_t(len)==uint64_t(offs)+compressed_size)
87 
88  len=uncompressed_size;
89  uncompressed_size*=sizeof(ST);
90  ST* vec=SG_MALLOC(ST, len);
91  compressor->decompress((uint8_t*) (&f[offs]), compressed_size,
92  (uint8_t*) vec, uncompressed_size);
93 
94  ASSERT(uncompressed_size==((uint64_t) len)*sizeof(ST))
95  return vec;
96 }
97 
98 template <class ST>
100 {
101  return P_DECOMPRESSSTRING;
102 }
103 
104 template class CDecompressString<bool>;
105 template class CDecompressString<char>;
106 template class CDecompressString<int8_t>;
107 template class CDecompressString<uint8_t>;
108 template class CDecompressString<int16_t>;
109 template class CDecompressString<uint16_t>;
110 template class CDecompressString<int32_t>;
111 template class CDecompressString<uint32_t>;
112 template class CDecompressString<int64_t>;
113 template class CDecompressString<uint64_t>;
114 template class CDecompressString<float32_t>;
115 template class CDecompressString<float64_t>;
116 template class CDecompressString<floatmax_t>;
117 }
#define SG_RESET_LOCALE
Definition: SGIO.h:86
EPreprocessorType
Definition: Preprocessor.h:32
Template class StringFeatures implements a list of strings.
static float64_t ceil(float64_t d)
Definition: Math.h:416
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:46
bool save(FILE *f)
save preprocessor init-data to file
#define SG_SET_LOCALE_C
Definition: SGIO.h:85
#define ASSERT(x)
Definition: SGIO.h:201
virtual EFeatureClass get_feature_class() const =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:21
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
The class Features is the base class of all feature objects.
Definition: Features.h:68
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

SHOGUN Machine Learning Toolbox - Documentation