effectful 0.1.0__py3-none-any.whl → 0.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,263 +0,0 @@
1
- """
2
- This module provides a term representation for numbers and operations on them.
3
- """
4
-
5
- import numbers
6
- import operator
7
- from typing import Any, TypeVar
8
-
9
- from typing_extensions import ParamSpec
10
-
11
- from effectful.ops.syntax import defdata, defop, syntactic_eq
12
- from effectful.ops.types import Expr, Operation, Term
13
-
14
- P = ParamSpec("P")
15
- Q = ParamSpec("Q")
16
- S = TypeVar("S")
17
- T = TypeVar("T")
18
- V = TypeVar("V")
19
-
20
- T_Number = TypeVar("T_Number", bound=numbers.Number)
21
-
22
-
23
- @defdata.register(numbers.Number)
24
- @numbers.Number.register
25
- class _NumberTerm(Term[numbers.Number]):
26
- def __init__(
27
- self, op: Operation[..., numbers.Number], *args: Expr, **kwargs: Expr
28
- ) -> None:
29
- self._op = op
30
- self._args = args
31
- self._kwargs = kwargs
32
-
33
- @property
34
- def op(self) -> Operation[..., numbers.Number]:
35
- return self._op
36
-
37
- @property
38
- def args(self) -> tuple:
39
- return self._args
40
-
41
- @property
42
- def kwargs(self) -> dict:
43
- return self._kwargs
44
-
45
- def __hash__(self):
46
- return hash((self.op, tuple(self.args), tuple(self.kwargs.items())))
47
-
48
-
49
- # Complex specific methods
50
- @defop
51
- def eq(x: T_Number, y: T_Number) -> bool:
52
- if not any(isinstance(a, Term) for a in (x, y)):
53
- return operator.eq(x, y)
54
- else:
55
- return syntactic_eq(x, y)
56
-
57
-
58
- def _wrap_cmp(op):
59
- def _wrapped_op(x: T_Number, y: T_Number) -> bool:
60
- if not any(isinstance(a, Term) for a in (x, y)):
61
- return op(x, y)
62
- else:
63
- raise NotImplementedError
64
-
65
- _wrapped_op.__name__ = op.__name__
66
- return _wrapped_op
67
-
68
-
69
- def _wrap_binop(op):
70
- def _wrapped_op(x: T_Number, y: T_Number) -> T_Number:
71
- if not any(isinstance(a, Term) for a in (x, y)):
72
- return op(x, y)
73
- else:
74
- raise NotImplementedError
75
-
76
- _wrapped_op.__name__ = op.__name__
77
- return _wrapped_op
78
-
79
-
80
- def _wrap_unop(op):
81
- def _wrapped_op(x: T_Number) -> T_Number:
82
- if not isinstance(x, Term):
83
- return op(x)
84
- else:
85
- raise NotImplementedError
86
-
87
- _wrapped_op.__name__ = op.__name__
88
- return _wrapped_op
89
-
90
-
91
- add = defop(_wrap_binop(operator.add))
92
- neg = defop(_wrap_unop(operator.neg))
93
- pos = defop(_wrap_unop(operator.pos))
94
- sub = defop(_wrap_binop(operator.sub))
95
- mul = defop(_wrap_binop(operator.mul))
96
- truediv = defop(_wrap_binop(operator.truediv))
97
- pow = defop(_wrap_binop(operator.pow))
98
- abs = defop(_wrap_unop(operator.abs))
99
-
100
-
101
- @defdata.register(numbers.Complex)
102
- @numbers.Complex.register
103
- class _ComplexTerm(_NumberTerm, Term[numbers.Complex]):
104
- def __bool__(self) -> bool:
105
- raise ValueError("Cannot convert term to bool")
106
-
107
- def __add__(self, other: Any) -> numbers.Real:
108
- return add(self, other)
109
-
110
- def __radd__(self, other: Any) -> numbers.Real:
111
- return add(other, self)
112
-
113
- def __neg__(self):
114
- return neg(self)
115
-
116
- def __pos__(self):
117
- return pos(self)
118
-
119
- def __sub__(self, other: Any) -> numbers.Real:
120
- return sub(self, other)
121
-
122
- def __rsub__(self, other: Any) -> numbers.Real:
123
- return sub(other, self)
124
-
125
- def __mul__(self, other: Any) -> numbers.Real:
126
- return mul(self, other)
127
-
128
- def __rmul__(self, other: Any) -> numbers.Real:
129
- return mul(other, self)
130
-
131
- def __truediv__(self, other: Any) -> numbers.Real:
132
- return truediv(self, other)
133
-
134
- def __rtruediv__(self, other: Any) -> numbers.Real:
135
- return truediv(other, self)
136
-
137
- def __pow__(self, other: Any) -> numbers.Real:
138
- return pow(self, other)
139
-
140
- def __rpow__(self, other: Any) -> numbers.Real:
141
- return pow(other, self)
142
-
143
- def __abs__(self) -> numbers.Real:
144
- return abs(self)
145
-
146
- def __eq__(self, other: Any) -> bool:
147
- return eq(self, other)
148
-
149
-
150
- # Real specific methods
151
- floordiv = defop(_wrap_binop(operator.floordiv))
152
- mod = defop(_wrap_binop(operator.mod))
153
- lt = defop(_wrap_cmp(operator.lt))
154
- le = defop(_wrap_cmp(operator.le))
155
- gt = defop(_wrap_cmp(operator.gt))
156
- ge = defop(_wrap_cmp(operator.ge))
157
-
158
-
159
- @defdata.register(numbers.Real)
160
- @numbers.Real.register
161
- class _RealTerm(_ComplexTerm, Term[numbers.Real]):
162
- # Real specific methods
163
- def __float__(self) -> float:
164
- raise ValueError("Cannot convert term to float")
165
-
166
- def __trunc__(self) -> numbers.Integral:
167
- raise NotImplementedError
168
-
169
- def __floor__(self) -> numbers.Integral:
170
- raise NotImplementedError
171
-
172
- def __ceil__(self) -> numbers.Integral:
173
- raise NotImplementedError
174
-
175
- def __round__(self, ndigits=None) -> numbers.Integral:
176
- raise NotImplementedError
177
-
178
- def __floordiv__(self, other):
179
- return floordiv(self, other)
180
-
181
- def __rfloordiv__(self, other):
182
- return floordiv(other, self)
183
-
184
- def __mod__(self, other):
185
- return mod(self, other)
186
-
187
- def __rmod__(self, other):
188
- return mod(other, self)
189
-
190
- def __lt__(self, other):
191
- return lt(self, other)
192
-
193
- def __le__(self, other):
194
- return le(self, other)
195
-
196
-
197
- @defdata.register(numbers.Rational)
198
- @numbers.Rational.register
199
- class _RationalTerm(_RealTerm, Term[numbers.Rational]):
200
- @property
201
- def numerator(self):
202
- raise NotImplementedError
203
-
204
- @property
205
- def denominator(self):
206
- raise NotImplementedError
207
-
208
-
209
- # Integral specific methods
210
- index = defop(_wrap_unop(operator.index))
211
- lshift = defop(_wrap_binop(operator.lshift))
212
- rshift = defop(_wrap_binop(operator.rshift))
213
- and_ = defop(_wrap_binop(operator.and_))
214
- xor = defop(_wrap_binop(operator.xor))
215
- or_ = defop(_wrap_binop(operator.or_))
216
- invert = defop(_wrap_unop(operator.invert))
217
-
218
-
219
- @defdata.register(numbers.Integral)
220
- @numbers.Integral.register
221
- class _IntegralTerm(_RationalTerm, Term[numbers.Integral]):
222
- # Integral specific methods
223
- def __int__(self) -> int:
224
- raise ValueError("Cannot convert term to int")
225
-
226
- def __index__(self) -> numbers.Integral:
227
- return index(self)
228
-
229
- def __pow__(self, exponent: Any, modulus=None) -> numbers.Integral:
230
- return pow(self, exponent)
231
-
232
- def __lshift__(self, other):
233
- return lshift(self, other)
234
-
235
- def __rlshift__(self, other):
236
- return lshift(other, self)
237
-
238
- def __rshift__(self, other):
239
- return rshift(self, other)
240
-
241
- def __rrshift__(self, other):
242
- return rshift(other, self)
243
-
244
- def __and__(self, other):
245
- return and_(self, other)
246
-
247
- def __rand__(self, other):
248
- return and_(other, self)
249
-
250
- def __xor__(self, other):
251
- return xor(self, other)
252
-
253
- def __rxor__(self, other):
254
- return xor(other, self)
255
-
256
- def __or__(self, other):
257
- return or_(self, other)
258
-
259
- def __ror__(self, other):
260
- return or_(other, self)
261
-
262
- def __invert__(self):
263
- return invert(self)
@@ -1,18 +0,0 @@
1
- effectful/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- effectful/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- effectful/handlers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- effectful/handlers/indexed.py,sha256=k98C-Gtm8rQPfCYRCUVEPlElwiD3PwWGZ5hwNTTaIt8,12651
5
- effectful/handlers/numbers.py,sha256=X-RI9IcOahSrwDNF0xZtQwxBvgKbNQpJRB_m9Vzy-Ew,6656
6
- effectful/handlers/pyro.py,sha256=r0Zyv9nNDaAdwujI3J-nlsIrlAHp-AAuLQ5DfG8S2q4,15294
7
- effectful/handlers/torch.py,sha256=cQxrIJUiC2Zmiz6e_OS-DgtVsHGr_MCsoTY2kvZ05Y4,18945
8
- effectful/internals/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- effectful/internals/runtime.py,sha256=E0ce5mfG0-DlTeALYZePWtdxr0AK3y0CPl_LE5pp_0k,1908
10
- effectful/ops/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
- effectful/ops/semantics.py,sha256=w5UWCkUH1UznIB4NKaQE1TCA2cOLlnbRKd0PNma30Rg,10252
12
- effectful/ops/syntax.py,sha256=U2URezErfQPySVpLNd7Wzx6ZXZwHDo4LZOvhalaXeBI,38241
13
- effectful/ops/types.py,sha256=vTg6eQQN5Xq1KIelUfEUvpofO2iJ3x8YbiyPzNESTjQ,3823
14
- effectful-0.1.0.dist-info/LICENSE.md,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
15
- effectful-0.1.0.dist-info/METADATA,sha256=mBVk7m_Lf3GkcR1WVQaKCMJ5f4AeAykMYCocITL7cko,5165
16
- effectful-0.1.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
17
- effectful-0.1.0.dist-info/top_level.txt,sha256=gtuJfrE2nXil_lZLCnqWF2KAbOnJs9ILNvK8WnkRzbs,10
18
- effectful-0.1.0.dist-info/RECORD,,