caffe: fix compilation against C++17

uku 75cdeccf f349c0d6

+68 -1
+1 -1
pkgs/applications/science/math/caffe/default.nix
··· 1 1 { 2 - config, 3 2 stdenv, 4 3 lib, 5 4 fetchFromGitHub, ··· 117 116 [ 118 117 ./darwin.patch 119 118 ./glog-cmake.patch 119 + ./random-shuffle.patch 120 120 (fetchpatch { 121 121 name = "support-opencv4"; 122 122 url = "https://github.com/BVLC/caffe/pull/6638/commits/0a04cc2ccd37ba36843c18fea2d5cbae6e7dd2b5.patch";
+67
pkgs/applications/science/math/caffe/random-shuffle.patch
··· 1 + From 11e585e52ab92bb9d7a995c5002cb55fbff687b2 Mon Sep 17 00:00:00 2001 2 + From: uku <hi@uku.moe> 3 + Date: Thu, 15 May 2025 11:10:50 +0200 4 + Subject: [PATCH] fix: remove usages of random_shuffle 5 + 6 + --- 7 + src/caffe/layers/hdf5_data_layer.cpp | 17 ++++++++++++----- 8 + 1 file changed, 12 insertions(+), 5 deletions(-) 9 + 10 + diff --git a/src/caffe/layers/hdf5_data_layer.cpp b/src/caffe/layers/hdf5_data_layer.cpp 11 + index 00716a92..01213691 100644 12 + --- a/src/caffe/layers/hdf5_data_layer.cpp 13 + +++ b/src/caffe/layers/hdf5_data_layer.cpp 14 + @@ -61,7 +61,9 @@ void HDF5DataLayer<Dtype>::LoadHDF5FileData(const char* filename) { 15 + 16 + // Shuffle if needed. 17 + if (this->layer_param_.hdf5_data_param().shuffle()) { 18 + - std::random_shuffle(data_permutation_.begin(), data_permutation_.end()); 19 + + std::random_device rand_device; 20 + + std::default_random_engine rand_engine(rand_device()); 21 + + std::shuffle(data_permutation_.begin(), data_permutation_.end(), rand_engine); 22 + DLOG(INFO) << "Successfully loaded " << hdf_blobs_[0]->shape(0) 23 + << " rows (shuffled)"; 24 + } else { 25 + @@ -104,7 +106,9 @@ void HDF5DataLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom, 26 + 27 + // Shuffle if needed. 28 + if (this->layer_param_.hdf5_data_param().shuffle()) { 29 + - std::random_shuffle(file_permutation_.begin(), file_permutation_.end()); 30 + + std::random_device rand_device; 31 + + std::default_random_engine rand_engine(rand_device()); 32 + + std::shuffle(file_permutation_.begin(), file_permutation_.end(), rand_engine); 33 + } 34 + 35 + // Load the first HDF5 file and initialize the line counter. 36 + @@ -137,14 +141,17 @@ bool HDF5DataLayer<Dtype>::Skip() { 37 + 38 + template<typename Dtype> 39 + void HDF5DataLayer<Dtype>::Next() { 40 + + std::random_device rand_device; 41 + + std::default_random_engine rand_engine(rand_device()); 42 + if (++current_row_ == hdf_blobs_[0]->shape(0)) { 43 + if (num_files_ > 1) { 44 + ++current_file_; 45 + if (current_file_ == num_files_) { 46 + current_file_ = 0; 47 + if (this->layer_param_.hdf5_data_param().shuffle()) { 48 + - std::random_shuffle(file_permutation_.begin(), 49 + - file_permutation_.end()); 50 + + std::shuffle(file_permutation_.begin(), 51 + + file_permutation_.end(), 52 + + rand_engine); 53 + } 54 + DLOG(INFO) << "Looping around to first file."; 55 + } 56 + @@ -153,7 +160,7 @@ void HDF5DataLayer<Dtype>::Next() { 57 + } 58 + current_row_ = 0; 59 + if (this->layer_param_.hdf5_data_param().shuffle()) 60 + - std::random_shuffle(data_permutation_.begin(), data_permutation_.end()); 61 + + std::shuffle(data_permutation_.begin(), data_permutation_.end(), rand_engine); 62 + } 63 + offset_++; 64 + } 65 + -- 66 + 2.49.0 67 +