zinnia: fix compilation on darwin, update sourceRoot logic

This commit is contained in:
TomaSajt
2025-05-12 00:19:00 +02:00
parent ad50b616f8
commit c7b26ea2bc
2 changed files with 39 additions and 8 deletions

View File

@@ -4,7 +4,7 @@
fetchFromGitHub,
}:
stdenv.mkDerivation {
stdenv.mkDerivation (finalAttrs: {
pname = "zinnia";
version = "2016-08-28";
@@ -15,15 +15,19 @@ stdenv.mkDerivation {
sha256 = "1izjy5qw6swg0rs2ym2i72zndb90mwrfbd1iv8xbpwckbm4899lg";
};
setSourceRoot = ''
sourceRoot=$(echo */zinnia)
'';
sourceRoot = "${finalAttrs.src.name}/zinnia";
meta = with lib; {
patches = [
# Fixes the following error on darwin:
# svm.cpp:50:10: error: no member named 'random_shuffle' in namespace 'std'
./remove-random-shuffle-usage.patch
];
meta = {
description = "Online hand recognition system with machine learning";
homepage = "http://taku910.github.io/zinnia/";
license = licenses.bsd2;
platforms = platforms.unix;
license = lib.licenses.bsd2;
platforms = lib.platforms.unix;
maintainers = [ ];
};
}
})

View File

@@ -0,0 +1,27 @@
diff --git a/svm.cpp b/svm.cpp
index 3b7643e..2a34b42 100644
--- a/svm.cpp
+++ b/svm.cpp
@@ -10,6 +10,7 @@
#include <vector>
#include <cmath>
#include <algorithm>
+#include <random>
#include "feature.h"
namespace zinnia {
@@ -43,11 +44,13 @@ bool svm_train(size_t l,
}
}
+ std::random_device rand_device;
+ std::default_random_engine rand_engine(rand_device());
static const size_t kMaxIteration = 2000;
for (size_t iter = 0; iter < kMaxIteration; ++iter) {
double PGmax_new = -kINF;
double PGmin_new = kINF;
- std::random_shuffle(index.begin(), index.begin() + active_size);
+ std::shuffle(index.begin(), index.begin() + active_size, rand_engine);
for (size_t s = 0; s < active_size; ++s) {
const size_t i = index[s];