SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DataType.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2012 Fernando Jose Iglesias Garcia
8  * Written (W) 2010,2012 Soeren Sonnenburg
9  * Written (W) 2011-2013 Heiko Strathmann
10  * Copyright (C) 2010 Berlin Institute of Technology
11  * Copyright (C) 2012 Soeren Sonnenburg
12  */
13 
14 #ifndef __DATATYPE_H__
15 #define __DATATYPE_H__
16 
17 #include <shogun/lib/common.h>
18 #include <shogun/io/SGIO.h>
19 
20 #define PT_NOT_GENERIC PT_SGOBJECT
21 
22 namespace shogun
23 {
24 
25 #ifndef DOXYGEN_SHOULD_SKIP_THIS
26 enum EContainerType
27 {
28  CT_SCALAR=0,
29  CT_VECTOR=1,
30  CT_MATRIX=2,
31  CT_NDARRAY=3,
32  CT_SGVECTOR=4,
33  CT_SGMATRIX=5,
34  CT_UNDEFINED=6
35 };
36 
37 enum EStructType
38 {
39  ST_NONE=0,
40  ST_STRING=1,
41  ST_SPARSE=2,
42  ST_UNDEFINED=3
43 };
44 
45 enum EPrimitiveType
46 {
47  PT_BOOL=0,
48  PT_CHAR=1,
49  PT_INT8=2,
50  PT_UINT8=3,
51  PT_INT16=4,
52  PT_UINT16=5,
53  PT_INT32=6,
54  PT_UINT32=7,
55  PT_INT64=8,
56  PT_UINT64=9,
57  PT_FLOAT32=10,
58  PT_FLOAT64=11,
59  PT_FLOATMAX=12,
60  PT_SGOBJECT=13,
61  PT_COMPLEX128=14,
62  PT_UNDEFINED=15
63 };
64 #endif
65 
68 {
70  EContainerType m_ctype;
72  EStructType m_stype;
74  EPrimitiveType m_ptype;
75 
80 
86  explicit TSGDataType(EContainerType ctype, EStructType stype,
87  EPrimitiveType ptype);
94  explicit TSGDataType(EContainerType ctype, EStructType stype,
95  EPrimitiveType ptype, index_t* length);
103  explicit TSGDataType(EContainerType ctype, EStructType stype,
104  EPrimitiveType ptype, index_t* length_y,
105  index_t* length_x);
106 
112  bool equals(TSGDataType other);
113 
119 
121  bool operator==(const TSGDataType& a);
125  inline bool operator!=(const TSGDataType& a)
126  {
127  return !(*this == a);
128  }
129 
134  void to_string(char* dest, size_t n) const;
135 
137  size_t sizeof_stype() const;
139  size_t sizeof_ptype() const;
140 
141  static size_t sizeof_ptype(EPrimitiveType ptype);
142  static size_t sizeof_stype(EStructType stype, EPrimitiveType ptype);
143 
147  static size_t sizeof_sparseentry(EPrimitiveType ptype);
148 
152  static size_t offset_sparseentry(EPrimitiveType ptype);
153 
160  static void stype_to_string(char* dest, EStructType stype,
161  EPrimitiveType ptype, size_t n);
167  static void ptype_to_string(char* dest, EPrimitiveType ptype,
168  size_t n);
173  static bool string_to_ptype(EPrimitiveType* ptype,
174  const char* str);
175 
179  size_t get_size();
180 
184  int64_t get_num_elements();
185 };
186 }
187 #endif /* __DATATYPE_H__ */

SHOGUN Machine Learning Toolbox - Documentation