pg.hyper.Choices¶
Accessible via pg.hyper.Choices
.
- class Choices(name=None, hints=None, num_choices=None, candidates=MISSING_VALUE, choices_distinct=True, choices_sorted=False, where=None)[source]¶
Bases:
pg.hyper.HyperPrimitive
Categorical choices from a list of candidates.
Example:
# A single categorical choice: v = pg.oneof([1, 2, 3]) # A multiple categorical choice as a list: vs = pg.manyof(2, [1, 2, 3]) # A hierarchical categorical choice: v2 = pg.oneof([ 'foo', 'bar', pg.manyof(2, [1, 2, 3]) ])
Attributes:
Returns candidate templates.
Returns whether this is a leaf node.
Methods:
- encode(value)[source]¶
Encode a list of values into DNA.
Example:
# DNA of an object containing a single OneOf. # {'a': 1} => DNA(0) { 'a': one_of([1, 2]) } # DNA of an object containing multiple OneOfs. # {'b': 1, 'c': bar} => DNA([0, 1]) { 'b': pg.oneof([1, 2]), 'c': pg.oneof(['foo', 'bar']) } # DNA of an object containing conditional space. # {'a': {'b': 1} => DNA(0, 0, 0)]) # {'a': {'b': [4, 7]} => DNA(1, [(0, 1), 2]) # {'a': {'b': 'bar'} => DNA(2) { 'a': { 'b': pg.oneof([ pg.oneof([ pg.oneof([1, 2]), pg.oneof(3, 4)]), pg.manyof(2, [ pg.oneof([4, 5]), 6, 7 ]), ]), 'bar', ]) } }
- Return type:
- Parameters:
value – A list of value that can match choice candidates.
- Returns:
Encoded DNA.
- Raises:
ValueError if value cannot be encoded. –