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_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_SPARSEMATRIX(fname, sg_type, dtype) |
#define | SET_STRING_LIST(fname, sg_type, dtype) |
#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=new 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_SPARSEMATRIX | ( | fname, | ||
sg_type, | ||||
datatype | ||||
) |
void CBinaryFile::fname(TSparse<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=new TSparse<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; \ TSparseEntry<sg_type>* vec = new TSparseEntry<sg_type>[len]; \ if (fread(vec, sizeof(TSparseEntry<sg_type>), len, file)!= (size_t) len) \ SG_ERROR("Failed to read sparse vector %d\n", i); \ matrix[i].features=vec; \ } \ }
Definition at line 118 of file BinaryFile.cpp.
#define GET_STRING_LIST | ( | fname, | ||
sg_type, | ||||
datatype | ||||
) |
void CBinaryFile::fname(TString<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=new TString<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].length=len; \ sg_type* str = new 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 161 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=new 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 230 of file BinaryFile.cpp.
#define SET_SPARSEMATRIX | ( | fname, | ||
sg_type, | ||||
dtype | ||||
) |
void CBinaryFile::fname(const TSparse<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++) \ { \ TSparseEntry<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(TSparseEntry<sg_type>), len, file)!= (size_t) len)) \ SG_ERROR("Failed to write Sparse Matrix\n"); \ } \ }
Definition at line 257 of file BinaryFile.cpp.
#define SET_STRING_LIST | ( | fname, | ||
sg_type, | ||||
dtype | ||||
) |
void CBinaryFile::fname(const TString<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].length; \ 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 293 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 209 of file BinaryFile.cpp.