41 file=fdopen(fd, mode);
58 if (rw==
'r' || rw ==
'w')
62 if (!(
file=fopen((
const char*)
filename, (
const char*) mode)))
67 SG_ERROR(
"unknown mode '%c'\n", mode[0])
79 vector= SG_MALLOC(
bool, len);
81 for (int32_t i=0; i<len; i++)
82 vector[i]= (int_vector[i]!=0);
89 int32_t* int_vector = SG_MALLOC(int32_t, len);
90 for (int32_t i=0;i<len;i++)
103 uint8_t * byte_matrix;
106 ASSERT(num_feat > 0 && num_vec > 0)
107 matrix = SG_MALLOC(
bool, num_feat*num_vec);
109 for(int32_t i = 0;i < num_vec;i++)
111 for(int32_t j = 0;j < num_feat;j++)
112 matrix[i*num_feat+j] = byte_matrix[i*num_feat+j] != 0 ? 1 : 0;
115 SG_FREE(byte_matrix);
120 uint8_t * byte_matrix = SG_MALLOC(uint8_t, num_feat*num_vec);
121 for(int32_t i = 0;i < num_vec;i++)
123 for(int32_t j = 0;j < num_feat;j++)
124 byte_matrix[i*num_feat+j] = matrix[i*num_feat+j] != 0 ? 1 : 0;
129 SG_FREE(byte_matrix);
134 int32_t& max_string_len)
139 ASSERT(num_str>0 && max_string_len>0)
142 for(int32_t i = 0;i < num_str;i++)
145 strings[i].
string = SG_MALLOC(
bool, strs[i].slen);
146 for(int32_t j = 0;j < strs[i].
slen;j++)
147 strings[i].
string[j] = strs[i].
string[j] != 0 ? 1 : 0;
150 for(int32_t i = 0;i < num_str;i++)
151 SG_FREE(strs[i].
string);
159 for(int32_t i = 0;i < num_str;i++)
162 strs[i].
string = SG_MALLOC(int8_t, strings[i].slen);
163 for(int32_t j = 0;j < strings[i].
slen;j++)
164 strs[i].
string[j] = strings[i].
string[j] != 0 ? 1 : 0;
169 for(int32_t i = 0;i < num_str;i++)
170 SG_FREE(strs[i].
string);
190 #define SPARSE_VECTOR_GETTER(type) \ 191 void CFile::set_sparse_vector( \ 192 const SGSparseVectorEntry<type>* entries, int32_t num_feat) \ 194 SGSparseVector<type> v((SGSparseVectorEntry<type>*) entries, num_feat, false); \ 195 set_sparse_matrix(&v, 0, 1); \ 198 void CFile::get_sparse_vector( \ 199 SGSparseVectorEntry<type>*& entries, int32_t& num_feat) \ 201 SGSparseVector<type>* v; \ 204 get_sparse_matrix(v, dummy, nvec); \ 206 entries=v->features; \ 207 num_feat=v->num_feat_entries; \ 223 #undef SPARSE_VECTOR_GETTER 228 FILE* tmpf=fopen(fname,
"r");
230 fseek(tmpf,0,SEEK_END);
234 char* result = SG_MALLOC(
char, len);
235 size_t total=fread(result,1,len,tmpf);
virtual void set_matrix(const bool *matrix, int32_t num_feat, int32_t num_vec)
#define SPARSE_VECTOR_GETTER(type)
virtual void set_string_list(const SGString< bool > *strings, int32_t num_str)
Class SGObject is the base class of all shogun objects.
virtual void get_vector(bool *&vector, int32_t &len)
virtual void get_matrix(bool *&matrix, int32_t &num_feat, int32_t &num_vec)
all of classes and functions are contained in the shogun namespace
char * get_variable_name()
static char * read_whole_file(char *fname, size_t &len)
virtual void get_string_list(SGString< bool > *&strings, int32_t &num_str, int32_t &max_string_len)
virtual void set_vector(const bool *vector, int32_t len)
void set_variable_name(const char *name)