20 using namespace shogun;
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);