Add findLocalMin#3559
Conversation
|
Is this implementation based on R's source code? If so, it probably cannot be included in Phobos, as R is licensed under GPL. |
|
@kyllingstad R's implementation is translation from Brent's book (source code is in book!). I have checked each line and rewrite algorithm from scratch. Both R and book's algorithms look identical and have the same bug (infinity loop), that was fixed in this PR. |
|
... "look identical" includes cycle structures and variable names. |
|
This is cute) I think we had at least one Brent's algorithm in std.numeric ? |
|
Ok, then this should be fine. I just had to make sure. (D has had its share of licence issues in the past, and we don't want to get into that mess again.) |
std/numeric.d
Outdated
There was a problem hiding this comment.
I think assert messages should describe the error, not the expected state. E.g., this could be:
assert(isFinite(ax) && isFinite(bx), "ax and/or bx are not finite");
But this is a matter of taste, I guess. I don't know what is the Phobos convention (if there is any) here. Also, this should be two asserts, so the user immediately knows which argument is bad.
|
Two general comments:
|
done |
std/numeric.d
Outdated
There was a problem hiding this comment.
My comment about assert messages holds for the other two as well.
|
Well, I don't have any further comments. I guess some of the more active Phobos devs should comment on any remaining style issues, and whether this functionality is general enough to warrant inclusion in Phobos. (I certainly think it is!) |
|
Thanks!
|
|
Fails because magic in 32 bit release mode: writeln("ttt ", [i, a, b, m, (a + b) / 2, (a + b) / 2.0, ], a <= m, m <= b);produce: ttt [8, -5.50533e+307, 4.49423e+307, -8.08875e+307, -8.08875e+307, -8.08875e+307]truetrueO_O So, |
There was a problem hiding this comment.
Hmm.
static assert(approxEqual((2*c - 3)^^2, 5.0);
? Probably total overkill, but I get nervous with these hexadecimal float constants obtained from external sources that basically have to be taken on faith.
|
Also, please squash commits, or at least put readable commit messages for them. :-) |
Please read my last comment about 32 bit release mode bug. I have no idea what I can do with this. |
|
Oops, wrong button.
File bug report, it looks like codegen bug. Have you tried LDC/GDC? |
|
I will try with LDC and file it. |
|
OSX works fine both with LDC and DMD. But FreeBSD/Linux fails with DMD. ISSUE https://issues.dlang.org/show_bug.cgi?id=15204 |
|
FreeBSD32 passed recently |
|
Cleaned and rebased |
|
As this is a name addition so CC @andralex |
std/numeric.d
Outdated
|
|
||
| /++ | ||
| Find a real minimum of a real function $(D f(x)) via bracketing. | ||
| Given a function $(D f) and a range $(D (ax..bx)), |
There was a problem hiding this comment.
The range notation does not exist in D or in math. Gotta choose one :o).
There was a problem hiding this comment.
I just follow findRoot naming: Given a function f and a range [a..b] ...
|
I approve the name addition, please mind the nits before pulling. Thx! |
| License: $(WEB www.boost.org/LICENSE_1_0.txt, Boost License 1.0). | ||
| Authors: $(WEB erdani.org, Andrei Alexandrescu), | ||
| Don Clugston, Robert Jacques | ||
| Don Clugston, Robert Jacques, Ilya Yaroshenko |
|
I didn't squash commit because the last contains style fixes for all |
|
Auto-merge toggled on |
|
just removed the link to wikipedia, because this refers to root-finding algorithm instead of optimization algorithm |
You are lucky that @braddr hasn't forbidden/fixed this yet braddr/d-tester#49 ;-) |
It is fixed version of R's
optimise.f
Blocked by https://issues.dlang.org/show_bug.cgi?id=15204