From 0b676fa3918a46400b5b5bd9db35603569eef56f Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Fri, 13 Jan 2023 16:47:35 +0000 Subject: [PATCH] move shuffle to subdir --- aimodel/src/lib/dataset/dataset.py | 2 +- aimodel/src/lib/dataset/dataset_encoderonly.py | 2 +- aimodel/src/lib/dataset/dataset_segmenter.py | 2 +- aimodel/src/lib/dataset/primitives/shuffle.py | 18 ++++++++++++++++++ 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 aimodel/src/lib/dataset/primitives/shuffle.py diff --git a/aimodel/src/lib/dataset/dataset.py b/aimodel/src/lib/dataset/dataset.py index 27a9340..cf85649 100644 --- a/aimodel/src/lib/dataset/dataset.py +++ b/aimodel/src/lib/dataset/dataset.py @@ -9,7 +9,7 @@ import tensorflow as tf from lib.dataset.read_metadata import read_metadata from ..io.readfile import readfile -from .shuffle import shuffle +from .primitives.shuffle import shuffle diff --git a/aimodel/src/lib/dataset/dataset_encoderonly.py b/aimodel/src/lib/dataset/dataset_encoderonly.py index 2a6ce13..86e97d2 100644 --- a/aimodel/src/lib/dataset/dataset_encoderonly.py +++ b/aimodel/src/lib/dataset/dataset_encoderonly.py @@ -9,7 +9,7 @@ import tensorflow as tf from lib.dataset.read_metadata import read_metadata from ..io.readfile import readfile -from .shuffle import shuffle +from .primitives.shuffle import shuffle from .parse_heightmap import parse_heightmap diff --git a/aimodel/src/lib/dataset/dataset_segmenter.py b/aimodel/src/lib/dataset/dataset_segmenter.py index 0caafab..cb78b96 100644 --- a/aimodel/src/lib/dataset/dataset_segmenter.py +++ b/aimodel/src/lib/dataset/dataset_segmenter.py @@ -7,7 +7,7 @@ import tensorflow as tf from lib.dataset.read_metadata import read_metadata from ..io.readfile import readfile -from .shuffle import shuffle +from .primitives.shuffle import shuffle # TO PARSE: diff --git a/aimodel/src/lib/dataset/primitives/shuffle.py b/aimodel/src/lib/dataset/primitives/shuffle.py new file mode 100644 index 0000000..487fe2c --- /dev/null +++ b/aimodel/src/lib/dataset/primitives/shuffle.py @@ -0,0 +1,18 @@ +from copy import deepcopy +from random import randint + + +def shuffle(lst): + """ + Shuffles a list with the Fisher-Yates algorithm. + @ref https://poopcode.com/shuffle-a-list-in-python-fisher-yates/ + @param lst list The list to shuffle. + @return list The a new list that is a shuffled copy of the original. + """ + tmplist = deepcopy(lst) + m = len(tmplist) + while (m): + m -= 1 + i = randint(0, m) + tmplist[m], tmplist[i] = tmplist[i], tmplist[m] + return tmplist