class sakkara.relation.representation.Representation#

Abstract class for a representation, i.e., class that transforms variables and other elements between different shapes.

abstract get_member_array(group: Group) ndarray[Any, dtype[Any]]#

Get an array shaped as a variable with this representation, where each value correspond to the member of the input group.

abstract get_member_tuples() List[Tuple[Any, ...]]#

Get a (flat) list of all member tuples of this representation

abstract get_members() Tuple[ndarray[Any, dtype[ScalarType]], ...]#
Get member arrays for all groups of this representation. For documentation of a member array, see

Representation.get_member_array().

abstract get_shape() Tuple[int, ...]#

Get the shape of a variable corresponding to a component with this representation

abstract map(element: Any, target_representation: Representation) Any#
Map/transform an element (variable or equivalent) corresponding to this representation to a target

representation.

Parameters:
  • element – The object/variable to transform.

  • target_representation – The representation that corresponds to the shape the variable should be in.

Returns:

The element but transformed to target representation.

abstract merge(other)#

Create a new Representation by adding upp groups from this object and from another.

Parameters:

other – Other Representation to merge with

Returns:

Merged representation. Note that all groups of the merged has either a twin or a parent group in at least one of the two input representations.

class sakkara.relation.representation.TensorRepresentation(*groups: Group)#

Class for a tuple of groups, reduced to its minimal representation. E.g., a parent can be represented by its child, hence when creating a TensorRepresentation object of the two only the child will be added to the tuple.

Parameters:

*groupsGroup objects to include in representation

add_group(group: Group) None#

Add group to the representation. It will not be added if there already is a twin or a child in the representation. If there is a parent to the group in the representation, the group will be added and the parent will be removed.

get_member_array(group: Group) ndarray[Any, dtype[Any]]#

Get an array shaped as a variable with this representation, where each value correspond to the member of the input group.

get_member_tuples() List[Tuple[Any, ...]]#

Get a (flat) list of all member tuples of this representation

get_members() Tuple[ndarray[Any, dtype[ScalarType]], ...]#
Get member arrays for all groups of this representation. For documentation of a member array, see

Representation.get_member_array().

get_shape() Tuple[int, ...]#

Get the shape of a variable corresponding to a component with this representation

is_mappable_to(target: Representation) bool#

Check if representation is mappable to another representation, i.e., groups of the other representation have twins or parents among the groups of this representation.

Returns:

True is self is mappable to target

map(element: object, target: Representation) object#
Map/transform an element (variable or equivalent) corresponding to this representation to a target

representation.

Parameters:
  • element – The object/variable to transform.

  • target_representation – The representation that corresponds to the shape the variable should be in.

Returns:

The element but transformed to target representation.

merge(other: Representation) Representation#

Create a new Representation by adding upp groups from this object and from another.

Parameters:

other – Other Representation to merge with

Returns:

Merged representation. Note that all groups of the merged has either a twin or a parent group in at least one of the two input representations.

class sakkara.relation.representation.UnrepeatableRepresentation#

Simple representation for elements that always have a single value and that can not be repeated.

get_member_array(group: Group) ndarray[Any, dtype[Any]]#

Get an array shaped as a variable with this representation, where each value correspond to the member of the input group.

get_member_tuples() List[Tuple[Any, ...]]#

Get a (flat) list of all member tuples of this representation

get_members() Tuple[ndarray[Any, dtype[ScalarType]], ...]#
Get member arrays for all groups of this representation. For documentation of a member array, see

Representation.get_member_array().

get_shape() Tuple[int, ...]#

Get the shape of a variable corresponding to a component with this representation

map(element: object, target_representation: Representation)#
Map/transform an element (variable or equivalent) corresponding to this representation to a target

representation.

Parameters:
  • element – The object/variable to transform.

  • target_representation – The representation that corresponds to the shape the variable should be in.

Returns:

The element but transformed to target representation.

merge(other)#

Create a new Representation by adding upp groups from this object and from another.

Parameters:

other – Other Representation to merge with

Returns:

Merged representation. Note that all groups of the merged has either a twin or a parent group in at least one of the two input representations.