Skip to content

Commit 17fba10

Browse files
authored
Docs for 2.1.0 (#397)
* fix inaccuracte type hint * fix docstring typos * update changelog, nep-29 info; add save/load docs * minor docs improvment * mention py310
1 parent d8a596c commit 17fba10

File tree

8 files changed

+89
-16
lines changed

8 files changed

+89
-16
lines changed

docs/source/changes.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,40 @@ This is a record of all past mygrad releases and what went into them,
66
in reverse chronological order. All previous releases should still be available
77
on pip.
88

9+
.. _v2.1.0:
10+
11+
------------------
12+
2.1.0 - 2022-01-01
13+
------------------
14+
15+
New Functions and Utilities
16+
---------------------------
17+
18+
The following differentiable functions are now supported by MyGrad, and "drop-in" overrides for their NumPy counterparts are supported as well.
19+
20+
- :func:`~mygrad.atleast_1d`
21+
- :func:`~mygrad.atleast_2d`
22+
- :func:`~mygrad.atleast_3d`
23+
24+
Basic tensor save/load functionality has been added (thanks to @kw-0).
25+
26+
- :func:`~mygrad.save`
27+
- :func:`~mygrad.load`
28+
29+
Improvements
30+
------------
31+
32+
- :func:`~mygrad.clip` and ``Tensor.clip`` now accept an ``out`` target, permitting in-place operations.
33+
- The method ``Tensor.__index__()`` is now implemented, which permits scalar integer-valued tensors to be used to index into Python sequences.
34+
- Added Python 3.10 to our automated test matrix.
35+
36+
Compatibility-Breaking Changes
37+
------------------------------
38+
39+
- In accordance with `NEP 29 <https://numpy.org/neps/nep-0029-deprecation_policy.html>`_ we are dropping support for NumPy versions below 1.19. However, MyGrad will not drop support for Python 3.7; to remain as lightweight and flexible as possible we will support minor versions of Python up until their EOL or until our minimal NumPy dependency drops support -- whichever occurs first.
40+
- The interface to :func:`~mygrad.arange` was changed from ``arange(start, stop=None, step=None, ...)`` to ``arange([start,] stop[, step,], ...)``. This provides exact parity with NumPy's arange function.
41+
- The derivatives of :func:`~mygrad.absolute` and :func:`~mygrad.linalg.norm` have been revised such that in cases where the derivatives used to be ``nan``, those entries will now be ``0``. Both functions can now be passed ``nan_to_num=False`` to enable the previous, more rigorous behavior. See `PR #379 <https://github.com/rsokl/MyGrad/pull/379>`_ for more details.
42+
943
.. _v2.0.2:
1044

1145
------------------

docs/source/generated/mygrad.load.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
mygrad.load
2+
===========
3+
4+
.. currentmodule:: mygrad
5+
6+
.. autofunction:: load

docs/source/generated/mygrad.save.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
mygrad.save
2+
===========
3+
4+
.. currentmodule:: mygrad
5+
6+
.. autofunction:: save

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,6 @@ during automatic differentiation
114114
math
115115
indexing
116116
nnet
117+
io
117118
graph_viz
118119
changes

docs/source/install.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ navigate to the MyGrad directory, then run:
2424
Support for Python and NumPy
2525
----------------------------
2626
MyGrad abides by the `NEP 29 <https://numpy.org/neps/nep-0029-deprecation_policy.html>`_ recommendation, and adopts
27-
a common “time window-based” policy for support of Python and NumPy versions.
28-
29-
Accordingly, MyGrad's drop schedule for Python and NumPy can be found `here <https://numpy.org/neps/nep-0029-deprecation_policy.html#drop-schedule>`_.
27+
a common “time window-based” policy for support of NumPy versions. Accordingly, MyGrad's drop schedule for NumPy versions can be found `here <https://numpy.org/neps/nep-0029-deprecation_policy.html#drop-schedule>`_.
28+
29+
Note, however, that MyGrad will maintain a wider window of support for minor Python
30+
versions than is specified by NEP 29. Because our only dependency is NumPy, and because
31+
we strive to remain an exceptionally lightweight and flexible dependency to our users,
32+
we will support minor versions of Python until their end of life, *or* until our lowest
33+
supported version of NumPy drops support for that version of Python -- whichever occurs
34+
first.

docs/source/io.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Input and Output
2+
****************
3+
4+
.. currentmodule:: mygrad
5+
6+
NumPy binary files (NPY, NPZ)
7+
-----------------------------
8+
.. autosummary::
9+
:toctree: generated/
10+
11+
save
12+
load

src/mygrad/tensor_base.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ def astensor(
396396
}
397397

398398

399-
_REGISTERED_NO_DIFF_NUMPY_FUNCS: Set[Callable[..., np.ndarray]] = {
399+
_REGISTERED_NO_DIFF_NUMPY_FUNCS: Set[Callable] = {
400400
np.allclose,
401401
np.bincount,
402402
np.can_cast,
@@ -1528,17 +1528,20 @@ def constant(self) -> bool:
15281528
return self._constant
15291529

15301530
@property
1531-
def creator(self) -> Operation:
1531+
def creator(self) -> Optional[Operation]:
15321532
"""The ``Operation`` instance that produced ``self``.
15331533
15341534
Returns
15351535
-------
1536-
Operation
1536+
creator : Optional[Operation]
1537+
The operation-instance that created the tensor, or `None`.
15371538
15381539
Examples
15391540
--------
15401541
>>> import mygrad as mg
15411542
>>> x = mg.Tensor(3)
1543+
>>> x.creator is None
1544+
True
15421545
>>> y = mg.Tensor(2)
15431546
>>> z = x * y # Multiply(x, y) -> z
15441547
>>> z.creator

src/mygrad/tensor_manip/array_shape/funcs.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def atleast_1d(
296296
297297
Returns
298298
-------
299-
ret : Tensor
299+
ret : Tensor | List[Tensor]
300300
A tensor, or list of tensors, each with ``a.ndim >= 1``.
301301
Copies are made only if necessary.
302302
@@ -373,7 +373,7 @@ def atleast_2d(
373373
374374
Returns
375375
-------
376-
ret : Tensor
376+
ret : Tensor | List[Tensor]
377377
A tensor, or list of tensors, each with ``a.ndim >= 2``.
378378
Copies are made only if necessary.
379379
@@ -406,7 +406,7 @@ def atleast_2d(
406406
>>> x.grad
407407
array(1.)
408408
409-
If any argument to ``numpy.atleast_2d`` is a Tensor, ``mygrad.atleast_1d``
409+
If any argument to ``numpy.atleast_2d`` is a Tensor, ``mygrad.atleast_2d``
410410
will be dispatched on all of the arguments.
411411
412412
>>> np.atleast_2d(x, 1.)
@@ -436,7 +436,7 @@ def atleast_3d(
436436
"""
437437
Convert inputs to tensors with at least one dimension.
438438
439-
Scalar inputs are converted to 2-dimensional tensors, whilst
439+
Scalar inputs are converted to 3-dimensional tensors, whilst
440440
higher-dimensional inputs are preserved.
441441
442442
This docstring was adapted from ``numpy.atleast_3d``.
@@ -448,9 +448,11 @@ def atleast_3d(
448448
449449
Returns
450450
-------
451-
ret : Tensor
452-
A tensor, or list of tensors, each with ``a.ndim >= 2``.
453-
Copies are made only if necessary.
451+
ret : Tensor | List[Tensor]
452+
A tensor, or list of tensors, each with ``a.ndim >= 3``.
453+
Copies are made only if necessary. For example, a 1-D tensor of shape ``(N,)``
454+
becomes a view of shape ``(1, N, 1)``, and a 2-D tensor of shape ``(M, N)``
455+
becomes a view of shape ``(M, N, 1)``.
454456
455457
See Also
456458
--------
@@ -463,11 +465,15 @@ def atleast_3d(
463465
Tensor([[[3.]]])
464466
465467
>>> x = mg.arange(3.0)
466-
>>> mg.atleast_3d(x)
467-
array([[0., 1., 2.]])
468+
>>> mg.atleast_3d(x).shape
469+
(1, 3, 1)
468470
>>> mg.atleast_3d(x).base is x
469471
True
470472
473+
>>> x = mg.arange(12.0).reshape(4,3)
474+
>>> mg.atleast_3d(x).shape
475+
(4, 3, 1)
476+
471477
>>> mg.atleast_3d(1, [[1, 2]], [[[[1, 2]]]])
472478
[Tensor([[[1]]]), Tensor([[[1, 2]]]), Tensor([[[[1, 2]]]])]
473479
@@ -481,7 +487,7 @@ def atleast_3d(
481487
>>> x.grad
482488
array(1.)
483489
484-
If any argument to ``numpy.atleast_3d`` is a Tensor, ``mygrad.atleast_1d``
490+
If any argument to ``numpy.atleast_3d`` is a Tensor, ``mygrad.atleast_3d``
485491
will be dispatched on all of the arguments.
486492
487493
>>> np.atleast_3d(x, 1.)

0 commit comments

Comments
 (0)