-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMathUtils.h
57 lines (44 loc) · 1.04 KB
/
MathUtils.h
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
// Copyright 2014 Isis Innovation Limited and the authors of InfiniTAM
#pragma once
#ifndef MIN
#define MIN(a,b) ((a < b) ? a : b)
#endif
#ifndef MAX
#define MAX(a,b) ((a < b) ? b : a)
#endif
#ifndef ABS
#define ABS(a) ((a < 0) ? -a : a)
#endif
#ifndef CLAMP
#define CLAMP(x,a,b) MAX((a), MIN((b), (x)))
#endif
#ifndef ROUND
#define ROUND(x) ((x < 0) ? (x - 0.5f) : (x + 0.5f))
#endif
#ifndef PI
#define PI float(3.1415926535897932384626433832795)
#endif
#ifndef DEGTORAD
#define DEGTORAD float(0.017453292519943295769236907684886)
#endif
#ifndef MY_INF
#define MY_INF 0x7f800000
#endif
#ifndef __METALC__
inline bool portable_finite(float a)
{
volatile float temp = a;
if (temp != a) return false;
if ((temp - a) != 0.0) return false;
return true;
}
inline void matmul(const float *A, const float *b, float *x, int numRows, int numCols)
{
for (int r = 0; r < numRows; ++r)
{
float res = 0.0f;
for (int c = 0; c < numCols; ++c) res += A[r*numCols + c] * b[c];
x[r] = res;
}
}
#endif