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