Skip to content

MAINT: remove Fortran like handling of constants#132

Open
dschmitz89 wants to merge 7 commits into
scipy:mainfrom
dschmitz89:refactor_amos_1
Open

MAINT: remove Fortran like handling of constants#132
dschmitz89 wants to merge 7 commits into
scipy:mainfrom
dschmitz89:refactor_amos_1

Conversation

@dschmitz89

Copy link
Copy Markdown
Contributor

This is a first step to make AMOS speak a little less FORTRAN.

dschmitz89 and others added 3 commits April 23, 2026 22:12
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
@dschmitz89 dschmitz89 changed the title MAINT: remove Fortran like arrays of machine constants in amos MAINT: remove Fortran like handling of constants Apr 25, 2026
Co-authored-by: Copilot <copilot@github.com>
@fbourgey fbourgey added the Enhancement New feature or request label Apr 27, 2026
Comment thread include/xsf/amos/amos.h
Comment thread include/xsf/amos/amos.h
// TOL WHERE B IS THE BASE OF THE ARITHMETIC.
//
t1 = (i1mach[13] - 1) * d1mach[4] * (std::log(10) / std::log(2));
t1 = (std::numeric_limits<double>::digits - 1) * LOG10_2 * (std::log(10) / std::log(2));

@fbourgey fbourgey Apr 27, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we rewrite this as

Suggested change
t1 = (std::numeric_limits<double>::digits - 1) * LOG10_2 * (std::log(10) / std::log(2));
t1 = std::numeric_limits<double>::digits - 1;

Comment thread include/xsf/amos/amos.h
Comment thread include/xsf/amos/amos.h Outdated
Comment thread include/xsf/amos/amos.h Outdated
Comment thread include/xsf/amos/amos.h Outdated
Comment thread include/xsf/amos/amos.h Outdated
dschmitz89 and others added 2 commits May 6, 2026 20:48
Co-authored-by: Florian Bourgey <bourgeyflorian@gmail.com>
@dschmitz89

Copy link
Copy Markdown
Contributor Author

@JaRoSchm Since you are familiar with AMOS, could you have a final look here? My long term plan was to make this more maintainable by using modern idioms and removing gotos which are planned for follow ups.

@JaRoSchm JaRoSchm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In general, looks like a nice improvement!

Comment thread include/xsf/amos/amos.h
std::complex<double> zeta2[2] = {0.0};
std::complex<double> cy[2] = {0.0};
double bry[3] = {1e3 * d1mach[0] / tol, tol / 1e3 * d1mach[0], d1mach[1]};
double bry[3] = {THRESHOLD_MIN / tol, tol / THRESHOLD_MIN, std::numeric_limits<double>::max()};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment thread include/xsf/amos/amos.h Outdated
@JaRoSchm

Copy link
Copy Markdown
Contributor

My long term plan was to make this more maintainable by using modern idioms and removing gotos which are planned for follow ups.

There's definitely potential for that in amos! In my opinion, it might be worth however to first try to fix #137 (fixing long known bugs/accuracy improvements in the Fortran implementation by the original author, which were not included in scipy before the translation) as this probably becomes harder if the versions diverge even more (and they already have quite a bit). In principle, I plan to look into this myself, but I can't say exactly when I'll get round to it yet.

@dschmitz89

dschmitz89 commented May 16, 2026

Copy link
Copy Markdown
Contributor Author

@JaRoSchm Thanks. Feel free to ping me when you feel like this should be merged. You have by far the best overview of everything amos related here and we should follow the PR order you propose. I will wait with resolving the merge conflicts until then.

@JaRoSchm

Copy link
Copy Markdown
Contributor

@dschmitz89 I see no reason for preferring any specific order of merging the open amos-related PRs (only #92 should be merged before I can add a test to #93). My previous comment is addressed by #149.

@JaRoSchm JaRoSchm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

By chance, I stumbled across two more translation errors.

Comment thread include/xsf/amos/amos.h Outdated
Comment thread include/xsf/amos/amos.h Outdated
@dschmitz89

Copy link
Copy Markdown
Contributor Author

@JaRoSchm Would you be willing to make a PR against my branch? I am starting to lose track of all the AMOS changes and this code is very hard to digest mentally. If not, we could still apply this change and proceed in a followup.

@JaRoSchm

Copy link
Copy Markdown
Contributor

@dschmitz89 I think you could simply accept @fbourgey's and my suggestions here (should be possible through the GitHub UI?). Then, this is ready to merge from my pov and #132 (comment) could be left for a followup.

Co-authored-by: JaRoSchm <jaro.schmidt@gmail.com>
Comment thread include/xsf/amos/amos.h
//
az = std::abs(z);
bb = d1mach[1] * 0.5;
bb = std::numeric_limits<int>::max() * 0.5;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

From https://github.com/scipy/xsf/blob/main/include/xsf/amos/amos.h#L141, should this be?

Suggested change
bb = std::numeric_limits<int>::max() * 0.5;
bb = std::numeric_limits<double>::max() * 0.5;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This fixes a translation bug, see #132 (review).

Comment thread include/xsf/amos/amos.h

aa = 0.5 / tol;
bb = d1mach[1] * 0.5;
bb = std::numeric_limits<int>::max() * 0.5;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here

Suggested change
bb = std::numeric_limits<int>::max() * 0.5;
bb = std::numeric_limits<double>::max() * 0.5;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This fixes a translation bug, see #132 (review).

@fbourgey

Copy link
Copy Markdown
Member

@dschmitz89 can you please resolve the conflict? I can then take a fresh look, and get that one in if OK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants