2021-01-15 22:18:51 +00:00
|
|
|
{ lib, stdenv
|
2020-04-24 23:36:52 +00:00
|
|
|
, runCommandCC
|
|
|
|
, fetchPypi
|
|
|
|
, buildPythonPackage
|
|
|
|
, isPyPy
|
|
|
|
, pythonOlder
|
|
|
|
, isPy3k
|
|
|
|
, nose
|
|
|
|
, numpy
|
|
|
|
, scipy
|
2021-09-23 15:35:13 +00:00
|
|
|
, setuptools
|
2020-04-24 23:36:52 +00:00
|
|
|
, six
|
|
|
|
, libgpuarray
|
2022-04-15 01:41:22 +00:00
|
|
|
, cudaSupport ? false, cudaPackages ? {}
|
|
|
|
, cudnnSupport ? false
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
|
2022-04-15 01:41:22 +00:00
|
|
|
let
|
|
|
|
inherit (cudaPackages) cudatoolkit cudnn;
|
|
|
|
in
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
assert cudnnSupport -> cudaSupport;
|
|
|
|
|
|
|
|
let
|
|
|
|
wrapped = command: buildTop: buildInputs:
|
|
|
|
runCommandCC "${command}-wrapped" { inherit buildInputs; } ''
|
|
|
|
type -P '${command}' || { echo '${command}: not found'; exit 1; }
|
|
|
|
cat > "$out" <<EOF
|
|
|
|
#!$(type -P bash)
|
|
|
|
$(declare -xp | sed -e '/^[^=]\+="\('"''${NIX_STORE//\//\\/}"'\|[^\/]\)/!d')
|
|
|
|
declare -x NIX_BUILD_TOP="${buildTop}"
|
|
|
|
$(type -P '${command}') "\$@"
|
|
|
|
EOF
|
|
|
|
chmod +x "$out"
|
|
|
|
'';
|
|
|
|
|
|
|
|
# Theano spews warnings and disabled flags if the compiler isn't named g++
|
|
|
|
cxx_compiler_name =
|
|
|
|
if stdenv.cc.isGNU then "g++" else
|
|
|
|
if stdenv.cc.isClang then "clang++" else
|
|
|
|
throw "Unknown C++ compiler";
|
|
|
|
cxx_compiler = wrapped cxx_compiler_name "\\$HOME/.theano"
|
2021-02-05 17:12:51 +00:00
|
|
|
( lib.optional cudaSupport libgpuarray_
|
|
|
|
++ lib.optional cudnnSupport cudnn );
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-04-15 01:41:22 +00:00
|
|
|
# We need to be careful with overriding Python packages within the package set
|
|
|
|
# as this can lead to collisions!
|
|
|
|
libgpuarray_ = libgpuarray.override { inherit cudaSupport cudaPackages; };
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
in buildPythonPackage rec {
|
|
|
|
pname = "Theano";
|
2020-08-20 17:08:02 +00:00
|
|
|
version = "1.0.5";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
disabled = isPyPy || pythonOlder "2.6" || (isPy3k && pythonOlder "3.3");
|
|
|
|
|
|
|
|
src = fetchPypi {
|
|
|
|
inherit pname version;
|
2020-08-20 17:08:02 +00:00
|
|
|
sha256 = "129f43ww2a6badfdr6b88kzjzz2b0wk0dwkvwb55z6dsagfkk53f";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
substituteInPlace theano/configdefaults.py \
|
|
|
|
--replace 'StrParam(param, is_valid=warn_cxx)' 'StrParam('\'''${cxx_compiler}'\''', is_valid=warn_cxx)' \
|
|
|
|
--replace 'rc == 0 and config.cxx != ""' 'config.cxx != ""'
|
2021-02-05 17:12:51 +00:00
|
|
|
'' + lib.optionalString cudaSupport ''
|
2020-04-24 23:36:52 +00:00
|
|
|
substituteInPlace theano/configdefaults.py \
|
|
|
|
--replace 'StrParam(get_cuda_root)' 'StrParam('\'''${cudatoolkit}'\''')'
|
2021-02-05 17:12:51 +00:00
|
|
|
'' + lib.optionalString cudnnSupport ''
|
2020-04-24 23:36:52 +00:00
|
|
|
substituteInPlace theano/configdefaults.py \
|
|
|
|
--replace 'StrParam(default_dnn_base_path)' 'StrParam('\'''${cudnn}'\''')'
|
|
|
|
'';
|
|
|
|
|
2020-10-19 00:13:06 +00:00
|
|
|
# needs to be postFixup so it runs before pythonImportsCheck even when
|
|
|
|
# doCheck = false (meaning preCheck would be disabled)
|
|
|
|
postFixup = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
mkdir -p check-phase
|
|
|
|
export HOME=$(pwd)/check-phase
|
|
|
|
'';
|
|
|
|
doCheck = false;
|
|
|
|
# takes far too long, also throws "TypeError: sort() missing 1 required positional argument: 'a'"
|
|
|
|
# when run from the installer, and testing with Python 3.5 hits github.com/Theano/Theano/issues/4276,
|
|
|
|
# the fix for which hasn't been merged yet.
|
|
|
|
|
|
|
|
# keep Nose around since running the tests by hand is possible from Python or bash
|
|
|
|
checkInputs = [ nose ];
|
2021-09-23 15:35:13 +00:00
|
|
|
# setuptools needed for cuda support
|
|
|
|
propagatedBuildInputs = [
|
|
|
|
libgpuarray_
|
|
|
|
numpy
|
|
|
|
numpy.blas
|
|
|
|
scipy
|
|
|
|
setuptools
|
|
|
|
six
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-10-19 00:13:06 +00:00
|
|
|
pythonImportsCheck = [ "theano" ];
|
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
meta = with lib; {
|
2021-10-07 14:46:35 +00:00
|
|
|
homepage = "https://github.com/Theano/Theano";
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "A Python library for large-scale array computation";
|
|
|
|
license = licenses.bsd3;
|
2022-04-27 09:35:20 +00:00
|
|
|
maintainers = [ ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|