News for hackers. Stuff that matters.
Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by mattbillenstein on Wednesday November 08, 2023 @05:50PM (#38198378)
Very naive question, but are the semantics of Fortran so different that it can't be translated to C first and then compiled using a C compiler? Perhaps maintained in C going forward?

I can't imagine there are a lot of Fortran folks around maintaining these old libraries - they must need maintenance no?

Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by not2b on Wednesday November 08, 2023 @06:01PM (#38198496)
If you want the code to run slower, yes, you could do that. Because there are no pointers in Fortran, only arrays, and because arguments to functions aren't allowed to alias (let's ignore the horror of COMMON blocks for now), aggressive optimization and vectorization is easier.

The standard Fortran math libraries just work, and they are fast.

I should clarify that you can write C/C++ code that would have equivalent speed, especially with the C restrict keyword, but putting in an f2c step to translate the existing code will making things significantly worse in many cases.

Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by Sohcahtoa82 on Wednesday November 08, 2023 @06:16PM (#38198643)
> Because there are no pointers in Fortran, only arrays, and because arguments to functions aren't allowed to alias [...], aggressive optimization and vectorization is easier.

Can you explain this like I'm 12?

What's an example of an aggressive optimization you can make based on arguments not being aliased and there being no pointers?

Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by superlopuh on Wednesday November 08, 2023 @06:40PM (#38198868)
Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by Falell on Wednesday November 08, 2023 @06:28PM (#38198760)
Not a direct compiler optimization, but consider memcpy() vs memmove() as an example. If you know two regions of memory do not overlap you can call memcpy() for a direct optimized copy, but if they overlap you must call memmove() and introduce an intermediate copy.
Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by Sohcahtoa82 on Wednesday November 08, 2023 @07:20PM (#38199228)
It makes sense, but when would you ever memcpy with overlap? I would think any situation that lets that happen is from a bug, like you have an incorrect buffer length or an incorrect destination address.
Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by murderfs on Wednesday November 08, 2023 @07:47PM (#38199413)
Inserting an element in an array is something along the lines of memmove(arr + idx + 1, arr + idx, (length - idx) * sizeof(*arr)); arr[idx] = foo;
Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by johncolanduoni on Thursday November 09, 2023 @07:13AM (#38204013)
memmove does not (in any implementation I’ve ever heard of) introduce an intermediate copy, it just performs the copy loop in the reverse direction to handle the overlap (and can’t always vectorize in the same way memcpy can).
Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by hurryer on Wednesday November 08, 2023 @06:49PM (#38198936)

  int *x;
  int *y;
  // ...
  *x = 5;
Because of aliasing, x and y might point to the same memory location, so the compiler must assume that when you modified x to 5, y also potentially got modifed, so at next access it will read y again from memory and discard any cached value in a register it might have.

The compiler will try proving that no such aliasing is present, by tracking your pointer usage, but it's not always possible, in those cases it will assume the worse and re-read values from memory.

Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by Sohcahtoa82 on Wednesday November 08, 2023 @07:18PM (#38199208)
Ah that makes sense. Thank you!
Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by wycy on Wednesday November 08, 2023 @09:38PM (#38200393)
I finally understand—-thanks for this example.
Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by dwheeler on Wednesday November 08, 2023 @06:49PM (#38198934)
Also, in Fortran arrays are normally stored in column-major order (sometimes called “Fortran order”). C uses row order. A simplistic translation would have terrible performance.
Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by pklausler on Wednesday November 08, 2023 @07:00PM (#38199042)
Fortran has had pointers in the standard language since F'90 and as a ubiquitous vendor extension since ca. 15 years earlier.
Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by Affric on Thursday November 09, 2023 @05:02AM (#38203070)
Are the often used in the big linear algebra libraries?
Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by not2b on Thursday November 09, 2023 @02:22PM (#38209633)
No. The math libraries are written in Fortran 77 for the most part, which did not have pointers. I should have been more precise about that.
Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by Affric on Saturday November 11, 2023 @06:45AM (#38229465)
Thanks for clarifying, I was intrigued by your comment and it seemed you’d know.
Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by lldb on Wednesday November 08, 2023 @05:55PM (#38198438)
We have this already - “f2c” has been around for decades.
Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by ogrisel on Thursday November 09, 2023 @12:08PM (#38207685)
It's currently used to provide a hackish WASM compatible port of scipy for Pyodide and the Pyodide maintainers are eager to be able to drop the f2c hacks in favor of lfortran or any WASM-capable fotran compiler because f2c can cause very hard to debug low level crashes when running scipy or other downstream libraries tests (e.g. scikit-learn).
Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by mkoubaa on Wednesday November 08, 2023 @05:55PM (#38198439)
Fortran is a higher level language than C. There are plenty of fortran developers.

It's awful for application development, but that isn't it's niche

Re:Why SciPy builds for Python 3.12 on Windows are a minor m... by googl-free on Wednesday November 08, 2023 @05:51PM (#38198396)
yeah, fortran has native arrays