47 file=fdopen(fd, mode);
66 if (rw==
'r' || rw ==
'w')
70 if (!(
file=fopen((
const char*)
filename, (
const char*) mode)))
75 SG_ERROR(
"unknown mode '%c'\n", mode[0])
87 vector= SG_MALLOC(
bool, len);
89 for (int32_t i=0; i<len; i++)
90 vector[i]= (int_vector[i]!=0);
97 int32_t* int_vector = SG_MALLOC(int32_t, len);
98 for (int32_t i=0;i<len;i++)
111 uint8_t * byte_matrix;
114 ASSERT(num_feat > 0 && num_vec > 0)
115 matrix = SG_MALLOC(
bool, num_feat*num_vec);
117 for(int32_t i = 0;i < num_vec;i++)
119 for(int32_t j = 0;j < num_feat;j++)
120 matrix[i*num_feat+j] = byte_matrix[i*num_feat+j] != 0 ? 1 : 0;
123 SG_FREE(byte_matrix);
128 uint8_t * byte_matrix = SG_MALLOC(uint8_t, num_feat*num_vec);
129 for(int32_t i = 0;i < num_vec;i++)
131 for(int32_t j = 0;j < num_feat;j++)
132 byte_matrix[i*num_feat+j] = matrix[i*num_feat+j] != 0 ? 1 : 0;
137 SG_FREE(byte_matrix);
142 int32_t& max_string_len)
147 ASSERT(num_str>0 && max_string_len>0)
150 for(int32_t i = 0;i < num_str;i++)
153 strings[i].
string = SG_MALLOC(
bool, strs[i].slen);
154 for(int32_t j = 0;j < strs[i].
slen;j++)
155 strings[i].
string[j] = strs[i].
string[j] != 0 ? 1 : 0;
158 for(int32_t i = 0;i < num_str;i++)
159 SG_FREE(strs[i].
string);
167 for(int32_t i = 0;i < num_str;i++)
170 strs[i].
string = SG_MALLOC(int8_t, strings[i].slen);
171 for(int32_t j = 0;j < strings[i].
slen;j++)
172 strs[i].
string[j] = strings[i].
string[j] != 0 ? 1 : 0;
177 for(int32_t i = 0;i < num_str;i++)
178 SG_FREE(strs[i].
string);
198 #define SPARSE_VECTOR_GETTER(type) \
199 void CFile::set_sparse_vector( \
200 const SGSparseVectorEntry<type>* entries, int32_t num_feat) \
202 SGSparseVector<type> v((SGSparseVectorEntry<type>*) entries, num_feat, false); \
203 set_sparse_matrix(&v, 0, 1); \
206 void CFile::get_sparse_vector( \
207 SGSparseVectorEntry<type>*& entries, int32_t& num_feat) \
209 SGSparseVector<type>* v; \
212 get_sparse_matrix(v, dummy, nvec); \
214 entries=v->features; \
215 num_feat=v->num_feat_entries; \
231 #undef SPARSE_VECTOR_GETTER
236 FILE* tmpf=fopen(fname,
"r");
238 fseek(tmpf,0,SEEK_END);
242 char* result = SG_MALLOC(
char, len);
243 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)