graphdot.codegen.typetool module

graphdot.codegen.typetool.can_cast(src, dst)[source]
class graphdot.codegen.typetool.common_concrete_type[source]

Bases: object

static of_types(types)[source]

Find the common concrete type (if one exists) among a type list.

Returns:t – Returns the type of the elements if all elements share a common type, and returns None otherwise.
Return type:type or None
static of_values(iterable)[source]

Find the common concrete type (if one exists) of all elements in a sequence.

Returns:t – Returns the type of the elements if all elements share a common type, and returns None otherwise.
Return type:type or None
class graphdot.codegen.typetool.common_min_type[source]

Bases: object

static of_types(types, coerce=True, min_float=<class 'numpy.float32'>, ensure_signed=True)[source]

Find the common minimum elemet type that can safely hold all types in the given list.

Parameters:
  • iterable – Sequence of types for which a common type is to be inferred.
  • coerce (bool) – Whether or not to up-cast in case when elements have different but inter-converible types.
  • min_float (dtype) – The smallest floating-point type that should be returned. Introduced because float16 is not universally supported yet.
  • ensure_signed (bool) – Whehter to promote the result to a signed type.
Returns:

t – If coerce=True, t would be the smallest numpy type that can safely contain all the values; otherwise, t would either be the smallest numpy dtype or the Python class that the elements belongs to.

Return type:

np.dtype or class

static of_values(iterable, coerce=True, min_float=<class 'numpy.float32'>, ensure_signed=True)[source]

Find the common minimum elemet type that can safely hold all elements of an iterable sequence.

Parameters:
  • iterable – Sequence of objects for which a common type is to be inferred.
  • coerce (bool) – Whether or not to up-cast in case when elements have different but inter-converible types.
  • min_float (dtype) – The smallest floating-point type that should be returned. Introduced because float16 is not universally supported yet.
  • ensure_signed (bool) – Whehter to promote the result to a signed type.
Returns:

t – If coerce=True, t would be the smallest numpy type that can safely contain all the values; otherwise, t would either be the smallest numpy dtype or the Python class that the elements belongs to.

Return type:

np.dtype or class

graphdot.codegen.typetool.have_same_fields(t1, t2)[source]