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