DisCoPy bridge¶
Convert an |
|
Convert a |
|
Wrap an |
|
Wrap an |
|
Convert a Markov box with array data to an |
|
Evaluate a Markov diagram as an |
|
Interpret |
- fxtensor_salmon.discopy.to_tensor(tensor)[source]¶
Convert an
FXTensorto adiscopy.tensor.Tensor.Axis order is domain factors then codomain factors, matching
Tensor.arrayasdom.inside + cod.inside. Empty domain or codomain becomes the monoidal unitDim(). Labels are dropped; restore them withfrom_tensor()or useto_box().- Parameters:
tensor (FXTensor)
- Return type:
Tensor
- fxtensor_salmon.discopy.from_tensor(tensor, labels=None)[source]¶
Convert a
discopy.tensor.Tensorto anFXTensor.labelsis an optional(domain_labels, codomain_labels)pair in the same format asFXTensor.labels. Without it the result is unlabeled and usestensor.dom.inside/tensor.cod.inside.- Parameters:
tensor (Tensor)
labels (Tuple[List[List[str]], List[List[str]]] | None)
- Return type:
- fxtensor_salmon.discopy.to_box(tensor, name='FXTensor')[source]¶
Wrap an
FXTensoras adiscopy.markov.Box.Each profile factor becomes one wire. Unlabeled factor
nis namedn; labeled factor['Sunny', 'Rainy']is stored as a JSON list on the type name sofrom_box()can restore it.- Parameters:
tensor (FXTensor)
name (str)
- Return type:
Box
- fxtensor_salmon.discopy.to_diagram(tensor, name='FXTensor')[source]¶
Wrap an
FXTensoras a Markov diagram (a single box).- Parameters:
tensor (FXTensor)
name (str)
- Return type:
Diagram
- fxtensor_salmon.discopy.from_box(box)[source]¶
Convert a Markov box with array data to an
FXTensor.Dimensions come from
box.data(reshaped todomthencod) and labels are restored from type names produced byto_box().- Parameters:
box (Box)
- Return type:
- fxtensor_salmon.discopy.from_diagram(diagram, ob=None, ar=None)[source]¶
Evaluate a Markov diagram as an
FXTensor.A single box with data is converted directly. Composite diagrams are interpreted by
FXTensorFunctor. Object images are inferred from encoded type names whenobis omitted.
- class fxtensor_salmon.discopy.FXTensorFunctor(ob, ar=None)[source]¶
Interpret
discopy.markovdiagrams asFXTensormorphisms.Copy, Discard, Swap and Id are sent to
FXTensor.copy_tensor(),FXTensor.exclamation(),FXTensor.swap()andFXTensor.identity_tensor(). Custom boxes are read fromar(anFXTensor, a DisCoPyTensor, or an array).- Parameters:
ob (Union[Mapping[Ty, ObImage], Callable[[Ob], ObImage]]) – Atomic
Tyto a dimension (int), a label list, or aDim.ar (Optional[Union[Mapping[Box, ArImage], Callable[[Box], ArImage]]]) – Generating
Boxto anFXTensoror array. Copy / Discard / Swap / Id are interpreted automatically and need no entry.