Skip to content

Commit d51b4d8

Browse files
committed
Clean code
1 parent e17b999 commit d51b4d8

File tree

1 file changed

+13
-27
lines changed

1 file changed

+13
-27
lines changed

pygad/helper/unique.py

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def unique_int_gene_from_range(self,
171171
max_val,
172172
mutation_by_replacement,
173173
gene_type,
174-
step=None):
174+
step=1):
175175

176176
"""
177177
Finds a unique integer value for the gene.
@@ -182,38 +182,24 @@ def unique_int_gene_from_range(self,
182182
max_val: Maximum value of the range to sample a number randomly.
183183
mutation_by_replacement: Identical to the self.mutation_by_replacement attribute.
184184
gene_type: Exactly the same as the self.gene_type attribute.
185-
185+
step: Defaults to 1.
186+
186187
Returns:
187188
selected_value: The new value of the gene. It may be identical to the original gene value in case there are no possible unique values for the gene.
188189
"""
189190

191+
# The gene_type is of the form [type, precision]
190192
if self.gene_type_single == True:
191-
if step is None:
192-
# all_gene_values = numpy.arange(min_val,
193-
# max_val,
194-
# dtype=gene_type[0])
195-
all_gene_values = numpy.asarray(numpy.arange(min_val, max_val),
196-
dtype=gene_type[0])
197-
else:
198-
# For non-integer steps, the numpy.arange() function returns zeros if the dtype parameter is set to an integer data type. So, this returns zeros if step is non-integer and dtype is set to an int data type: numpy.arange(min_val, max_val, step, dtype=gene_type[0])
199-
# To solve this issue, the data type casting will not be handled inside numpy.arange(). The range is generated by numpy.arange() and then the data type is converted using the numpy.asarray() function.
200-
all_gene_values = numpy.asarray(numpy.arange(min_val,
201-
max_val,
202-
step),
203-
dtype=gene_type[0])
193+
dtype = gene_type[0]
204194
else:
205-
if step is None:
206-
# all_gene_values = numpy.arange(min_val,
207-
# max_val,
208-
# dtype=gene_type[gene_index][0])
209-
all_gene_values = numpy.asarray(numpy.arange(min_val,
210-
max_val),
211-
dtype=gene_type[gene_index][0])
212-
else:
213-
all_gene_values = numpy.asarray(numpy.arange(min_val,
214-
max_val,
215-
step),
216-
dtype=gene_type[gene_index][0])
195+
dtype = gene_type[gene_index][0]
196+
197+
# For non-integer steps, the numpy.arange() function returns zeros if the dtype parameter is set to an integer data type. So, this returns zeros if step is non-integer and dtype is set to an int data type: numpy.arange(min_val, max_val, step, dtype=gene_type[0])
198+
# To solve this issue, the data type casting will not be handled inside numpy.arange(). The range is generated by numpy.arange() and then the data type is converted using the numpy.asarray() function.
199+
all_gene_values = numpy.asarray(numpy.arange(min_val,
200+
max_val,
201+
step),
202+
dtype=dtype)
217203

218204
if mutation_by_replacement:
219205
pass

0 commit comments

Comments
 (0)