1{ lib
2, stdenv
3, fetchFromGitHub
4, fetchpatch
5, cmake
6, doctest
7, enableAssertions ? false
8, enableBoundChecks ? false # Broadcasts don't pass bound checks
9, nlohmann_json
10, xtl
11, xsimd
12}:
13
14stdenv.mkDerivation (finalAttrs: {
15 pname = "xtensor";
16 version = "0.24.7";
17
18 src = fetchFromGitHub {
19 owner = "xtensor-stack";
20 repo = "xtensor";
21 rev = finalAttrs.version;
22 hash = "sha256-dVbpcBW+jK9nIl5efk5LdKdBm8CkaJWEZ0ZY7ZuApwk=";
23 };
24 patches = [
25 # Support for xsimd 11
26 (fetchpatch {
27 url = "https://github.com/xtensor-stack/xtensor/commit/77a650a8018e0be6fcc76bf66685ff352ae23ef1.patch";
28 hash = "sha256-vOdUzzsSK+lYcA7fZXWOTVV202GZC0DhkMMjzggnmWE=";
29 })
30 # A single test fails on Darwin, see:
31 # https://github.com/xtensor-stack/xtensor/issues/2718
32 ./remove-failing-test_xinfo.patch
33 ];
34
35 nativeBuildInputs = [
36 cmake
37 ];
38 propagatedBuildInputs = [
39 nlohmann_json
40 xtl
41 ] ++ lib.optionals (!(stdenv.isAarch64 && stdenv.isLinux)) [
42 # xsimd support is broken on aarch64-linux, see:
43 # https://github.com/xtensor-stack/xsimd/issues/945
44 xsimd
45 ];
46
47 cmakeFlags = let
48 cmakeBool = x: if x then "ON" else "OFF";
49 in [
50 "-DBUILD_TESTS=${cmakeBool finalAttrs.finalPackage.doCheck}"
51 "-DXTENSOR_ENABLE_ASSERT=${cmakeBool enableAssertions}"
52 "-DXTENSOR_CHECK_DIMENSION=${cmakeBool enableBoundChecks}"
53 ];
54
55 doCheck = true;
56 nativeCheckInputs = [
57 doctest
58 ];
59 checkTarget = "xtest";
60
61 meta = with lib; {
62 description = "Multi-dimensional arrays with broadcasting and lazy computing.";
63 homepage = "https://github.com/xtensor-stack/xtensor";
64 license = licenses.bsd3;
65 maintainers = with maintainers; [ cpcloud ];
66 platforms = platforms.all;
67 };
68})