Skip to content
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

Precise fsum #2513

Closed
wants to merge 49 commits into from
Closed

Precise fsum #2513

wants to merge 49 commits into from

Conversation

9il
Copy link
Member

@9il 9il commented Sep 14, 2014

Blocked

Issues [DMD]

  1. [ICE] https://issues.dlang.org/show_bug.cgi?id=14158 (workaround)
  2. https://issues.dlang.org/show_bug.cgi?id=13485 (fixed)
  3. https://issues.dlang.org/show_bug.cgi?id=13474 (workaround)

Note issue 13469 while testing:
https://issues.dlang.org/show_bug.cgi?id=13469 (workaround)

Example 0:

import std.numeric.summation;
import std.math, std.algorithm, std.range;
auto r1 = iota(  1, 501 ).map!(a => (-1.0)^^a/a);
auto r2 = iota(501, 1001).map!(a => (-1.0)^^a/a);
Summator!double s1 = 0, s2 = 0;
foreach(e; r1) s1.put(e); 
foreach(e; r2) s2 -= e;  //put(-e)
s1 -= s2;
assert(s1.sum == -0.69264743055982025);

Example 1:

import std.algorithm : map;
import std.numeric : fsum;
auto ar = [1, 1e100, 1, -1e100].map!(a => a*10000);
double r = 20000;
assert(r != ar.fsum!(Summation.Naive));
assert(r != ar.fsum!(Summation.Pairwise));
assert(r != ar.fsum!(Summation.Kahan));
assert(r == ar.fsum!(Summation.KBN)); //Fails with dmd -O -m32: DMD Optimizer BUG.   :(
assert(r == ar.fsum!(Summation.KB2));
assert(r == ar.fsum);  //Summation.Precise

Example 2:

//Summation.Precise is default

// Works like Python's fsum, 
// but  current implementation re-establish special
// value semantics across iterations (i.e. handling -Inf + Inf).

import std.numeric : fsum;
import std.math, std.algorithm, std.range;
auto ar = iota(1000).map!(a => 1.7.pow(a+1) - 1.7.pow(a)).chain([-(1.7.pow(1000))]);
assert(ar.fsum  ==  -1.0);
assert(ar.fsum!real  ==  -1.0);

@9il 9il changed the title (do not merger) Precise , KB2, KBN and other fsum algo (not ready) Precise , KB2, KBN and other fsum algo Sep 14, 2014
@9il 9il changed the title (not ready) Precise , KB2, KBN and other fsum algo (blocked) Precise , KB2, KBN and other fsum algo Sep 14, 2014
@9il 9il changed the title (blocked) Precise , KB2, KBN and other fsum algo (blocked) Precise fsum Sep 14, 2014
@9il 9il changed the title (blocked) Precise fsum Precise fsum Sep 14, 2014
std.internal.math.summation: tabs

std.algorithm: sum (Kahan and Pairswise) update

*.mak update

std.interanl.math.summation update

std.numeric: added fsum

std.interanl.math.summation update

std.interanl.math.summation update

std.interanl.math.summation update

std.interanl.math.summation add local fabs

std.interanl.math.summation

Docs update

minor update

tabs

minor ddoc update

minor ddoc update

remove reverse summation

Full redesign

std.internal.math.summation: privacy changes

std.internal.math.summation: privacy changes

fabs update

opertor overlaoding for Summator

opertor overlaoding for Summator update

opertor overlaoding unittest added

update Summator

remove blank lines

update Summator unittests

add unittest for Complex

std.internal.scopebuffer: added inout for slices

update unittest

removed no-op cast

add opAssign and const for operators

remove reset (use = 0)

added extendTo template

update fsum for Complex

remove static if for __ctfe

fsum update

minor

add CTFEable param

added = void

minor update

update location of Summator

_

update summation.d
@quickfur
Copy link
Member

quickfur commented Oct 6, 2014

ping

@9il 9il mentioned this pull request Oct 27, 2014
@andralex
Copy link
Member

May I convince some of the dmd core team to take a look at https://issues.dlang.org/show_bug.cgi?id=13485, https://issues.dlang.org/show_bug.cgi?id=13474, and https://issues.dlang.org/show_bug.cgi?id=13469

Perhaps aim the fixes for 2.067?

cc @WalterBright @donc @9rnsr @yebblies

@yebblies
Copy link
Member

I can probably have a look at the optimizer bugs when I'm done with va_copy. Do we have any sort of timeline on 2.067?

@andralex
Copy link
Member

Let's aim for Sunday March 1st, which means we need to have a prerelease by Sun Feb 15.

@yebblies
Copy link
Member

yebblies commented Feb 8, 2015

This needs rebasing.

@9il
Copy link
Member Author

9il commented Feb 8, 2015

Whoohooo! I am starting to rewrite this code now! Thanks!

@9il
Copy link
Member Author

9il commented Feb 14, 2015

Issue 13485 fixed (Thanks to @yebblies).
Issue 13474 still blocks this PR.

@yebblies
Copy link
Member

Would doing all the internal calculations explicitly with real on x86 work around the failures?

@9il
Copy link
Member Author

9il commented Feb 16, 2015

Yes, for real it works well.
I will try to create internal representation with real for x86.

@9il
Copy link
Member Author

9il commented Feb 16, 2015

There are will be some minimal precision loss for float and double versions of fsum on x87:
nextDown(s) <= r && nextUp(s) >= r
instead of s == r. I think it is acceptable.

@9il
Copy link
Member Author

9il commented Feb 16, 2015

Reopened in #2991.

@9il 9il closed this Feb 16, 2015
@9il 9il deleted the sum branch April 29, 2015 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants