IntFeatures.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "features/IntFeatures.h"
00013 #include "lib/File.h"
00014
00015 bool CIntFeatures::load(char* fname)
00016 {
00017 bool status=false;
00018 num_vectors=1;
00019 num_features=0;
00020 CFile f(fname, 'r', F_INT);
00021 int64_t numf=0;
00022 free_feature_matrix();
00023 feature_matrix=f.load_int_data(NULL, numf);
00024 num_features=numf;
00025
00026
00027 if (!f.is_ok()) {
00028 SG_ERROR( "loading file \"%s\" failed", fname);
00029 }
00030 else
00031 status=true;
00032
00033 return status;
00034 }
00035
00036 bool CIntFeatures::save(char* fname)
00037 {
00038 int32_t len;
00039 bool free;
00040 int32_t* fv;
00041
00042 CFile f(fname, 'w', F_INT);
00043
00044 for (int32_t i=0; i< (int32_t) num_vectors && f.is_ok(); i++)
00045 {
00046 if (!(i % (num_vectors/10+1)))
00047 SG_PRINT( "%02d%%.", (int) (100.0*i/num_vectors));
00048 else if (!(i % (num_vectors/200+1)))
00049 SG_PRINT( ".");
00050
00051 fv=get_feature_vector(i, len, free);
00052 f.save_int_data(fv, len);
00053 free_feature_vector(fv, i, free) ;
00054 }
00055
00056 if (f.is_ok())
00057 SG_INFO( "%d vectors with %d features each successfully written (filesize: %ld)\n", num_vectors, num_features, num_vectors*num_features*sizeof(int32_t));
00058
00059 return true;
00060 }