Seems to work quite well.
[flatland.git] / misc.h
1
2 /*
3  *  dyncnn is a deep-learning algorithm for the prediction of
4  *  interacting object dynamics
5  *
6  *  Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/
7  *  Written by Francois Fleuret <francois.fleuret@idiap.ch>
8  *
9  *  This file is part of dyncnn.
10  *
11  *  dyncnn is free software: you can redistribute it and/or modify it
12  *  under the terms of the GNU General Public License version 3 as
13  *  published by the Free Software Foundation.
14  *
15  *  dyncnn 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 dyncnn.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24
25 #ifndef MISC_H
26 #define MISC_H
27
28 #include <float.h>
29 #include <stdlib.h>
30
31 #ifdef DEBUG
32 #define ASSERT(x, s) if(!(x)) { std::cerr << "ASSERT FAILED IN " << __FILE__ << ":" << __LINE__ << " [" << (s) << "]\n"; abort(); }
33 #else
34 #define ASSERT(x, s)
35 #endif
36
37 // typedef float scalar_t;
38 typedef double scalar_t;
39
40 inline scalar_t sq(scalar_t x) { return x*x; }
41
42 inline scalar_t prod_vect(scalar_t x1, scalar_t y1, scalar_t x2, scalar_t y2) {
43   return x1 * y2 - x2 * y1;
44 }
45
46 struct Couple {
47   int index;
48   scalar_t value;
49 };
50
51 int compare_couple(const void *a, const void *b);
52
53 #endif