dinopy.shape module

class dinopy.shape.Shape(object shape)

The Shape class represents a shape that can be applied to qgrams.

Parameters:

shape (object) – Any descriptor for a shape. For a list of possible descriptors, see below.

Representations that can be parsed include:

  • Strings consisting of ‘#’ (care) and ‘_’/’-’ (don’t care) characters, e.g. "#__##" or "#--##"

  • A single integer: for example, specifying 5 is equivalent to "#####"

  • Any iterable which consists of exactly two different items, e.g. ["care", "don't care", "care", "care"] is the same as "#_##".

    Note

    As valid shapes must always start with a care character, we assume that the first item encountered is indeed a care character. This can lead to counterintuitive behaviour, i.e. ["no", "yes", "yes", "no"] is equivalent to "#__#".

  • Any iterable which consists of exactly one unique item, e.g. [1, 1, 1, 1] is the same as "####". Note that there’s no special case for bitlike lists, i.e. [0, 0, 0, 0] is the same as "####"!

Upon creation, some information about the shape is gathered:

  • shape length: can be accessed via len(shape) or the shape.length attribute.

  • solidity: a shape is called solid iff it solely consists of care characters. Can be checked for via dinopy.shape.is_solid().

In addition to the above information, we also generate four different shape representations, because they may prove useful for certain applications. They can be accessed by:

  • shape.bool_shape: A boolean numpy array with True (care) and False (don’t care), e.g. "#_##"array([True, False, True, True], dtype=bool)

  • shape.index_shape_care: A list containing only those indices which correspond to a care character, e.g. "#_##"[0, 2, 3]. This is especially useful for shapes with lots of don’t cares (or gaps).

  • shape.index_shape_dont_care: A list containing only those indices which correspond to a don’t care character, e.g. "#_##"[1]. This is especially useful for shapes with lots of cares.

bool_shape

Numpy array of booleans containing the shape encoded as True (care position) and False (don’t-care position).

Type:

np.ndarray

index_shape_care

List containing the indices of all care positions.

Type:

list, readonly

index_shape_dont_care

List containing the indices of all don’t care positions.

Type:

list, readonly

length

Total length of the shape (care + don’t-care positions).

Type:

int, readonly

num_care

Number of care positions in the shape.

Type:

int, readonly

num_dont_care

Number of don’t care positions in the shape.

Type:

int, readonly

is_solid(self) bool

Return True if the Shape does not have any don’t care positions.