23 using namespace shogun;
44 file=fdopen(fd, mode);
61 if (rw==
'r' || rw ==
'w')
65 if (!(
file=fopen((
const char*)
filename, (
const char*) mode)))
70 SG_ERROR(
"unknown mode '%c'\n", mode[0])
82 vector= SG_MALLOC(
bool, len);
84 for (int32_t i=0; i<len; i++)
85 vector[i]= (int_vector[i]!=0);
92 int32_t* int_vector = SG_MALLOC(int32_t, len);
93 for (int32_t i=0;i<len;i++)
106 uint8_t * byte_matrix;
109 ASSERT(num_feat > 0 && num_vec > 0)
110 matrix = SG_MALLOC(
bool, num_feat*num_vec);
112 for(int32_t i = 0;i < num_vec;i++)
114 for(int32_t j = 0;j < num_feat;j++)
115 matrix[i*num_feat+j] = byte_matrix[i*num_feat+j] != 0 ? 1 : 0;
118 SG_FREE(byte_matrix);
123 uint8_t * byte_matrix = SG_MALLOC(uint8_t, num_feat*num_vec);
124 for(int32_t i = 0;i < num_vec;i++)
126 for(int32_t j = 0;j < num_feat;j++)
127 byte_matrix[i*num_feat+j] = matrix[i*num_feat+j] != 0 ? 1 : 0;
132 SG_FREE(byte_matrix);
137 int32_t& max_string_len)
142 ASSERT(num_str>0 && max_string_len>0)
145 for(int32_t i = 0;i < num_str;i++)
148 strings[i].
string = SG_MALLOC(
bool, strs[i].slen);
149 for(int32_t j = 0;j < strs[i].
slen;j++)
150 strings[i].
string[j] = strs[i].
string[j] != 0 ? 1 : 0;
153 for(int32_t i = 0;i < num_str;i++)
154 SG_FREE(strs[i].
string);
162 for(int32_t i = 0;i < num_str;i++)
165 strs[i].
string = SG_MALLOC(int8_t, strings[i].slen);
166 for(int32_t j = 0;j < strings[i].
slen;j++)
167 strs[i].
string[j] = strings[i].
string[j] != 0 ? 1 : 0;
172 for(int32_t i = 0;i < num_str;i++)
173 SG_FREE(strs[i].
string);
193 #define SPARSE_VECTOR_GETTER(type) \
194 void CFile::set_sparse_vector( \
195 const SGSparseVectorEntry<type>* entries, int32_t num_feat) \
197 SGSparseVector<type> v((SGSparseVectorEntry<type>*) entries, num_feat, false); \
198 set_sparse_matrix(&v, 0, 1); \
201 void CFile::get_sparse_vector( \
202 SGSparseVectorEntry<type>*& entries, int32_t& num_feat) \
204 SGSparseVector<type>* v; \
207 get_sparse_matrix(v, dummy, nvec); \
209 entries=v->features; \
210 num_feat=v->num_feat_entries; \
226 #undef SPARSE_VECTOR_GETTER
231 FILE* tmpf=fopen(fname,
"r");
233 fseek(tmpf,0,SEEK_END);
237 char* result = SG_MALLOC(
char, len);
238 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)
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)