Skip to content

Commit fd031d3

Browse files
committed
None precision for int dtypes
1 parent 0ede7a2 commit fd031d3

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

pygad/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from .pygad import * # Relative import.
22

3-
__version__ = "3.1.0"
3+
__version__ = "3.1.1"

pygad/pygad.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,11 @@ def __init__(self,
345345
elif len(gene_type) == 2 and gene_type[0] in GA.supported_float_types and (type(gene_type[1]) in GA.supported_int_types or gene_type[1] is None):
346346
self.gene_type = gene_type
347347
self.gene_type_single = True
348-
# A single data type of int with precision.
348+
# A single data type of integer with precision None ([int, None]).
349+
elif len(gene_type) == 2 and gene_type[0] in GA.supported_int_types and gene_type[1] is None:
350+
self.gene_type = gene_type
351+
self.gene_type_single = True
352+
# Raise an exception for a single data type of int with integer precision.
349353
elif len(gene_type) == 2 and gene_type[0] in GA.supported_int_types and (type(gene_type[1]) in GA.supported_int_types or gene_type[1] is None):
350354
self.gene_type_single = False
351355
raise ValueError(f"Integers cannot have precision. Please use the integer data type directly instead of {gene_type}.")
@@ -362,10 +366,8 @@ def __init__(self,
362366
self.valid_parameters = False
363367
raise ValueError(f"When the parameter 'gene_type' is nested, then it can be either [float, int<precision>] or with length equal to the value passed to the 'num_genes' parameter. Instead, value {gene_type} with len(gene_type) ({len(gene_type)}) != len(num_genes) ({num_genes}) found.")
364368
for gene_type_idx, gene_type_val in enumerate(gene_type):
365-
if gene_type_val in GA.supported_float_types:
366-
# If the gene type is float and no precision is passed, set it to None.
367-
gene_type[gene_type_idx] = [gene_type_val, None]
368-
elif gene_type_val in GA.supported_int_types:
369+
if gene_type_val in GA.supported_int_float_types:
370+
# If the gene type is float and no precision is passed or an integer, set its precision to None.
369371
gene_type[gene_type_idx] = [gene_type_val, None]
370372
elif type(gene_type_val) in [list, tuple, numpy.ndarray]:
371373
# A float type is expected in a list/tuple/numpy.ndarray of length 2.
@@ -376,6 +378,12 @@ def __init__(self,
376378
else:
377379
self.valid_parameters = False
378380
raise TypeError(f"In the 'gene_type' parameter, the precision for float gene data types must be an integer but the element {gene_type_val} at index {gene_type_idx} has a precision of {gene_type_val[1]} with type {gene_type_val[0]}.")
381+
elif gene_type_val[0] in GA.supported_int_types:
382+
if gene_type_val[1] is None:
383+
pass
384+
else:
385+
self.valid_parameters = False
386+
raise TypeError(f"In the 'gene_type' parameter, either do not set a precision for integer data types or set it to None. But the element {gene_type_val} at index {gene_type_idx} has a precision of {gene_type_val[1]} with type {gene_type_val[0]}.")
379387
else:
380388
self.valid_parameters = False
381389
raise TypeError(

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ build-backend = "setuptools.build_meta"
99

1010
[project]
1111
name = "pygad"
12-
version = "3.1.0"
12+
version = "3.1.1"
1313
description = "PyGAD: A Python Library for Building the Genetic Algorithm and Training Machine Learning Algoithms (Keras & PyTorch)."
1414
readme = {file = "README.md", content-type = "text/markdown"}
1515
requires-python = ">=3"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="pygad",
8-
version="3.1.0",
8+
version="3.1.1",
99
author="Ahmed Fawzy Gad",
1010
install_requires=["numpy", "matplotlib", "cloudpickle",],
1111
author_email="ahmed.f.gad@gmail.com",

0 commit comments

Comments
 (0)