forked from arrayfire/arrayfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdispatch.hpp
More file actions
44 lines (34 loc) · 967 Bytes
/
dispatch.hpp
File metadata and controls
44 lines (34 loc) · 967 Bytes
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
/*******************************************************
* Copyright (c) 2014, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#pragma once
#include <cmath>
#define divup(a, b) (((a) + (b)-1) / (b))
unsigned nextpow2(unsigned x);
// isPrime & greatestPrimeFactor are tailored after
// itk::Math::{IsPrimt, GreatestPrimeFactor}
template<typename T>
inline bool isPrime(T n) {
if (n <= 1) return false;
const T last = (T)std::sqrt((double)n);
for (T x = 2; x <= last; ++x) {
if (n % x == 0) return false;
}
return true;
}
template<typename T>
inline T greatestPrimeFactor(T n) {
T v = 2;
while (v <= n) {
if (n % v == 0 && isPrime(v))
n /= v;
else
v += 1;
}
return v;
}