Skip to content

Commit

Permalink
Add documentation for lena.math.refine_mesh and lena.math.flatten.
Browse files Browse the repository at this point in the history
  • Loading branch information
ynikitenko committed Apr 21, 2020
1 parent d16bbe9 commit 83ea2e8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions docs/source/math.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ math package

.. currentmodule:: lena.math.meshes
.. autosummary::
flatten
mesh
md_map
refine_mesh

**Functions of scalar and multidimensional arguments:**

Expand All @@ -31,8 +33,10 @@ Functions of multidimensional arguments
---------------------------------------

.. module:: lena.math.meshes
.. autofunction:: flatten
.. autofunction:: mesh
.. autofunction:: md_map
.. autofunction:: refine_mesh

Functions of scalar and multidimensional arguments
--------------------------------------------------
Expand Down
11 changes: 7 additions & 4 deletions lena/math/meshes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
def flatten(array):
"""Flatten an *array* of arbitrary dimension.
Array must be list or a tuple (can be nested).
*array* must be list or a tuple (can be nested).
Depth-first flattening is used.
Return an iterator over the flattened array.
Expand Down Expand Up @@ -140,12 +140,15 @@ def mesh_1d(nbins, range_):


def refine_mesh(arr, refinement):
"""Refine (subdivide) a mesh *arr*.
"""Refine (subdivide) one-dimensional mesh *arr*.
*refinement* is the number of subdivisions, it must be not less than 1.
*refinement* is the number of subdivisions.
It must be not less than 1.
*arr* must be one-dimensional now.
Note that to create a new mesh may be faster.
Use this function only for convenience.
"""
# *arr* must be one-dimensional.
new_mesh = [arr[0]]
for low, up in zip(arr, arr[1:]):
new_mesh.extend(mesh((low, up), refinement)[1:])
Expand Down

0 comments on commit 83ea2e8

Please sign in to comment.