File: general.h

package info (click to toggle)
torch 2-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 5,488 kB
  • ctags: 3,217
  • sloc: cpp: 14,272; makefile: 201
file content (187 lines) | stat: -rw-r--r-- 4,747 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// Copyright (C) 2002 Ronan Collobert (collober@iro.umontreal.ca)
//                
//
// This file is part of Torch. Release II.
// [The Ultimate Machine Learning Library]
//
// Torch is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Torch is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Torch; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

#ifndef GENERAL_INC
#define GENERAL_INC

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>
#include <stdarg.h>
#include <time.h>
#include <sys/times.h>
#include <float.h>

// Old systems need that to define FLT_MAX and DBL_MAX
#ifndef DBL_MAX
#include <values.h>
#endif

namespace Torch {

#ifdef USEDOUBLE
#define INF DBL_MAX
#define REAL_EPSILON DBL_EPSILON
#define real double
#else
#define INF FLT_MAX
#define REAL_EPSILON FLT_EPSILON
#define real float
#endif

/** Sparse definition.
    @author Ronan Collobert (collober@iro.umontreal.ca)
*/
struct sreal
{
    /// Index which is not zero.
    int index;
    /// Value of this index.
    real value;
};

/** Return the size of a sparse vector #line#.

    @author Ronan Collobert (collober@iro.umontreal.ca)
*/
int sparseVectorLength(sreal *line);
//-----------------------------------

//- IO ------------------------------

/** Several functions for Inputs/Ouputs on disk.

    @author Ronan Collobert (collober@iro.umontreal.ca)
 */
//@{

/// Returns #true# if the computer use the Little Endian coding.
bool isLittleEndian();
/// Returns #true# if we'll load/save using the native mode
bool isNativeMode();
/// We'll load/save in native mode.
void setNativeMode();
/// We'll load/save in Little Endian mode.
void setLittleEndianMode();
/// We'll load/save in Big Endian mode.
void setBigEndianMode();
/** Reverse #n_blocks# of memory starting from #ptr_#.
    In each block of size #block_size#, reverse
    the memory byte per byte.
*/
void reverseMemory(void *ptr_, int block_size, int n_blocks);

/** As #fread()#, but reverse the memory if it has been specified
    with #setNativeMode()#, #setLittleEndianMode()# or
    #setBigEndianMode()#.
*/
int xfread(void *ptr, int block_size, int n_blocks, FILE *f);
/** As #fwrite()#, but reverse the memory if it has been specified
    with #setNativeMode()#, #setLittleEndianMode()# or
    #setBigEndianMode()#.
*/
int xfwrite(void *ptr, int block_size, int n_blocks, FILE *f);
//@}
//-----------------------------------

//- Divers --------------------------

/// Memory functions
//@{

/** As #malloc()#, but send an error message if there
    is no more memory.

    @author Ronan Collobert (collober@iro.umontreal.ca)
*/
void *xalloc(int size);

/** As #calloc()#, but send an error message if there
    is no more memory.

    @author Ronan Collobert (collober@iro.umontreal.ca)
*/
void *xcalloc(int n_blocks, int size);

/** Almost as #realloc()#, but send an error message if there
    is no more memory.
    Use #free()# is #size# is #0#.

    @author Ronan Collobert (collober@iro.umontreal.ca)
*/
void *xrealloc(void *ptr, int size);
//@}


/** Text outputs functions.

    These functions are like #printf()#, but you should
    use them instead. Note that you should never try to
    print a message larger than 10000 characters.

    @author Ronan Collobert (collober@iro.umontreal.ca)
 */
//@{

/// Print an error message. The program will exit.
void error(const char* msg, ...);
/// Print a warning message.
void warning(const char* msg, ...);
/// Print a message.
void message(const char* msg, ...);
/// Like printf.
void print(const char* msg, ...);

/** Print a control bar [\#\#\#\#\#\#\#\#\#\#].
    
    First time, you can it with #level=-1#.
    It'll print the control bar at each time
    you will call that.

    #max_level# is the value of the last #level#
    you'll call this function.

    @author Ronan Collobert (collober@iro.umontreal.ca)
 */
void controlBar(int level, int max_level);
//@}

/** Return the time in CLOCKS_PER_SEC

    @author Ronan Collobert (collober@iro.umontreal.ca)
*/
long getRuntime(void);

#ifndef min
/// The min function
#define	min(a,b) ((a) > (b) ? (b) : (a))
#endif

#ifndef max
/// The max function
#define	max(a,b) ((a) > (b) ? (a) : (b))
#endif


}

#endif