-
Notifications
You must be signed in to change notification settings - Fork 54
Add : Python Fortran Rosetta Stone (Transfer content from fortran90.org #112) #175
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
Conversation
#build_preview |
This PR has been built with Sphinx and can be previewed at: https://fortran-lang.github.io/webpage/pr/175 |
@awvwgk Should we add Rosetta stone to minibook tutorials ? |
The "Mini-book Tutorials > Getting started" section seems the right place. Concerning the tables, is it possible to improve the vertical alignments of the Python / Fortran tables? For example by simply adding void lines to have the same number of lines in the two languages? Do you think syntax coloring could be added? Finally, we will have to modernize the code. At first sight, the main problem seems to be that is Python 2. We will have to replace I have also detected that in some tables the Python (compulsory) indentations are lacking, for example: i = 5
def f(x):
return x + 5 |
The "Timings on Acer 1830T with gfortran 4.6.1" will also need updating... |
I have used a couple of two column code listings in https://awvwgk.github.io/foopss/, note that those were carefully constructed to always have the same number of lines to make it look better. Either sphinx-design grids or tabs are used there, but they are certainly not optimal, just an example. Edit: Maybe it would be a good idea to just transfer the above page to the learn section, open for discussion in #177. |
Sure sir , will add it there.
I had noticed them but it is due to pandoc. so they must be resolved manually.
Maybe we could add that The above Python code is Python 2 and similarly for Fortran. Thanks and Regards, |
#build_preview |
This PR has been built with Sphinx and can be previewed at: https://fortran-lang.github.io/webpage/pr/175 |
Since Python 2 is end-of-life we should rather modernize to Python 3 instead. |
The Fortran snippets can be quickly tested in the Fortran Playground https://play.fortran-lang.org/
It is also missing on the Python side. |
source/learn/rosetta_stone.md
Outdated
</tbody> | ||
</table> | ||
|
||
In Python, just save the code to a file `a.py` and execute using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a.py
and a.f90
are bad choices for the name here. Especially for newcomers it might not be immediately clear that a.out
is not obtained by using the basename of the Fortran source file. Rather we should call them example.py
or test.f90
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure Sir, actually I had been re-writing the entire document in myst , so will also add this. Thanks.
source/learn/rosetta_stone.md
Outdated
> - Fortran counts (by default) from 1, NumPy always from 0 | ||
> - Fortran array sections (slices) include both ends, in NumPy the | ||
> initial point is included, the final is excluded | ||
> - In C the array is stored row wise in the memory (by default NumPy | ||
> uses C storage), while in Fortran it is stored column wise (this | ||
> only matters in the next two points) | ||
> - By default `reshape` uses Fortran ordering in Fortran, and C | ||
> ordering in NumPy (in both cases an optional argument `order` | ||
> allows to use the other ordering). This also matters when | ||
> `reshape` is used implicitly in other operations like flattening. | ||
> - The first index is the fastest in Fortran, while in NumPy, the | ||
> last index is the fastest | ||
> - By default NumPy prints the 2d array nicely, while in Fortran one | ||
> has to specify a format to print it (also Fortran prints column | ||
> wise, so one has to transpose the array for row wise printing) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should that be a block quote or should we rather aim for an admonition.
source/learn/rosetta_stone.md
Outdated
module constants | ||
use types, only: dp | ||
implicit none | ||
private | ||
public pi, e, I | ||
! Constants contain more digits than double precision, so that | ||
! they are rounded correctly: | ||
real(dp), parameter :: pi = 3.1415926535897932384626433832795_dp | ||
real(dp), parameter :: e = 2.7182818284590452353602874713527_dp | ||
complex(dp), parameter :: I = (0, 1) | ||
end module |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will not get highlighted correctly
source/learn/rosetta_stone.md
Outdated
<table> | ||
<colgroup> | ||
<col style="width: 49%" /> | ||
<col style="width: 50%" /> | ||
</colgroup> | ||
<tbody> | ||
<tr class="odd"> | ||
<td>NumPy</td> | ||
<td><blockquote> | ||
<p>Fortran</p> | ||
</blockquote></td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's rather cumbersome to edit, can we find a pure MyST equivalent? Maybe something like
:::::{grid}
::::{grid-item}
```{code-block} python
:caption: Python
# ...
```
::::
::::{grid-item}
```{code-block} fortran
:caption: Fortran
! ...
```
::::
:::::
I have to admit that MyST seems to be only a minor improvement over raw HTML in this context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure sir. Thanks
What's the status here --- I see some force pushes into P.S. We should never be force pushing into main, we should even forbid it in GitHub itself. |
We will be opening a new pr soon. |
Actually due to a rebase this has been closed . Will open a new one |
Ok, thanks. Once you do, please post a link here. |
#delete_preview |
The preview build for this PR has now been deleted. |
This PR adds Fortran90 content Python Fortran Rosetta Stone, We are grateful to the original owners (@certik) of the content for opensourcing it . This content has been taken from https://github.com/certik/fortran90.org . This content has been formatted with pandoc and converted to myst markdown for consistency.
This PR Resolves:
Closes #112
Thanks and Regards,
Henil
CC @awvwgk @vmagnin