|
1 | | -""" |
2 | | -Provide a simple user friendly API to PyTensor-managed memory. |
3 | | -
|
4 | | -""" |
| 1 | +"""Provide a simple user friendly API to PyTensor-managed memory.""" |
5 | 2 |
|
6 | 3 | import copy |
7 | 4 | from contextlib import contextmanager |
@@ -30,52 +27,14 @@ def collect_new_shareds(): |
30 | 27 |
|
31 | 28 |
|
32 | 29 | class SharedVariable(Variable): |
33 | | - """ |
34 | | - Variable that is (defaults to being) shared between functions that |
35 | | - it appears in. |
36 | | -
|
37 | | - Parameters |
38 | | - ---------- |
39 | | - name : str |
40 | | - The name for this variable (see `Variable`). |
41 | | - type : str |
42 | | - The type for this variable (see `Variable`). |
43 | | - value |
44 | | - A value to associate with this variable (a new container will be |
45 | | - created). |
46 | | - strict |
47 | | - True : assignments to .value will not be cast or copied, so they must |
48 | | - have the correct type. |
49 | | - allow_downcast |
50 | | - Only applies if `strict` is False. |
51 | | - True : allow assigned value to lose precision when cast during |
52 | | - assignment. |
53 | | - False : never allow precision loss. |
54 | | - None : only allow downcasting of a Python float to a scalar floatX. |
55 | | - container |
56 | | - The container to use for this variable. Illegal to pass this as well as |
57 | | - a value. |
58 | | -
|
59 | | - Notes |
60 | | - ----- |
61 | | - For more user-friendly constructor, see `shared`. |
| 30 | + """Variable that is shared between compiled functions.""" |
62 | 31 |
|
63 | | - """ |
64 | | - |
65 | | - # Container object |
66 | | - container = None |
| 32 | + container: Optional[Container] = None |
67 | 33 | """ |
68 | 34 | A container to use for this SharedVariable when it is an implicit |
69 | 35 | function parameter. |
70 | | -
|
71 | | - :type: `Container` |
72 | 36 | """ |
73 | 37 |
|
74 | | - # default_update |
75 | | - # If this member is present, its value will be used as the "update" for |
76 | | - # this Variable, unless another update value has been passed to "function", |
77 | | - # or the "no_default_updates" list passed to "function" contains it. |
78 | | - |
79 | 38 | def __init__(self, name, type, value, strict, allow_downcast=None, container=None): |
80 | 39 | super().__init__(type=type, name=name, owner=None, index=None) |
81 | 40 |
|
@@ -207,37 +166,30 @@ def shared_constructor(ctor, remove=False): |
207 | 166 |
|
208 | 167 |
|
209 | 168 | def shared(value, name=None, strict=False, allow_downcast=None, **kwargs): |
210 | | - """Return a SharedVariable Variable, initialized with a copy or |
211 | | - reference of `value`. |
| 169 | + r"""Create a `SharedVariable` initialized with a copy or reference of `value`. |
212 | 170 |
|
213 | 171 | This function iterates over constructor functions to find a |
214 | | - suitable SharedVariable subclass. The suitable one is the first |
| 172 | + suitable `SharedVariable` subclass. The suitable one is the first |
215 | 173 | constructor that accept the given value. See the documentation of |
216 | 174 | :func:`shared_constructor` for the definition of a constructor |
217 | 175 | function. |
218 | 176 |
|
219 | 177 | This function is meant as a convenient default. If you want to use a |
220 | | - specific shared variable constructor, consider calling it directly. |
221 | | -
|
222 | | - ``pytensor.shared`` is a shortcut to this function. |
223 | | -
|
224 | | - .. attribute:: constructors |
| 178 | + specific constructor, consider calling it directly. |
225 | 179 |
|
226 | | - A list of shared variable constructors that will be tried in reverse |
227 | | - order. |
| 180 | + `pytensor.shared` is a shortcut to this function. |
228 | 181 |
|
229 | 182 | Notes |
230 | 183 | ----- |
231 | 184 | By passing kwargs, you effectively limit the set of potential constructors |
232 | 185 | to those that can accept those kwargs. |
233 | 186 |
|
234 | | - Some shared variable have ``borrow`` as extra kwargs. |
| 187 | + Some shared variable have `borrow` as a kwarg. |
235 | 188 |
|
236 | | - Some shared variable have ``broadcastable`` as extra kwargs. As shared |
| 189 | + `SharedVariable`\s of `TensorType` have `broadcastable` as a kwarg. As shared |
237 | 190 | variable shapes can change, all dimensions default to not being |
238 | | - broadcastable, even if ``value`` has a shape of 1 along some dimension. |
239 | | - This parameter allows you to create for example a `row` or `column` 2d |
240 | | - tensor. |
| 191 | + broadcastable, even if `value` has a shape of 1 along some dimension. |
| 192 | + This parameter allows one to create for example a row or column tensor. |
241 | 193 |
|
242 | 194 | """ |
243 | 195 |
|
|
0 commit comments