Skip to content

Commit 247c064

Browse files
author
Dex
committed
Better test for parameter auxiliary_data
1 parent b955d2d commit 247c064

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

pygad.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import pickle
55
import time
66
import warnings
7+
from multiprocessing import Process, Queue
8+
79

810
class GA:
911

@@ -648,7 +650,7 @@ def __init__(self,
648650
try:
649651
if desired_output.size > 0 and function_inputs.size > 0:
650652
self.fitness_function_extra_data_set = 1
651-
if auxiliary_data:
653+
if not self.test_numpy_array_empty(auxiliary_data):
652654
self.fitness_function_extra_data_set = 2
653655
self.desired_output = desired_output
654656
self.function_inputs = function_inputs
@@ -938,6 +940,31 @@ def __init__(self,
938940
self.last_generation_offspring_mutation = None # A list holding the offspring after applying mutation in the last generation.
939941
self.previous_generation_fitness = None # Holds the fitness values of one generation before the fitness values saved in the last_generation_fitness attribute. Added in PyGAD 2.26.2
940942

943+
@staticmethod
944+
def test_numpy_array_empty(np_array):
945+
is_empty = False
946+
test_performed = True
947+
try:
948+
if np_array:
949+
is_empty = False
950+
else:
951+
is_empty = True
952+
except:
953+
test_performed = False
954+
955+
if not test_performed:
956+
test_performed = True
957+
try:
958+
if np_array.size == 0:
959+
is_empty = True
960+
else:
961+
is_empty = False
962+
except:
963+
is_empty = True
964+
test_performed = False
965+
966+
return is_empty
967+
941968
def round_genes(self, solutions):
942969
for gene_idx in range(self.num_genes):
943970
if self.gene_type_single:

0 commit comments

Comments
 (0)