SHOGUN  4.1.0
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
宏定义 | 函数
BinaryFile.cpp 文件参考

浏览源代码.

宏定义

#define GET_VECTOR(fname, sg_type, datatype)
 
#define GET_MATRIX(fname, sg_type, datatype)
 
#define GET_NDARRAY(fname, sg_type, datatype)
 
#define GET_SPARSEMATRIX(fname, sg_type, datatype)
 
#define GET_STRING_LIST(fname, sg_type, datatype)
 
#define SET_VECTOR(fname, sg_type, dtype)
 
#define SET_MATRIX(fname, sg_type, dtype)
 
#define SET_NDARRAY(fname, sg_type, datatype)
 
#define SET_SPARSEMATRIX(fname, sg_type, dtype)
 
#define SET_STRING_LIST(fname, sg_type, dtype)
 

函数

 GET_NDARRAY (get_ndarray, uint8_t, TSGDataType(CT_NDARRAY, ST_NONE, PT_UINT8))
 
 GET_NDARRAY (get_ndarray, char, TSGDataType(CT_NDARRAY, ST_NONE, PT_CHAR))
 
 GET_NDARRAY (get_ndarray, int32_t, TSGDataType(CT_NDARRAY, ST_NONE, PT_INT32))
 
 GET_NDARRAY (get_ndarray, int16_t, TSGDataType(CT_NDARRAY, ST_NONE, PT_INT16))
 
 GET_NDARRAY (get_ndarray, uint16_t, TSGDataType(CT_NDARRAY, ST_NONE, PT_UINT16))
 
 GET_NDARRAY (get_ndarray, float32_t, TSGDataType(CT_NDARRAY, ST_NONE, PT_FLOAT32))
 
 GET_NDARRAY (get_ndarray, float64_t, TSGDataType(CT_NDARRAY, ST_NONE, PT_FLOAT64))
 
 SET_NDARRAY (set_ndarray, uint8_t,(CT_NDARRAY, ST_NONE, PT_UINT8))
 
 SET_NDARRAY (set_ndarray, char,(CT_NDARRAY, ST_NONE, PT_CHAR))
 
 SET_NDARRAY (set_ndarray, int32_t,(CT_NDARRAY, ST_NONE, PT_INT32))
 
 SET_NDARRAY (set_ndarray, int16_t,(CT_NDARRAY, ST_NONE, PT_INT16))
 
 SET_NDARRAY (set_ndarray, uint16_t,(CT_NDARRAY, ST_NONE, PT_UINT16))
 
 SET_NDARRAY (set_ndarray, float32_t,(CT_NDARRAY, ST_NONE, PT_FLOAT32))
 
 SET_NDARRAY (set_ndarray, float64_t,(CT_NDARRAY, ST_NONE, PT_FLOAT64))
 

宏定义说明

#define GET_MATRIX (   fname,
  sg_type,
  datatype 
)
值:
void CBinaryFile::fname(sg_type*& matrix, int32_t& num_feat, int32_t& num_vec) \
{ \
if (!file) \
SG_ERROR("File invalid.\n") \
TSGDataType dtype(CT_SCALAR, ST_NONE, PT_BOOL); read_header(&dtype); \
if (dtype!=datatype) \
SG_ERROR("Datatype mismatch\n") \
\
if (fread(&num_feat, sizeof(int32_t), 1, file)!=1 || \
fread(&num_vec, sizeof(int32_t), 1, file)!=1) \
SG_ERROR("Failed to read Matrix dimensions\n") \
matrix=SG_MALLOC(sg_type, int64_t(num_feat)*num_vec); \
if (fread(matrix, sizeof(sg_type)*num_feat, num_vec, file)!=(size_t) num_vec) \
SG_ERROR("Failed to read Matrix\n") \
}
#define SG_ERROR(...)
Definition: SGIO.h:129

在文件 BinaryFile.cpp68 行定义.

#define GET_NDARRAY (   fname,
  sg_type,
  datatype 
)
值:
void CBinaryFile::fname(sg_type *& array, int32_t *& dims,int32_t & num_dims)\
{ \
size_t total = 1; \
\
if (!file) \
SG_ERROR("File invalid.\n") \
\
TSGDataType dtype(CT_SCALAR, ST_NONE, PT_BOOL); \
read_header(&dtype); \
\
if (dtype!=datatype) \
SG_ERROR("Datatype mismatch\n") \
\
if (fread(&num_dims,sizeof(int32_t),1,file) != 1) \
SG_ERROR("Failed to read number of dimensions") \
\
dims = SG_MALLOC(int32_t, num_dims); \
if (fread(dims,sizeof(int32_t),num_dims,file) != (size_t)num_dims) \
SG_ERROR("Failed to read sizes of dimensions!") \
\
for (int32_t i = 0;i < num_dims;i++) \
total *= dims[i]; \
\
array = SG_MALLOC(sg_type, total); \
if (fread(array,sizeof(sg_type),total,file) != (size_t)total) \
SG_ERROR("Failed to read array data!") \
}
#define SG_ERROR(...)
Definition: SGIO.h:129

在文件 BinaryFile.cpp99 行定义.

#define GET_SPARSEMATRIX (   fname,
  sg_type,
  datatype 
)
值:
void CBinaryFile::fname(SGSparseVector<sg_type>*& matrix, int32_t& num_feat, int32_t& num_vec) \
{ \
if (!(file)) \
SG_ERROR("File invalid.\n") \
\
TSGDataType dtype(CT_SCALAR, ST_NONE, PT_BOOL); read_header(&dtype); \
if (dtype!=datatype) \
SG_ERROR("Datatype mismatch\n") \
\
if (fread(&num_vec, sizeof(int32_t), 1, file)!=1) \
SG_ERROR("Failed to read number of vectors\n") \
\
matrix=SG_MALLOC(SGSparseVector<sg_type>, num_vec); \
\
for (int32_t i=0; i<num_vec; i++) \
{ \
new (&matrix[i]) SGSparseVector<sg_type>(); \
int32_t len=0; \
if (fread(&len, sizeof(int32_t), 1, file)!=1) \
SG_ERROR("Failed to read sparse vector length of vector idx=%d\n", i) \
matrix[i].num_feat_entries=len; \
SGSparseVectorEntry<sg_type>* vec = SG_MALLOC(SGSparseVectorEntry<sg_type>, len); \
if (fread(vec, sizeof(SGSparseVectorEntry<sg_type>), len, file)!= (size_t) len) \
SG_ERROR("Failed to read sparse vector %d\n", i) \
matrix[i].features=vec; \
num_feat = CMath::max(num_feat, matrix[i].get_num_dimensions()); \
} \
}
#define SG_ERROR(...)
Definition: SGIO.h:129
template class SGSparseVectorEntry
Definition: File.h:23
template class SGSparseVector The assumtion is that the stored SGSparseVectorEntry* vector is orde...
Matrix::Scalar max(Matrix m)
Definition: Redux.h:66

在文件 BinaryFile.cpp137 行定义.

#define GET_STRING_LIST (   fname,
  sg_type,
  datatype 
)
值:
void CBinaryFile::fname(SGString<sg_type>*& strings, int32_t& num_str, int32_t& max_string_len) \
{ \
strings=NULL; \
num_str=0; \
max_string_len=0; \
\
if (!file) \
SG_ERROR("File invalid.\n") \
\
TSGDataType dtype(CT_SCALAR, ST_NONE, PT_BOOL); read_header(&dtype); \
if (dtype!=datatype) \
SG_ERROR("Datatype mismatch\n") \
\
if (fread(&num_str, sizeof(int32_t), 1, file)!=1) \
SG_ERROR("Failed to read number of strings\n") \
\
strings=SG_MALLOC(SGString<sg_type>, num_str); \
\
for (int32_t i=0; i<num_str; i++) \
{ \
int32_t len=0; \
if (fread(&len, sizeof(int32_t), 1, file)!=1) \
SG_ERROR("Failed to read string length of string with idx=%d\n", i) \
strings[i].slen=len; \
sg_type* str = SG_MALLOC(sg_type, len); \
if (fread(str, sizeof(sg_type), len, file)!= (size_t) len) \
SG_ERROR("Failed to read string %d\n", i) \
strings[i].string=str; \
} \
}
#define SG_ERROR(...)
Definition: SGIO.h:129
shogun string

在文件 BinaryFile.cpp182 行定义.

#define GET_VECTOR (   fname,
  sg_type,
  datatype 
)
值:
void CBinaryFile::fname(sg_type*& vec, int32_t& len) \
{ \
if (!file) \
SG_ERROR("File invalid.\n") \
TSGDataType dtype(CT_SCALAR, ST_NONE, PT_BOOL); read_header(&dtype); \
if (dtype!=datatype) \
SG_ERROR("Datatype mismatch\n") \
\
if (fread(&len, sizeof(int32_t), 1, file)!=1) \
SG_ERROR("Failed to read vector length\n") \
vec=SG_MALLOC(sg_type, len); \
if (fread(vec, sizeof(sg_type), len, file)!=(size_t) len) \
SG_ERROR("Failed to read Matrix\n") \
}
#define SG_ERROR(...)
Definition: SGIO.h:129

在文件 BinaryFile.cpp38 行定义.

#define SET_MATRIX (   fname,
  sg_type,
  dtype 
)
值:
void CBinaryFile::fname(const sg_type* matrix, int32_t num_feat, int32_t num_vec) \
{ \
if (!(file && matrix)) \
SG_ERROR("File or matrix invalid.\n") \
\
TSGDataType t dtype; write_header(&t); \
\
if (fwrite(&num_feat, sizeof(int32_t), 1, file)!=1 || \
fwrite(&num_vec, sizeof(int32_t), 1, file)!=1 || \
fwrite(matrix, sizeof(sg_type)*num_feat, num_vec, file)!=(size_t) num_vec) \
SG_ERROR("Failed to write Matrix\n") \
}
#define SG_ERROR(...)
Definition: SGIO.h:129

在文件 BinaryFile.cpp256 行定义.

#define SET_NDARRAY (   fname,
  sg_type,
  datatype 
)
值:
void CBinaryFile::fname(const sg_type * array, int32_t * dims,int32_t num_dims) \
{ \
size_t total = 1; \
\
if (!file) \
SG_ERROR("File invalid.\n") \
\
if (!array) \
SG_ERROR("Invalid array!\n") \
\
TSGDataType t datatype; \
write_header(&t); \
\
if (fwrite(&num_dims,sizeof(int32_t),1,file) != 1) \
SG_ERROR("Failed to write number of dimensions!\n") \
\
if (fwrite(dims,sizeof(int32_t),num_dims,file) != (size_t)num_dims) \
SG_ERROR("Failed to write sizes of dimensions!\n") \
\
for (int32_t i = 0;i < num_dims;i++) \
total *= dims[i]; \
\
if (fwrite(array,sizeof(sg_type),total,file) != (size_t)total) \
SG_ERROR("Failed to write array data!\n") \
}
#define SG_ERROR(...)
Definition: SGIO.h:129

在文件 BinaryFile.cpp283 行定义.

#define SET_SPARSEMATRIX (   fname,
  sg_type,
  dtype 
)
值:
void CBinaryFile::fname(const SGSparseVector<sg_type>* matrix, \
int32_t num_feat, int32_t num_vec) \
{ \
if (!(file && matrix)) \
SG_ERROR("File or matrix invalid.\n") \
\
TSGDataType t dtype; write_header(&t); \
\
if (fwrite(&num_vec, sizeof(int32_t), 1, file)!=1) \
SG_ERROR("Failed to write Sparse Matrix\n") \
\
for (int32_t i=0; i<num_vec; i++) \
{ \
SGSparseVectorEntry<sg_type>* vec = matrix[i].features; \
int32_t len=matrix[i].num_feat_entries; \
if ((fwrite(&len, sizeof(int32_t), 1, file)!=1) || \
(fwrite(vec, sizeof(SGSparseVectorEntry<sg_type>), len, file)!= (size_t) len)) \
SG_ERROR("Failed to write Sparse Matrix\n") \
} \
}
#define SG_ERROR(...)
Definition: SGIO.h:129
template class SGSparseVectorEntry
Definition: File.h:23
template class SGSparseVector The assumtion is that the stored SGSparseVectorEntry* vector is orde...

在文件 BinaryFile.cpp319 行定义.

#define SET_STRING_LIST (   fname,
  sg_type,
  dtype 
)
值:
void CBinaryFile::fname(const SGString<sg_type>* strings, int32_t num_str) \
{ \
if (!(file && strings)) \
SG_ERROR("File or strings invalid.\n") \
\
TSGDataType t dtype; write_header(&t); \
for (int32_t i=0; i<num_str; i++) \
{ \
int32_t len = strings[i].slen; \
if ((fwrite(&len, sizeof(int32_t), 1, file)!=1) || \
(fwrite(strings[i].string, sizeof(sg_type), len, file)!= (size_t) len)) \
SG_ERROR("Failed to write Sparse Matrix\n") \
} \
}
#define SG_ERROR(...)
Definition: SGIO.h:129
shogun string

在文件 BinaryFile.cpp355 行定义.

#define SET_VECTOR (   fname,
  sg_type,
  dtype 
)
值:
void CBinaryFile::fname(const sg_type* vec, int32_t len) \
{ \
if (!(file && vec)) \
SG_ERROR("File or vector invalid.\n") \
\
TSGDataType t dtype; write_header(&t); \
\
if (fwrite(&len, sizeof(int32_t), 1, file)!=1 || \
fwrite(vec, sizeof(sg_type), len, file)!=(size_t) len) \
SG_ERROR("Failed to write vector\n") \
}
#define SG_ERROR(...)
Definition: SGIO.h:129

set functions - to pass data from shogun to the target interface

在文件 BinaryFile.cpp230 行定义.

函数说明

GET_NDARRAY ( get_ndarray  ,
uint8_t  ,
TSGDataType(CT_NDARRAY, ST_NONE, PT_UINT8)   
)
GET_NDARRAY ( get_ndarray  ,
char  ,
TSGDataType(CT_NDARRAY, ST_NONE, PT_CHAR)   
)
GET_NDARRAY ( get_ndarray  ,
int32_t  ,
TSGDataType(CT_NDARRAY, ST_NONE, PT_INT32)   
)
GET_NDARRAY ( get_ndarray  ,
int16_t  ,
TSGDataType(CT_NDARRAY, ST_NONE, PT_INT16)   
)
GET_NDARRAY ( get_ndarray  ,
uint16_t  ,
TSGDataType(CT_NDARRAY, ST_NONE, PT_UINT16)   
)
GET_NDARRAY ( get_ndarray  ,
float32_t  ,
TSGDataType(CT_NDARRAY, ST_NONE, PT_FLOAT32)   
)
GET_NDARRAY ( get_ndarray  ,
float64_t  ,
TSGDataType(CT_NDARRAY, ST_NONE, PT_FLOAT64)   
)
SET_NDARRAY ( set_ndarray  ,
uint8_t  ,
(CT_NDARRAY, ST_NONE, PT_UINT8)   
)
SET_NDARRAY ( set_ndarray  ,
char  ,
(CT_NDARRAY, ST_NONE, PT_CHAR)   
)
SET_NDARRAY ( set_ndarray  ,
int32_t  ,
(CT_NDARRAY, ST_NONE, PT_INT32)   
)
SET_NDARRAY ( set_ndarray  ,
int16_t  ,
(CT_NDARRAY, ST_NONE, PT_INT16)   
)
SET_NDARRAY ( set_ndarray  ,
uint16_t  ,
(CT_NDARRAY, ST_NONE, PT_UINT16)   
)
SET_NDARRAY ( set_ndarray  ,
float32_t  ,
(CT_NDARRAY, ST_NONE, PT_FLOAT32)   
)
SET_NDARRAY ( set_ndarray  ,
float64_t  ,
(CT_NDARRAY, ST_NONE, PT_FLOAT64)   
)

SHOGUN 机器学习工具包 - 项目文档