Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: How to partition domains #22375

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

melissawm
Copy link
Member

@melissawm melissawm commented Oct 3, 2022

Adds a how-to guide on partitioning domains with NumPy. Covers usage of

  • linspace
  • arange
  • geomspace
  • logspace
  • meshgrid
  • mgrid
  • ogrid

The main goal of this document is to avoid issues around usage of linspace and arange, but also to elaborate on the usage of all cited functions/tools. This is a first stab at a guide, feedback is appreciated!

Possibly, fixes #9616, #18625, #19670, #17339

Related issues: #18099, #13349, #12715, #2457, #630, #7009

@melissawm melissawm added the 35 - How-To candidate Documentation issues/questions that are candidates to be answered by a how-to guide label Oct 3, 2022
@melissawm melissawm marked this pull request as draft Oct 3, 2022
@melissawm melissawm marked this pull request as ready for review Oct 4, 2022
complex numbers.

* Use `numpy.linspace` if you want the endpoint to be included in the result, or
if you are using a non-integer step size.
Copy link
Member

@mattip mattip Oct 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit of "why" is missing, maybe something like

Suggested change
if you are using a non-integer step size.
if you are using a non-integer step size since floating-point inaccuracies
can make ``arange`` results with floating-point numbers confusing.

Copy link
Member

@mattip mattip Oct 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, you have this below. Maybe a "(see below)" instead?

@mattip
Copy link
Member

mattip commented Oct 4, 2022

Looks great, thanks. Perhaps a reference to the howto could be added to the SeeAlso sections of the relevant functions?

Copy link
Member

@seberg seberg left a comment

Nice! I added a few thoughts, but just possible ideas. I will assume @rossbar will have a closer look to see this through :).

array([0, 2, 4, 6, 8])

The arguments ``start`` and ``stop`` should be integer or real, but not
complex numbers.
Copy link
Member

@seberg seberg Oct 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should mention the builtin range? real also means floats, but we want to somewhat discourage that, so I wonder if we can rephrase the sentence to do that.

.. _how-to-partition:

=====================================
How to partition a domain using NumPy
Copy link
Member

@seberg seberg Oct 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a less mathy wording for the title is better? Something in the direction of generate regular spaced numbers using NumPy?


>>> np.linspace(1+1.j, 4, 5, dtype=np.complex64)
array([1. +1.j , 1.75+0.75j, 2.5 +0.5j , 3.25+0.25j, 4. +0.j ],
dtype=complex64)
Copy link
Member

@seberg seberg Oct 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect linspace is probably commonly confusing due to problem of requiring num=n+1 compared to the division step with endpoint=True ("fencepost error"), just a thought that mentioning that might help (not sure).

`mgrid` and `ogrid`, approximately defined as::

mgrid = nd_grid(sparse=False)
ogrid = nd_grid(sparse=True)
Copy link
Member

@seberg seberg Oct 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not mention nd_grid at all? It seems more of an implementation detail to me.

Copy link
Member Author

@melissawm melissawm Oct 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was conflicted here. Will remove

``ogrid``
---------

Similar to ``numpy.mgrid``, ``numpy.ogrid`` returns a ``nd_grid`` instance, but
Copy link
Member

@seberg seberg Oct 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is such an instance, but lets ignore that fact?


Similar to ``numpy.mgrid``, ``numpy.ogrid`` returns a ``nd_grid`` instance, but
the result is an *open* multidimensional meshgrid. This means that when it is
indexed, so that only one dimension of each returned array is greater than 1.
Copy link
Member

@seberg seberg Oct 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the "so that" to much? Might be good to add length of only one dimension (the "length") to clarify that it is not ndim. Could also add a sentence saying that this avoids repeating the data and thus saves memory (just another way to say the same thing) – which is often desirable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
04 - Documentation 35 - How-To candidate Documentation issues/questions that are candidates to be answered by a how-to guide
Projects
None yet
Development

Successfully merging this pull request may close these issues.

arange recomputation of step variable may lead to problems with floating point
3 participants