// get the ID3tag from the file void get_id3_tag( const char* pFileName, off_t size ){ static char szTitle[31] = {'\0'}; static char szArtist[31] = {'\0'}; static char szAlbum[31] = {'\0'}; static char szYear[5] = {'\0'}; static char szPath[PATH_MAX] = {'\0'}; if( bRelPath ) strcpy( szPath, szRelativePath ); else getcwd( szPath, PATH_MAX ); if( bFsInfo ) // Save file size size_count( size ); get_tags( pFileName, szTitle, szArtist, szAlbum, szYear ); // Try to get all tags if( szTitle[0] == '\0' && szArtist[0] == '\0' && szAlbum[0] == '\0' && szYear[0] == '\0' ){ if( bUseFileName ){ // Use file name to get song infos filename_to_field( pFileName, szTitle, szArtist, szAlbum, szYear ); } else { // print a warning message and return if( bVerbose ) print_message( WARNING, "%s has no id3 Tag\n", pFileName ); } } sql_insert( szTitle, szArtist, szAlbum, szYear, pFileName, szPath, size ); }
dvariable dnorm(const dvector& x, const dvar_vector& mu, const dvar_vector& std) { double pi=3.14159265358979323844; int n=size_count(x); dvar_vector var=square(std); dvar_vector SS=square(x-mu); return(0.5*n*log(2.*pi)+sum(log(std))+0.5*sum(elem_div(SS,var))); }
double eff_N(const dvector& pobs, const dvar_vector& phat) { pobs += 0.0001; phat += 0.0001; dvar_vector rtmp = elem_div((pobs-phat),sqrt(elem_prod(phat,(1-phat)))); double vtmp; vtmp = value(norm2(rtmp)/size_count(rtmp)); return 1./vtmp; }
dvector norm_res(const dvector& pred, const dvector& obs, double m) { RETURN_ARRAYS_INCREMENT(); pred += 0.0001; obs += 0.0001; dvector nr(1,size_count(obs)); nr = elem_div(obs-pred,sqrt(elem_prod(pred,(1.-pred))/m)); RETURN_ARRAYS_DECREMENT(); return nr; }
/** Return computed mean of d3_array array. */ double mean(const d3_array& array) { unsigned int size = size_count(array); if (size == 0) { cerr << "Error: Unable to compute mean of empty d3_array.\n"; ad_exit(1); } return sum(array) / size; }
/** \author Steven James Dean Martell UBC Fisheries Centre \date 2011-06-24 \param k vector of observed numbers \param lambda vector of epected means of the distribution \return returns the negative loglikelihood \f$\sum_i -k_i \ln( \lambda_i ) - \lambda_i + \ln(k_i!) \f$ \sa **/ dvariable dpois(const dvector& k, const dvar_vector& lambda) { RETURN_ARRAYS_INCREMENT(); int i; int n = size_count(k); dvariable nll=0; for(i = 1; i <= n; i++) { // nll -= k(i)*log(lambda(i))+lambda(i)+gammln(k(i)+1.); nll += -k(i)*log(lambda(i))+lambda(i)+gammln(k(i)+1.); } RETURN_ARRAYS_DECREMENT(); return nll; }
/** Return the variable mean of matrix m. */ dvariable mean(const dvar_matrix& m) { dvariable tmp; const unsigned int size = size_count(m); if (size > 0) { tmp = sum(m) / size; } else { cerr << "Error: Unable to compute mean of dvar_matrix.\n"; ad_exit(1); } return tmp; }
/** \author Steven James Dean Martell \date 2011-06-21 \param x a differentiable vector \param mu is a prevariable log mean \param std a prevariable log standard deviation \return returns the negative loglikelihood of the lognormal distribution \sa **/ dvariable dlnorm( const dvar_vector& x, const prevariable& mu, const prevariable& std ) { if( std<=0 || min(x)<=0 ) { cerr<<"Standard deviation or the mix(x) is less than or equal to zero in " "dlnorm( const dvar_vector& x, const dvariable& mu, const dvariable& std )\n"; return 0; } RETURN_ARRAYS_INCREMENT(); long n=size_count(x); dvariable ss = norm2( log(x)-mu ); dvariable t1 = n*(0.5*log(2*M_PI)+log(std)); dvariable nloglike = t1 + sum(log(x)) + ss/(2.*std*std); RETURN_ARRAYS_DECREMENT(); return nloglike; }
TEST_F(test_d3_array, size_count) { d3_array a(1, 4, 1, 3, 1, 2); ASSERT_EQ(24, size_count(a)); }
void param_init_bounded_vector::dev_correction(const dmatrix& H, const int& _ii) { int& ii=(int&) _ii; ii+=size_count(); }
void param_init_d3array::dev_correction(const dmatrix& H, const int& _ii) { int& ii=(int&) _ii; ii+=size_count(); }
/** Return computed mean of d3_array m. */ double mean(const d3_array& m) { double ret = sum(m) / size_count(m); return ret; }
// main int main( int argc, const char* argv[] ){ RETURNCODE ret; pProgramName = argv[0]; bNoSpaceAvailable = FALSE; Mp3Counter = 0; strcpy( szRelativePath, "" ); // initialize the relative path string int mysql_check=0; int sqlite_check=0; #ifndef __MYSQL mysql_check=1; #endif #ifndef __SQLITE sqlite_check=1; #endif if(mysql_check && sqlite_check){ print_message( ERROR, "Program compiled without DB support. Unable to continue.\n"); exit( 0 ); } init(); // init all global variables if( ( ret = check_flag( argc, argv ) ) != PARAM_OK ) print_error( ret ); // output the right message for the error code if( !bNoSpaceAvailable ){ getcwd( szCurrentPath, PATH_MAX ); // save current path VERBOSE_LOG( "Opening DB connection\n" ); if( ( ret = OpenDBConnection() ) != DBOPENED ) // Open DB Connection print_error( ret ); VERBOSE_LOG( "DB connection succeded\n" ); if( bCreateTab ){ VERBOSE_LOG( "Creating new table into DB\n" ); create_table(); VERBOSE_LOG( "Table creation succeded\n" ); } VERBOSE_LOG1( "Changing to %s\n", pPath ); if( chdir( pPath ) != 0 ) // change to pPath print_error( CHDIR_ERROR ); VERBOSE_LOG( "Changed directory\n" ); VERBOSE_LOG( "Start files counting\n" ); if( ( ret = mp3_scan_loop( TRUE ) ) != END_LOOP ) // scan only loop print_error( ret ); if( Mp3Counter > 0 ){ VERBOSE_LOG1( "Found %d file(s)\n", Mp3Counter ); VERBOSE_LOG( "Starting files scan\n" ); if( ( ret = mp3_scan_loop( FALSE ) ) != END_LOOP ) // mp3 scan loop print_error( ret ); VERBOSE_LOG( "Files scan terminated\n" ); if( bFsInfo ) size_count( -1 ); // Print Total files size } else { print_message( ERROR, "No MP3 file found\n" ); } VERBOSE_LOG( "Closing DB connection\n" ); if( ( ret = CloseDBConnection() ) != DBCLOSED ) // close DB connection print_error( ret ); VERBOSE_LOG( "DB connection closed\n" ); VERBOSE_LOG1( "Changing back to %s\n", szCurrentPath ); chdir( szCurrentPath ); // change to initial path } else { print_message( ERROR, "No space available on hard drive to store mp3 infos" ); } if( bUseColor ) printf( "\x1B[0m" ); // reset the shell color scheme exit( 0 ); }