DataType.h

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 2012 Fernando José Iglesias García
00008  * Written (W) 2010,2012 Soeren Sonnenburg
00009  * Copyright (C) 2010 Berlin Institute of Technology
00010  * Copyright (C) 2012 Soeren Sonnenburg
00011  */
00012 
00013 #ifndef __DATATYPE_H__
00014 #define __DATATYPE_H__
00015 
00016 #include <shogun/lib/common.h>
00017 #include <shogun/io/SGIO.h>
00018 
00019 #define PT_NOT_GENERIC  PT_SGOBJECT
00020 #define PT_LONGEST  floatmax_t
00021 
00022 namespace shogun
00023 {
00024 
00025 //class CMath;
00026 template<class T> class CCache;
00027 
00029 typedef int32_t index_t;
00030 
00031 
00032 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00033 enum EContainerType
00034 {
00035     CT_SCALAR=0,
00036     CT_VECTOR=1,
00037     CT_MATRIX=2,
00038     CT_NDARRAY=3,
00039     CT_SGVECTOR=4,
00040     CT_SGMATRIX=5
00041 };
00042 
00043 enum EStructType
00044 {
00045     ST_NONE=0,
00046     ST_STRING=1,
00047     ST_SPARSE=2
00048 };
00049 
00050 enum EPrimitiveType
00051 {
00052     PT_BOOL=0,
00053     PT_CHAR=1,
00054     PT_INT8=2,
00055     PT_UINT8=3,
00056     PT_INT16=4,
00057     PT_UINT16=5,
00058     PT_INT32=6,
00059     PT_UINT32=7,
00060     PT_INT64=8,
00061     PT_UINT64=9,
00062     PT_FLOAT32=10,
00063     PT_FLOAT64=11,
00064     PT_FLOATMAX=12,
00065     PT_SGOBJECT=13
00066 };
00067 #endif
00068 
00070 struct TSGDataType
00071 {
00073     EContainerType m_ctype;
00075     EStructType m_stype;
00077     EPrimitiveType m_ptype;
00078 
00080     index_t *m_length_y;
00082     index_t *m_length_x;
00083 
00089     explicit TSGDataType(EContainerType ctype, EStructType stype,
00090                          EPrimitiveType ptype);
00097     explicit TSGDataType(EContainerType ctype, EStructType stype,
00098                          EPrimitiveType ptype, index_t* length);
00106     explicit TSGDataType(EContainerType ctype, EStructType stype,
00107                          EPrimitiveType ptype, index_t* length_y,
00108                          index_t* length_x);
00109 
00111     bool operator==(const TSGDataType& a);
00115     inline bool operator!=(const TSGDataType& a)
00116     {
00117         return !(*this == a);
00118     }
00119 
00124     void to_string(char* dest, size_t n) const;
00125 
00127     size_t sizeof_stype() const;
00129     size_t sizeof_ptype() const;
00130 
00134     static size_t sizeof_sparseentry(EPrimitiveType ptype);
00135 
00139     static size_t offset_sparseentry(EPrimitiveType ptype);
00140 
00147     static void stype_to_string(char* dest, EStructType stype,
00148                                 EPrimitiveType ptype, size_t n);
00154     static void ptype_to_string(char* dest, EPrimitiveType ptype,
00155                                 size_t n);
00160     static bool string_to_ptype(EPrimitiveType* ptype,
00161                                 const char* str);
00162 
00166     size_t get_size();
00167 
00171     index_t get_num_elements();
00172 };
00173 }
00174 #endif /* __DATATYPE_H__  */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation