class sakkara.relation.representation.Representation(*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 Representation 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 i:th group.

get_members() Tuple[ndarray[Any, dtype[Any]], ...]#

Get array of members corresponding to the indices of a variable with the representation

Returns:

One array per group of representation filled with corresponding member names, so that the i:th array correspond to the i:th group of the representation

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_to(target: Representation) Tuple[ndarray[Any, dtype[int]], ...] | slice#

Create indexing for a variable of this representation to another target representation.

Parameters:

target – The representation that corresponds to the shape the variable should be in. Each group of self representation must have a twin or a child in the target representation.

Returns:

Tuple of index arrays, or slice object, to be used for indexing on array object. For more information about the format of this tuple, see https://numpy.org/doc/stable/user/basics.indexing.html#advanced-indexing.

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.