stdlib icon indicating copy to clipboard operation
stdlib copied to clipboard

meshgrid

Open certik opened this issue 6 years ago • 5 comments

Here is a 2D implementation https://github.com/certik/fortran-utils/blob/b43bd24cd421509a5bc6d3b9c3eeae8ce856ed88/src/mesh.f90#L164, but NumPy's meshgrid is much more general. Here is Matlab's meshgrid.

certik avatar Dec 19 '19 16:12 certik

Hi, I wish to start contributing to stdlib so I am looking for a first issue to tackle. Is this issue still relevant?

If yes, should we aim for the level of genericity attained by NumPy, or is the Matlab version sufficient?

igirault avatar Apr 21 '23 06:04 igirault

If we seek to have only 2d and 3d versions, we could implement them separately under a generic interface:

interface meshgrid
  module procedure meshgrid_2d
  module procedure meshgrid_3d
end interface

where the 2d implementation for instance would be a pure subroutine with the following interface

  pure subroutine meshgrid_2d(x, y, xm, ym, indexing)
    implicit none
    real, intent(in) :: x(:)
    real, intent(in) :: y(:)
    real, intent(out) :: xm(:)
    real, intent(out) :: ym(:)
    character(len=*), intent(in), optional :: indexing
  end subroutine meshgrid_2d

The optional argument indexing would have the same influence on the result than in NumPy's meshgrid.

Of course there would also the possibility to implement meshgrid_2d / meshgrid_3d as functions rather than subroutines. In this case the output could either be encapsulated in a single array, or in a derived type.

What do you think?

igirault avatar Jan 13 '24 15:01 igirault

Hi @Ivanou34 , welcome and thank you for proposing to contribute to stdlib.

This issue is still relevant, and I think it is a good one to get familiar with stdlib

If yes, should we aim for the level of genericity attained by NumPy, or is the Matlab version sufficient?

Yes, it would be nice to reach the same level of genericity as NumPy. But as a first step I would suggest to first focus on 2d and 3d. See also e.g., stdlib_stats_mean.fypp, on how genericity could be achieved with the fypp preprocessor.

Your propposed API of the subroutine in your comment sounds good to me. A wrapper (e.g. function, derived type) could be added in the future, if needed.

jvdp1 avatar Jan 13 '24 22:01 jvdp1

Thanks for your answer @jvdp1

Should I start working on it, or is it preferable to wait for feedback from other people?

igirault avatar Jan 14 '24 10:01 igirault

I guess you can start working on this and open a PR. Duscussion about API and implemtation can tehn continue on real material.

Le dim. 14 janv. 2024, 11:02, Ivanou34 @.***> a écrit :

Thanks for your answer @jvdp1 https://github.com/jvdp1

Should I start working on it, or is it preferable to wait for feedback from other people?

— Reply to this email directly, view it on GitHub https://github.com/fortran-lang/stdlib/issues/18#issuecomment-1890904890, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD5RO7GJVMEYWKQ7RFQGKGDYOOULVAVCNFSM4J5KMSWKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBZGA4TANBYHEYA . You are receiving this because you were mentioned.Message ID: @.***>

jvdp1 avatar Jan 14 '24 10:01 jvdp1