提交 d1ed0cfe 编写于 作者: HansBug's avatar HansBug 😆

doc(hansbug): split docs for numpy.funcs to serverial pages

上级 adf83c6a
import codecs
import re import re
import numpy as np import numpy as np
...@@ -21,34 +22,44 @@ if __name__ == '__main__': ...@@ -21,34 +22,44 @@ if __name__ == '__main__':
print_title(tnp.funcs.__name__, levelc='=') print_title(tnp.funcs.__name__, levelc='=')
current_module(tnp.funcs.__name__) current_module(tnp.funcs.__name__)
for _name in sorted(tnp.funcs.__all__): with print_block('toctree', params=dict(maxdepth=1)) as tf:
_item = getattr(tnp.funcs, _name) for _name in sorted(tnp.funcs.__all__):
_origin = get_origin(_item) _file_tag = f'funcs.{_name}.auto'
print_title(_name, levelc='-') _filename = f'{_file_tag}.rst'
print(_file_tag, file=tf)
with print_block('autofunction', value=_name):
pass _item = getattr(tnp.funcs, _name)
_origin = get_origin(_item)
if _origin and (_origin.__doc__ or '').strip(): with codecs.open(_filename, 'w') as sf:
with print_block('admonition', value='Numpy Version Related', params={'class': 'tip'}) as f: print_title(_name, levelc='=', file=sf)
print_doc(f""" current_module(tnp.funcs.__name__, file=sf)
This documentation is based on
`numpy.{_name} <https://numpy.org/doc/{_short_version}/reference/generated/numpy.{_name}.html>`_ print_title("Documentation", levelc='-', file=sf)
in `numpy v{_numpy_version} <https://numpy.org/doc/{_short_version}/>`_. with print_block('autofunction', value=_name, file=sf):
**Its arguments\' arrangements depend on the version of numpy you installed**. pass
If some arguments listed here are not working properly, please check your numpy's version if _origin and (_origin.__doc__ or '').strip():
with the following command and find its documentation. with print_block('admonition', value='Numpy Version Related',
params={'class': 'tip'}, file=sf) as f:
.. code-block:: shell print_doc(f"""
:linenos: This documentation is based on
`numpy.{_name} <https://numpy.org/doc/{_short_version}/reference/generated/numpy.{_name}.html>`_
python -c 'import numpy as np;print(np.__version__)' in `numpy v{_numpy_version} <https://numpy.org/doc/{_short_version}/>`_.
**Its arguments\' arrangements depend on the version of numpy you installed**.
The arguments and keyword arguments supported in numpy v{_numpy_version} is listed below.
If some arguments listed here are not working properly, please check your numpy's version
""", file=f) with the following command and find its documentation.
print()
.. code-block:: shell
print_doc(_raw_doc_process(_origin.__doc__ or '')) :linenos:
print()
python -c 'import numpy as np;print(np.__version__)'
The arguments and keyword arguments supported in numpy v{_numpy_version} is listed below.
""", file=f)
print(file=sf)
print_title(f"Description For numpy v{_short_version}", levelc='-', file=sf)
print_doc(_raw_doc_process(_origin.__doc__ or ''), file=sf)
print(file=sf)
...@@ -2,7 +2,7 @@ treetensor.numpy ...@@ -2,7 +2,7 @@ treetensor.numpy
===================== =====================
.. toctree:: .. toctree::
:maxdepth: 3 :maxdepth: 2
funcs.auto funcs.auto
numpy.auto numpy.auto
...@@ -2,7 +2,7 @@ treetensor.torch ...@@ -2,7 +2,7 @@ treetensor.torch
===================== =====================
.. toctree:: .. toctree::
:maxdepth: 3 :maxdepth: 2
funcs.auto funcs.auto
size.auto size.auto
......
import builtins import builtins
from typing import List
import numpy as np import numpy as np
from treevalue import TreeValue
from treevalue import func_treelize as original_func_treelize from treevalue import func_treelize as original_func_treelize
from treevalue.utils import post_process
from .numpy import TreeNumpy from .numpy import TreeNumpy
from ..common import ireduce, TreeObject from ..common import ireduce, TreeObject
from ..utils import replaceable_partial, doc_from from ..utils import replaceable_partial, doc_from, args_mapping
__all__ = [ __all__ = [
'all', 'any', 'all', 'any',
'equal', 'array_equal', 'equal', 'array_equal',
] ]
func_treelize = post_process(post_process(args_mapping(
def _doc_stripper(src, _, lines: List[str]): lambda i, x: TreeValue(x) if isinstance(x, (dict, TreeValue)) else x)))(
_name, _version = src.__name__, np.__version__ replaceable_partial(original_func_treelize, return_type=TreeNumpy)
_short_version = '.'.join(_version.split('.')[:2]) )
return [
f'.. note::',
f'',
f' This documentation is based on '
f' `numpy.{_name} <https://numpy.org/doc/{_short_version}/reference/generated/numpy.{_name}.html>`_ '
f' in `numpy v{_version} <https://numpy.org/doc/{_short_version}/>`_.',
f' **Its arguments\' arrangements depend on the version of numpy you installed**.',
f'',
*lines,
]
func_treelize = replaceable_partial(original_func_treelize, return_type=TreeNumpy)
@doc_from(np.all) @doc_from(np.all)
......
...@@ -27,7 +27,7 @@ __all__ = [ ...@@ -27,7 +27,7 @@ __all__ = [
] ]
func_treelize = post_process(post_process(args_mapping( func_treelize = post_process(post_process(args_mapping(
lambda i, x: Tensor(x) if isinstance(x, (dict, TreeValue)) else x)))( lambda i, x: TreeValue(x) if isinstance(x, (dict, TreeValue)) else x)))(
replaceable_partial(original_func_treelize, return_type=Tensor) replaceable_partial(original_func_treelize, return_type=Tensor)
) )
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册