1{
2 lib,
3 stdenv,
4 runCommandCC,
5 fetchPypi,
6 buildPythonPackage,
7 isPyPy,
8 pythonOlder,
9 isPy3k,
10 nose,
11 numpy,
12 scipy,
13 setuptools,
14 six,
15 libgpuarray,
16 config,
17 cudaSupport ? config.cudaSupport,
18 cudaPackages ? { },
19 cudnnSupport ? cudaSupport,
20}:
21
22let
23 inherit (cudaPackages) cudatoolkit cudnn;
24in
25
26assert cudnnSupport -> cudaSupport;
27
28let
29 wrapped =
30 command: buildTop: buildInputs:
31 runCommandCC "${command}-wrapped" { inherit buildInputs; } ''
32 type -P '${command}' || { echo '${command}: not found'; exit 1; }
33 cat > "$out" <<EOF
34 #!$(type -P bash)
35 $(declare -xp | sed -e '/^[^=]\+="\('"''${NIX_STORE//\//\\/}"'\|[^\/]\)/!d')
36 declare -x NIX_BUILD_TOP="${buildTop}"
37 $(type -P '${command}') "\$@"
38 EOF
39 chmod +x "$out"
40 '';
41
42 # Theano spews warnings and disabled flags if the compiler isn't named g++
43 cxx_compiler_name =
44 if stdenv.cc.isGNU then
45 "g++"
46 else if stdenv.cc.isClang then
47 "clang++"
48 else
49 throw "Unknown C++ compiler";
50 cxx_compiler = wrapped cxx_compiler_name "\\$HOME/.theano" (
51 lib.optional cudaSupport libgpuarray_ ++ lib.optional cudnnSupport cudnn
52 );
53
54 # We need to be careful with overriding Python packages within the package set
55 # as this can lead to collisions!
56 libgpuarray_ = libgpuarray.override { inherit cudaSupport cudaPackages; };
57in
58buildPythonPackage rec {
59 pname = "theano";
60 version = "1.0.5";
61 format = "setuptools";
62
63 disabled = isPyPy || pythonOlder "2.6";
64
65 src = fetchPypi {
66 inherit pname version;
67 sha256 = "129f43ww2a6badfdr6b88kzjzz2b0wk0dwkvwb55z6dsagfkk53f";
68 };
69
70 postPatch =
71 ''
72 substituteInPlace theano/configdefaults.py \
73 --replace 'StrParam(param, is_valid=warn_cxx)' 'StrParam('\'''${cxx_compiler}'\''', is_valid=warn_cxx)' \
74 --replace 'rc == 0 and config.cxx != ""' 'config.cxx != ""'
75 ''
76 + lib.optionalString cudaSupport ''
77 substituteInPlace theano/configdefaults.py \
78 --replace 'StrParam(get_cuda_root)' 'StrParam('\'''${cudatoolkit}'\''')'
79 ''
80 + lib.optionalString cudnnSupport ''
81 substituteInPlace theano/configdefaults.py \
82 --replace 'StrParam(default_dnn_base_path)' 'StrParam('\'''${cudnn}'\''')'
83 '';
84
85 # needs to be postFixup so it runs before pythonImportsCheck even when
86 # doCheck = false (meaning preCheck would be disabled)
87 postFixup = ''
88 mkdir -p check-phase
89 export HOME=$(pwd)/check-phase
90 '';
91 doCheck = false;
92 # takes far too long, also throws "TypeError: sort() missing 1 required positional argument: 'a'"
93 # when run from the installer, and testing with Python 3.5 hits github.com/Theano/Theano/issues/4276,
94 # the fix for which hasn't been merged yet.
95
96 # keep Nose around since running the tests by hand is possible from Python or bash
97 nativeCheckInputs = [ nose ];
98 # setuptools needed for cuda support
99 propagatedBuildInputs = [
100 libgpuarray_
101 numpy
102 numpy.blas
103 scipy
104 setuptools
105 six
106 ];
107
108 pythonImportsCheck = [ "theano" ];
109
110 meta = with lib; {
111 homepage = "https://github.com/Theano/Theano";
112 description = "A Python library for large-scale array computation";
113 license = licenses.bsd3;
114 maintainers = [ ];
115 broken = true;
116 };
117}