From 869a742b93cccd6d649db4fe7476acea803e65b3 Mon Sep 17 00:00:00 2001 From: thibault allenet <thibault.allenet@cea.fr> Date: Thu, 22 Feb 2024 16:16:23 +0000 Subject: [PATCH] Add Random utils for random shuffling the batches --- include/aidge/aidge.hpp | 1 + include/aidge/utils/Random.hpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 include/aidge/utils/Random.hpp diff --git a/include/aidge/aidge.hpp b/include/aidge/aidge.hpp index 9e0e457b4..6c4ca93ce 100644 --- a/include/aidge/aidge.hpp +++ b/include/aidge/aidge.hpp @@ -70,6 +70,7 @@ #include "aidge/utils/Attributes.hpp" #include "aidge/utils/StaticAttributes.hpp" #include "aidge/utils/DynamicAttributes.hpp" +#include "aidge/utils/Random.hpp" #include "aidge/utils/Registrar.hpp" #include "aidge/utils/Types.h" diff --git a/include/aidge/utils/Random.hpp b/include/aidge/utils/Random.hpp new file mode 100644 index 000000000..704609c0c --- /dev/null +++ b/include/aidge/utils/Random.hpp @@ -0,0 +1,31 @@ +/******************************************************************************** + * Copyright (c) 2023 CEA-List + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + ********************************************************************************/ + + +#ifndef AIDGE_RANDOM_H_ +#define AIDGE_RANDOM_H_ + + +#include <algorithm> +#include <vector> +#include <random> + +namespace Random { + + void randShuffle(std::vector<unsigned int>& vec) { + std::random_device rd; + std::mt19937 g(rd()); + std::shuffle(vec.begin(), vec.end(), g); + } + +} + +#endif //AIDGE_RANDOM_H_ \ No newline at end of file -- GitLab