-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfftw.py
139 lines (136 loc) · 4.8 KB
/
fftw.py
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
# -*- python -*-
#
# Copyright Christoph Lassner 2014.
#
# Distributed under the Boost Software License, Version 1.0.
# (See http://www.boost.org/LICENSE_1_0.txt)
from __future__ import print_function
from ._tools import _checkLibs, _setupPaths
from .python import CheckPython
from SCons.SConf import CheckContext
CheckContext.checkLibs = _checkLibs
import os
_check_dict = {}
_fftw_option_dict = {'--fftw-dir':
{'dest':"fftw_prefix",
'type':"string",
'nargs':1,
'action':"store",
'metavar':"DIR",
'default':os.environ.get("FFTW_ROOT"),
'help':"prefix for the fftw library; should contain fftw3.h and the library files."},
'--fftw-inc-dir':
{'dest':"fftw_include",
'type':"string",
'nargs':1,
'action':"store",
'metavar':"DIR",
'help':"location of fftw3.h",
'default':os.environ.get("FFTW_INCLUDE_DIR")},
'--boost-lib-dir':
{'dest':"fftw_lib",
'type':"string",
'nargs':1,
'action':"store",
'metavar':"DIR",
'help':"location of fftw libraries",
'default':os.environ.get("FFTW_LIB_DIR")},
'--fftw-lib-flavor':
{'dest':"fftw_flavor",
'type':"string",
'nargs':1,
'action':"store",
'help':"FFTW library suffix for float or long double linkage, so either '', 'f' or 'l'.",
'default':""},
'--fftw-ver-major':
{'dest':"fftw_ver_major",
'type':"int",
'nargs':1,
'action':"store",
'help':"FFTW library major version, e.g. 3",
'default':3},
'--fftw-ver-minor':
{'dest':"fftw_ver_minor",
'type':"int",
'nargs':1,
'action':"store",
'help':"FFTW library minor version, e.g. 3",
'default':3}}
def CheckFFTW(context):
fftw_dtype = 'double'
fftw_flavor = ''
try:
fftw_flavor = context.env.GetOption("fftw_flavor")
except:
pass
if fftw_flavor == 'f':
fftw_dtype = 'float'
elif fftw_flavor == 'l':
fftw_dtype = 'long double'
elif fftw_flavor != '':
raise Exception("Unknown fftw flavor: %s" % (fftw_flavor))
fftw_major = 3
try:
fftw_major = context.env.GetOption("fftw_ver_major")
except:
pass
fftw_minor = 3
try:
fftw_minor = context.env.GetOption("fftw_ver_minor")
except:
pass
fftw_source_file = r"""
#include <numeric>
#include <cstdint>
#include <fftw3.h>
int main() {
fftw_complex *in, *out;
fftw_plan p;
std::size_t N = 10;
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
p = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
for (std::size_t i = 0; i < N; ++i) {
in[i][0] = static_cast<%s>(i);
in[i][1] = static_cast<%s>(i);
}
fftw_execute(p);
fftw_destroy_plan(p);
fftw_free(in);
fftw_free(out);
return 0;
}
""" % (fftw_dtype, fftw_dtype)
context.Message('Check building against fftw... ')
fftw_root = context.env.GetOption("fftw_prefix")
fftw_ex_inc = context.env.GetOption("fftw_include")
fftw_ex_lib = context.env.GetOption("fftw_lib")
if fftw_ex_inc is None and not fftw_root is None:
fftw_ex_inc = fftw_root
if fftw_ex_lib is None and not fftw_root is None:
fftw_ex_lib = fftw_root
_setupPaths(context.env,
prefix = fftw_root,
include = fftw_ex_inc,
lib = fftw_ex_lib
)
if context.env['CC'] == 'gcc':
context.env.AppendUnique(CPPFLAGS=['-std=c++0x'])
if os.name == 'nt':
fftw_libname = 'libfftw%d%s-%d' % (fftw_major, fftw_flavor, fftw_minor)
else:
fftw_libname = 'libfftw%d%s' % (fftw_major, fftw_flavor)
result = context.checkLibs([fftw_libname], fftw_source_file)
if not result:
context.Result(0)
print("Cannot build against fftw.")
return False
result, output = context.TryRun(fftw_source_file, '.cpp')
if not result:
context.Result(0)
print("Cannot run program built against fftw.")
return False
context.Result(1)
return True
_check_dict['fftw'] = {'options': _fftw_option_dict,
'checks': [CheckFFTW]}