FunTuple.FunctorCollection
Attributes
Classes
Class to hold the functor/variable dictionary. |
Module Contents
- class FunctorCollection(functor_dict: Type_FunctorDict = {})[source]
Class to hold the functor/variable dictionary.
- functor_dict[source]
dictionary of functors/variables, whose key is the field (branch) name suffix and value is the Functor code.
- Methods are largely the same as for a dict class with specific requirements:
update : extends a given dictionary of functors to the collection, throwing a warning about overwriting an entry if it already exists. pop : given a name or list of names it removes the functors from the collection, raising an error if the entry(ies) does(do) not exist. add operator (+) : adds two FunctorCollection, for common entries warns the user about picking the entry from “base” FunctorCollection instance. sub operator (-) : returns a FunctorCollection that contains unique entries between two FunctorCollections. get_loki_functors(self): returns dictionary of loki functors get_thor_functors(self): returns dictionary of thor functors
- update(functor_dict_new: Type_FunctorDict)[source]
Add new entries to the FunctorCollection given a dictionary. Raises a user warning about overwriting an entry if it already exists.
- pop(functor_names: str | list[str])[source]
Remove an entry or a list of entries from the FunctorCollection.
- Parameters:
functor_names (str or list) – entries to be removed.
- Raises:
AttributeError – if the input is not adequate.
KeyError – if an entry to be removed does not exist.
- __repr__() str [source]
Representation as a string in the common ‘<…>’ format, providing the number of ThOr and LoKi functors stored.
- __str__() str [source]
print(FunctorCollection) gives all the entries inside the FunctorCollection.
- __add__(other: Self_FunctorCollection) Self_FunctorCollection [source]
Return all entries from two FunctorCollection e.g. FunctorCollection_1(A,B) + FuntorCollection_2(B,C) gives FunctorCollection(A,B,C) where B is from FunctorCollection_1. Raises a user warning about common entries (this should rather be an error, I think)
- __iadd__(other: Self_FunctorCollection) Self_FunctorCollection [source]
Return self adding the entries in FunctorCollection ‘other’.
- Raises:
TypeError – if the input type is not adequate, i.e a FunctorCollection instance.
- __sub__(other: Self_FunctorCollection) Self_FunctorCollection [source]
Return unique entries from two FunctorCollections, e.g. FunctorCollection_1(A,B) - FuntorCollection_2(B,C) gives FunctorCollection(A,C)
- Raises:
RuntimeError – if the two functors do not have any unique entries.
- __isub__(other: Self_FunctorCollection) Self_FunctorCollection [source]
Return self subtraction of the entries in FunctorCollection ‘other’.
See __sub__ for a description of the behaviour.
- __contains__(key: str) bool [source]
Check for key containment.
Example
>>> c = FunctorCollection({"PT": F.PT}) >>> "PT" in c True >>> "Nope" in c False
- get_loki_functors() dict[str, str] [source]
Return dictionary of loki functors (checking if the values are strings or not).
- get_thor_functors() dict[str, Functors.grammar.FunctorBase] [source]
Return dictionary of thor functors (checking if the values are not strings). Explicitly type checking for ThOr needed here are they always of type ‘Functors.grammar.BoundFunctor’(?)
- __setitem__(key: str, value: Functors.grammar.FunctorBase | str) None [source]
Add an item to the dictionary.