zinnia: fix compilation on darwin, update sourceRoot logic

TomaSajt c7b26ea2 ad50b616

+39 -8
+12 -8
pkgs/by-name/zi/zinnia/package.nix
··· 4 4 fetchFromGitHub, 5 5 }: 6 6 7 - stdenv.mkDerivation { 7 + stdenv.mkDerivation (finalAttrs: { 8 8 pname = "zinnia"; 9 9 version = "2016-08-28"; 10 10 ··· 15 15 sha256 = "1izjy5qw6swg0rs2ym2i72zndb90mwrfbd1iv8xbpwckbm4899lg"; 16 16 }; 17 17 18 - setSourceRoot = '' 19 - sourceRoot=$(echo */zinnia) 20 - ''; 18 + sourceRoot = "${finalAttrs.src.name}/zinnia"; 21 19 22 - meta = with lib; { 20 + patches = [ 21 + # Fixes the following error on darwin: 22 + # svm.cpp:50:10: error: no member named 'random_shuffle' in namespace 'std' 23 + ./remove-random-shuffle-usage.patch 24 + ]; 25 + 26 + meta = { 23 27 description = "Online hand recognition system with machine learning"; 24 28 homepage = "http://taku910.github.io/zinnia/"; 25 - license = licenses.bsd2; 26 - platforms = platforms.unix; 29 + license = lib.licenses.bsd2; 30 + platforms = lib.platforms.unix; 27 31 maintainers = [ ]; 28 32 }; 29 - } 33 + })
+27
pkgs/by-name/zi/zinnia/remove-random-shuffle-usage.patch
··· 1 + diff --git a/svm.cpp b/svm.cpp 2 + index 3b7643e..2a34b42 100644 3 + --- a/svm.cpp 4 + +++ b/svm.cpp 5 + @@ -10,6 +10,7 @@ 6 + #include <vector> 7 + #include <cmath> 8 + #include <algorithm> 9 + +#include <random> 10 + #include "feature.h" 11 + 12 + namespace zinnia { 13 + @@ -43,11 +44,13 @@ bool svm_train(size_t l, 14 + } 15 + } 16 + 17 + + std::random_device rand_device; 18 + + std::default_random_engine rand_engine(rand_device()); 19 + static const size_t kMaxIteration = 2000; 20 + for (size_t iter = 0; iter < kMaxIteration; ++iter) { 21 + double PGmax_new = -kINF; 22 + double PGmin_new = kINF; 23 + - std::random_shuffle(index.begin(), index.begin() + active_size); 24 + + std::shuffle(index.begin(), index.begin() + active_size, rand_engine); 25 + 26 + for (size_t s = 0; s < active_size; ++s) { 27 + const size_t i = index[s];