Implementing Sparse Vectors With Associative Arrays/Compiler Bug?

2013-03-06 Thread Ed
I'm new to D and am trying to implement simple sparse vectors using associative arrays, but I'm getting fairly large floating point errors. Example code for sparse dot product: import std.stdio; import std.math; import std.random; static import std.datetime; int main(string[] args) { double[

Re: Implementing Sparse Vectors With Associative Arrays/Compiler Bug?

2013-03-07 Thread jerro
Are errors of this magnitude to be expected using doubles, or is this a compiler bug? Errors of this magnitude are to be expected. the value of accum in your example is somewhere around 3e+08, so the relative error is around 1e-15, and double.epsilon is 2.22045e-16. By the way, you can use u

Re: Implementing Sparse Vectors With Associative Arrays/Compiler Bug?

2013-03-07 Thread Rene Zwanenburg
On Thursday, 7 March 2013 at 09:43:21 UTC, jerro wrote: Are errors of this magnitude to be expected using doubles, or is this a compiler bug? Errors of this magnitude are to be expected. the value of accum in your example is somewhere around 3e+08, so the relative error is around 1e-15, and d

Re: Implementing Sparse Vectors With Associative Arrays/Compiler Bug?

2013-03-10 Thread Nick B
On Thursday, 7 March 2013 at 07:03:04 UTC, Ed wrote: I'm new to D and am trying to implement simple sparse vectors using associative arrays, but I'm getting fairly large floating point errors. Example code for sparse dot product: import std.stdio; import std.math; import std.random; static imp

Re: Implementing Sparse Vectors With Associative Arrays/Compiler Bug?

2013-03-10 Thread Danny Arends
You could also try to use a Kahan Accumulator to 'fix' this problem. See wikipedia: http://en.wikipedia.org/wiki/Kahan_summation_algorithm Its pretty straight forward to implement. Gr, Danny Arends http://www.dannyarends.nl