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) 2010 Soeren Sonnenburg
00008  * Copyright (C) 2010 Berlin Institute of Technology
00009  */
00010 
00011 #ifndef __DATATYPE_H__
00012 #define __DATATYPE_H__
00013 
00014 #include "lib/common.h"
00015 
00016 #define PT_NOT_GENERIC             PT_SGOBJECT
00017 #define PT_LONGEST                 floatmax_t
00018 
00019 namespace shogun
00020 {
00021 
00022 typedef int32_t                    index_t;
00023 
00024 template<class T> struct TString {
00026     T* string;
00028     index_t length;
00029 };
00030 
00032 template <class T> struct TSparseEntry {
00034     index_t feat_index;
00036     T entry;
00037 };
00038 
00040 template <class T> struct TSparse {
00042     index_t vec_index;
00044     index_t num_feat_entries;
00046     TSparseEntry<T>* features;
00047 };
00048 
00049 enum EContainerType {
00050     CT_SCALAR, CT_VECTOR, CT_MATRIX
00051 };
00052 
00053 enum EStructType {
00054     ST_NONE, ST_STRING, ST_SPARSE
00055 };
00056 
00057 enum EPrimitiveType {
00058     PT_BOOL, PT_CHAR, PT_INT8, PT_UINT8, PT_INT16, PT_UINT16, PT_INT32,
00059     PT_UINT32, PT_INT64, PT_UINT64, PT_FLOAT32, PT_FLOAT64, PT_FLOATMAX,
00060     PT_SGOBJECT
00061 };
00062 
00063 /* Datatypes that shogun supports. */
00064 struct TSGDataType
00065 {
00066     EContainerType m_ctype;
00067     EStructType m_stype;
00068     EPrimitiveType m_ptype;
00069     index_t *m_length_y, *m_length_x;
00070 
00071     explicit TSGDataType(EContainerType ctype, EStructType stype,
00072                          EPrimitiveType ptype);
00073     explicit TSGDataType(EContainerType ctype, EStructType stype,
00074                          EPrimitiveType ptype, index_t* length);
00075     explicit TSGDataType(EContainerType ctype, EStructType stype,
00076                          EPrimitiveType ptype, index_t* length_y,
00077                          index_t* length_x);
00078 
00079     bool operator==(const TSGDataType& a);
00080     inline bool operator!=(const TSGDataType& a) {
00081         return !(*this == a);
00082     }
00083 
00084     void to_string(char* dest, size_t n) const;
00085     size_t sizeof_stype(void) const;
00086     size_t sizeof_ptype(void) const;
00087 
00088     static size_t sizeof_sparseentry(EPrimitiveType ptype);
00089     static size_t offset_sparseentry(EPrimitiveType ptype);
00090 
00091     static void stype_to_string(char* dest, EStructType stype,
00092                                 EPrimitiveType ptype, size_t n);
00093     static void ptype_to_string(char* dest, EPrimitiveType ptype,
00094                                 size_t n);
00095     static bool string_to_ptype(EPrimitiveType* result,
00096                                 const char* str);
00097 };
00098 }
00099 #endif /* __DATATYPE_H__  */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation