Go to the source code of this file.
Defines | |
#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) |
Functions | |
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"); \ }
Definition at line 59 of file BinaryFile.cpp.
#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!"); \ }
Definition at line 90 of file BinaryFile.cpp.
#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++) \ { \ 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; \ } \ }
Definition at line 128 of file BinaryFile.cpp.
#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; \ } \ }
Definition at line 171 of file BinaryFile.cpp.
#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"); \ }
Definition at line 34 of file BinaryFile.cpp.
#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"); \ }
Definition at line 240 of file BinaryFile.cpp.
#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"); \ }
Definition at line 267 of file BinaryFile.cpp.
#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"); \ } \ }
Definition at line 303 of file BinaryFile.cpp.
#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"); \ } \ }
Definition at line 339 of file BinaryFile.cpp.
#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"); \ }
set functions - to pass data from shogun to the target interface
Definition at line 219 of file BinaryFile.cpp.
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 | , | |
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 | , | |
int32_t | , | |||
TSGDataType(CT_NDARRAY, ST_NONE, PT_INT32) | ||||
) |
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 | , | |
int32_t | , | |||
(CT_NDARRAY, ST_NONE, PT_INT32) | ||||
) |
SET_NDARRAY | ( | set_ndarray | , | |
int16_t | , | |||
(CT_NDARRAY, ST_NONE, PT_INT16) | ||||
) |
SET_NDARRAY | ( | set_ndarray | , | |
float32_t | , | |||
(CT_NDARRAY, ST_NONE, PT_FLOAT32) | ||||
) |
SET_NDARRAY | ( | set_ndarray | , | |
float64_t | , | |||
(CT_NDARRAY, ST_NONE, PT_FLOAT64) | ||||
) |
SET_NDARRAY | ( | set_ndarray | , | |
char | , | |||
(CT_NDARRAY, ST_NONE, PT_CHAR) | ||||
) |
SET_NDARRAY | ( | set_ndarray | , | |
uint16_t | , | |||
(CT_NDARRAY, ST_NONE, PT_UINT16) | ||||
) |