Skip to content

Commit c5f2a60

Browse files
committed
rename ob_cls -> ob_factory
1 parent 3b3f214 commit c5f2a60

File tree

8 files changed

+34
-34
lines changed

8 files changed

+34
-34
lines changed

cartesian.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class PythonFunctor(rigidcat.Functor):
156156
Implements functors into the category of Python functions on tuples
157157
"""
158158
def __init__(self, ob, ar):
159-
super().__init__(ob, ar, ob_cls=PRO, ar_cls=Function)
159+
super().__init__(ob, ar, ob_factory=PRO, ar_factory=Function)
160160

161161

162162
class Diagram(rigidcat.Diagram):
@@ -317,7 +317,7 @@ class Functor(rigidcat.Functor):
317317
>>> assert F(f >> g)(43) == 86
318318
"""
319319
def __init__(self, ob, ar):
320-
super().__init__(ob, ar, ob_cls=PRO, ar_cls=Diagram)
320+
super().__init__(ob, ar, ob_factory=PRO, ar_factory=Diagram)
321321

322322

323323
def disco(dom, cod, name=None):

cat.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ class Functor:
484484
485485
By default, `Functor` defines an endofunctor from the free dagger category
486486
to itself. The codomain can be changed with the optional parameters
487-
`ob_cls` and `ar_cls`.
487+
`ob_factory` and `ar_factory`.
488488
489489
>>> x, y, z = Ob('x'), Ob('y'), Ob('z')
490490
>>> f, g = Box('f', x, y), Box('g', y, z)
@@ -495,16 +495,16 @@ class Functor:
495495
Parameters
496496
----------
497497
ob : dict_like
498-
Mapping from :class:`cat.Ob` to `ob_cls`.
498+
Mapping from :class:`cat.Ob` to `ob_factory`.
499499
ar : dict_like
500-
Mapping from :class:`cat.Box` to `ar_cls`.
500+
Mapping from :class:`cat.Box` to `ar_factory`.
501501
502502
Other Parameters
503503
----------------
504-
ob_cls : type, optional
504+
ob_factory : type, optional
505505
Class to be used as objects for the codomain of the functor.
506506
If None, this will be set to :class:`cat.Ob`.
507-
ar_cls : type, optional
507+
ar_factory : type, optional
508508
Class to be used as arrows for the codomain of the functor.
509509
If None, this will be set to :class:`cat.Arrow`.
510510
@@ -522,12 +522,12 @@ class Functor:
522522
>>> assert F(f[::-1]) == F(f)[::-1]
523523
>>> assert F(f.dom) == F(f).dom and F(f.cod) == F(f).cod
524524
"""
525-
def __init__(self, ob, ar, ob_cls=None, ar_cls=None):
526-
if ob_cls is None:
527-
ob_cls = Ob
528-
if ar_cls is None:
529-
ar_cls = Arrow
530-
self.ob_cls, self.ar_cls = ob_cls, ar_cls
525+
def __init__(self, ob, ar, ob_factory=None, ar_factory=None):
526+
if ob_factory is None:
527+
ob_factory = Ob
528+
if ar_factory is None:
529+
ar_factory = Arrow
530+
self.ob_factory, self.ar_factory = ob_factory, ar_factory
531531
self._ob, self._ar = ob, ar
532532

533533
@property
@@ -561,7 +561,7 @@ def __call__(self, arrow):
561561
return self.ar[arrow.dagger()].dagger()
562562
return self.ar[arrow]
563563
if isinstance(arrow, Arrow):
564-
return self.ar_cls.id(self(arrow.dom)).compose(
564+
return self.ar_factory.id(self(arrow.dom)).compose(
565565
*map(self, arrow.boxes))
566566
raise TypeError(messages.type_err(Arrow, arrow))
567567

circuit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ class CircuitFunctor(Functor):
963963
SWAP @ Id(1) >> Id(1) @ Rx(0.25) @ Id(1) >> Id(1) @ CX
964964
"""
965965
def __init__(self, ob, ar):
966-
super().__init__(ob, ar, ob_cls=PRO, ar_cls=Circuit)
966+
super().__init__(ob, ar, ob_factory=PRO, ar_factory=Circuit)
967967

968968
def __repr__(self):
969969
"""

moncat.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ class Functor(cat.Functor):
806806
"""
807807
Implements a monoidal functor given its image on objects and arrows.
808808
One may define monoidal functors into custom categories by overriding
809-
the defaults ob_cls=Ty and ar_cls=Diagram.
809+
the defaults ob_factory=Ty and ar_factory=Diagram.
810810
811811
>>> x, y, z, w = Ty('x'), Ty('y'), Ty('z'), Ty('w')
812812
>>> f0, f1 = Box('f0', x, y, data=[0.1]), Box('f1', z, w, data=[1.1])
@@ -816,24 +816,24 @@ class Functor(cat.Functor):
816816
>>> assert F(f0 @ f1) == f1 @ f0
817817
>>> assert F(f0 >> f0[::-1]) == f1 >> f1[::-1]
818818
"""
819-
def __init__(self, ob, ar, ob_cls=None, ar_cls=None):
820-
if ob_cls is None:
821-
ob_cls = Ty
822-
if ar_cls is None:
823-
ar_cls = Diagram
824-
super().__init__(ob, ar, ob_cls=ob_cls, ar_cls=ar_cls)
819+
def __init__(self, ob, ar, ob_factory=None, ar_factory=None):
820+
if ob_factory is None:
821+
ob_factory = Ty
822+
if ar_factory is None:
823+
ar_factory = Diagram
824+
super().__init__(ob, ar, ob_factory=ob_factory, ar_factory=ar_factory)
825825

826826
def __call__(self, diagram):
827827
if isinstance(diagram, Ty):
828828
return sum([self.ob[type(diagram)(x)] for x in diagram],
829-
self.ob_cls()) # the empty type is the unit for sum.
829+
self.ob_factory()) # the empty type is the unit for sum.
830830
if isinstance(diagram, Box):
831831
return super().__call__(diagram)
832832
if isinstance(diagram, Diagram):
833-
scan, result = diagram.dom, self.ar_cls.id(self(diagram.dom))
833+
scan, result = diagram.dom, self.ar_factory.id(self(diagram.dom))
834834
for box, off in zip(diagram.boxes, diagram.offsets):
835-
id_l = self.ar_cls.id(self(scan[:off]))
836-
id_r = self.ar_cls.id(self(scan[off + len(box.dom):]))
835+
id_l = self.ar_factory.id(self(scan[:off]))
836+
id_r = self.ar_factory.id(self(scan[off + len(box.dom):]))
837837
result = result >> id_l @ self(box) @ id_r
838838
scan = scan[:off] + box.cod + scan[off + len(box.dom):]
839839
return result

notebooks/monoid-delooping.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
"\n",
133133
"class MonoidFunctor(Functor):\n",
134134
" def __init__(self, ob, ar):\n",
135-
" super().__init__(ob, ar, ar_cls=Monoid)\n",
135+
" super().__init__(ob, ar, ar_factory=Monoid)\n",
136136
"\n",
137137
"ob = {x: Ty() for x in [s, n, tv, itv]}\n",
138138
"ar = {r0: Monoid(0.25), r1: Monoid(2.0)}\n",

notebooks/snake-removal.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
" update @ Diagram.id(s.l @ n))\n",
156156
" }\n",
157157
"\n",
158-
"A = Functor(ob, ar, ob_cls=Ty, ar_cls=Diagram)"
158+
"A = Functor(ob, ar, ob_factory=Ty, ar_factory=Diagram)"
159159
]
160160
},
161161
{

rigidcat.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -513,13 +513,13 @@ class Functor(moncat.Functor):
513513
>>> sentence = Alice @ loves @ Bob >> Cup(n, n.r) @ Id(s) @ Cup(n.l, n)
514514
>>> assert F(sentence).normal_form() == Alice >> Id(n) @ Bob >> love_box
515515
"""
516-
def __init__(self, ob, ar, ob_cls=Ty, ar_cls=Diagram):
516+
def __init__(self, ob, ar, ob_factory=Ty, ar_factory=Diagram):
517517
"""
518518
>>> F = Functor({Ty('x'): Ty('y')}, {})
519519
>>> F(Id(Ty('x')))
520520
Id(Ty('y'))
521521
"""
522-
super().__init__(ob, ar, ob_cls=ob_cls, ar_cls=ar_cls)
522+
super().__init__(ob, ar, ob_factory=ob_factory, ar_factory=ar_factory)
523523

524524
def __call__(self, diagram):
525525
"""
@@ -530,7 +530,7 @@ def __call__(self, diagram):
530530
>>> assert F(f.transpose_r()) == F(f).transpose_r()
531531
"""
532532
if isinstance(diagram, Ty):
533-
return sum([self(b) for b in diagram.objects], self.ob_cls())
533+
return sum([self(b) for b in diagram.objects], self.ob_factory())
534534
if isinstance(diagram, Ob) and not diagram.z:
535535
return self.ob[Ty(diagram.name)]
536536
if isinstance(diagram, Ob):
@@ -543,9 +543,9 @@ def __call__(self, diagram):
543543
result = result.r
544544
return result
545545
if isinstance(diagram, Cup):
546-
return self.ar_cls.cups(self(diagram.dom[0]), self(diagram.dom[1]))
546+
return self.ar_factory.cups(self(diagram.dom[0]), self(diagram.dom[1]))
547547
if isinstance(diagram, Cap):
548-
return self.ar_cls.caps(self(diagram.cod[0]), self(diagram.cod[1]))
548+
return self.ar_factory.caps(self(diagram.cod[0]), self(diagram.cod[1]))
549549
if isinstance(diagram, Diagram):
550550
return super().__call__(diagram)
551551
raise TypeError(messages.type_err(Diagram, diagram))

tensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class TensorFunctor(Functor):
201201
Tensor(dom=Dim(1), cod=Dim(2), array=[0, 1])
202202
"""
203203
def __init__(self, ob, ar):
204-
super().__init__(ob, ar, ob_cls=Dim, ar_cls=Tensor)
204+
super().__init__(ob, ar, ob_factory=Dim, ar_factory=Tensor)
205205

206206
def __repr__(self):
207207
return super().__repr__().replace("Functor", "TensorFunctor")

0 commit comments

Comments
 (0)