Added #include <unistd.h> for nice().
[mlp.git] / misc.h
1 /*
2  *  mlp-mnist is an implementation of a multi-layer neural network.
3  *
4  *  Copyright (c) 2006 École Polytechnique Fédérale de Lausanne,
5  *  http://www.epfl.ch
6  *
7  *  Written by Francois Fleuret <francois@fleuret.org>
8  *
9  *  This file is part of mlp-mnist.
10  *
11  *  mlp-mnist is free software: you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License version 3 as
13  *  published by the Free Software Foundation.
14  *
15  *  mlp-mnist is distributed in the hope that it will be useful, but
16  *  WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  *  General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with mlp-mnist.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24
25 #ifndef MISC_H
26 #define MISC_H
27
28 #ifdef DEBUG
29 #define ASSERT(x, s) if(!(x)) { std::cerr << "ASSERT FAILED IN " << __FILE__ << ":" << __LINE__ << " [" << (s) << "]\n"; abort(); }
30 #else
31 #define ASSERT(x, s)
32 #endif
33
34 const int buffer_size = 1024;
35
36 typedef float scalar_t;
37
38 template<class T> T sq(T x) { return x*x; }
39
40 template<class T> T pos(T x) { if(x < 0) return 0.0; else return x; }
41
42 struct Couple {
43   int index;
44   double value;
45 };
46
47 int compare_couple(const void *a, const void *b);
48
49 int factorial(int k);
50
51 #endif