include/utils.h

Go to the documentation of this file.
00001 /********************************************************************************
00002  *  Neural Network Framework.                                                   *
00003  *  Copyright (C) 2005-2008 Gianluca Massera <emmegian@yahoo.it>                     *
00004  *                                                                              *
00005  *  This program is free software; you can redistribute it and/or modify        *
00006  *  it under the terms of the GNU General Public License as published by        *
00007  *  the Free Software Foundation; either version 2 of the License, or           *
00008  *  (at your option) any later version.                                         *
00009  *                                                                              *
00010  *  This program is distributed in the hope that it will be useful,             *
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of              *
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
00013  *  GNU General Public License for more details.                                *
00014  *                                                                              *
00015  *  You should have received a copy of the GNU General Public License           *
00016  *  along with this program; if not, write to the Free Software                 *
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA  *
00018  ********************************************************************************/
00019 
00020 #ifndef UTILS_H
00021 #define UTILS_H
00022 
00029 #include "types.h"
00030 
00031 #ifndef WIN32
00032     #include <sys/time.h>
00033 #else
00034     #include <windows.h>
00035 #endif
00036 
00037 namespace nnfw {
00038 
00039 class BaseNeuralNet;
00040 class LearningNetwork;
00041 
00052 NNFW_API BaseNeuralNet* feedForwardNet( U_IntVec layers, const char* clusterType = "BiasedCluster", const char* linkerType = "MatrixLinker" );
00053 
00065 class SimpleTimer {
00066 public:
00067     SimpleTimer() {
00068 #ifdef WIN32
00069         QueryPerformanceFrequency( &frequency );
00070         QueryPerformanceCounter( &baseCount );
00071 #else
00072         struct timeval tv;
00073         gettimeofday( &tv, NULL );
00074         lastTime = tv.tv_sec*1000000 + tv.tv_usec;
00075 #endif
00076     };
00077     int tac() {
00078 #ifdef WIN32
00079         unsigned ticks;
00080         QueryPerformanceCounter( &count );
00081         count.QuadPart -= baseCount.QuadPart;
00082         ticks = unsigned( count.QuadPart * LONGLONG (1000000) / frequency.QuadPart );
00083         return ticks;
00084 #else
00085         struct timeval tv;
00086         gettimeofday( &tv, NULL );
00087         int ret = (tv.tv_sec*1000000 + tv.tv_usec) - lastTime;
00088         lastTime = (tv.tv_sec*1000000 + tv.tv_usec);
00089         return ret;
00090 #endif
00091     };
00092 private:
00093 #ifdef WIN32
00094     LARGE_INTEGER count;
00095     LARGE_INTEGER frequency;
00096     LARGE_INTEGER baseCount;
00097 #else
00098     long int lastTime;
00099 #endif
00100 };
00101 
00102 }
00103 
00104 #endif
BerliOS Developer Logo Valid XHTML 1.0 Transitional Valid CSS!