* [ruby-dev:48579] [ruby-trunk - Feature #10298] [Open] Array#float_sum (like math.fsum of Python)
[not found] <redmine.issue-10298.20140926094937@ruby-lang.org>
@ 2014-09-26 9:49 ` t_nissie
2014-10-01 5:04 ` [ruby-dev:48588] [ruby-trunk - Feature #10298] " t_nissie
` (5 subsequent siblings)
6 siblings, 0 replies; 7+ messages in thread
From: t_nissie @ 2014-09-26 9:49 UTC (permalink / raw
To: ruby-dev
Issue #10298 has been reported by Takeshi Nishimatsu.
----------------------------------------
Feature #10298: Array#float_sum (like math.fsum of Python)
https://bugs.ruby-lang.org/issues/10298
* Author: Takeshi Nishimatsu
* Status: Open
* Priority: Low
* Assignee:
* Category: math
* Target version:
----------------------------------------
Here, I propose Array#float_sum in array.c (or math.c).
Array#float_sum returns an accurate total summation of Float
elements in an array using the Kahan summation algorithm
http://en.wikipedia.org/wiki/Kahan_summation_algorithm .
This algorithm can significantly reduce the numerical
error in the total obtained by adding a sequence of
finite precision floating point numbers, compared to the
obvious approach. Python already have math.fsum
https://docs.python.org/2/library/math.html#math.fsum .
```
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1].float_sum #=> 1.0
[].float_sum #=> 0.0
Array.new( 10, 0.1).float_sum #=> 1.0
Array.new(100, 0.1).float_sum #=> 10.0
# cf.
Array.new( 10, 0.1).reduce(:+) #=> 0.9999999999999999
Array.new(100, 0.1).reduce(:+) #=> 9.99999999999998
```
The name of method can be fsum, sum_float, etc., though
I propose float_sum.
This Array#float_sum is inspired by Feature #9834 Float#{next_float,prev_float}.
---Files--------------------------------
array.float_sum.patch (1.32 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-dev:48588] [ruby-trunk - Feature #10298] Array#float_sum (like math.fsum of Python)
[not found] <redmine.issue-10298.20140926094937@ruby-lang.org>
2014-09-26 9:49 ` [ruby-dev:48579] [ruby-trunk - Feature #10298] [Open] Array#float_sum (like math.fsum of Python) t_nissie
@ 2014-10-01 5:04 ` t_nissie
2014-10-13 6:46 ` [ruby-dev:48621] " akr
` (4 subsequent siblings)
6 siblings, 0 replies; 7+ messages in thread
From: t_nissie @ 2014-10-01 5:04 UTC (permalink / raw
To: ruby-dev
Issue #10298 has been updated by Takeshi Nishimatsu.
Timing.
Of course it is fast.
```
$ uname -sprsv
Darwin 13.3.0 Darwin Kernel Version 13.3.0: Tue Jun 3 21:27:35 PDT 2014; root:xnu-2422.110.17~1/RELEASE_X86_64 i386
$ sysctl -n machdep.cpu.brand_string
Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz
$ ./miniruby --version
ruby 2.2.0dev (2014-09-29 trunk 47735) [x86_64-darwin13]
$ /usr/bin/time ./miniruby -e 'p Array.new(10000000,0.1).reduce(:+)'
999999.9998389754
0.66 real 0.62 user 0.03 sys
$ /usr/bin/time ./miniruby -e 'sum=0.0; c=0.0; Array.new(10000000,0.1).each{|x|y=x-c; t=sum+y; c=(t-sum)-y; sum=t}; p sum'
1000000.0
1.47 real 1.44 user 0.02 sys
$ /usr/bin/time ./miniruby -e 'p Array.new(10000000, 0.1).float_sum'
1000000.0
0.10 real 0.06 user 0.03 sys
```
----------------------------------------
Feature #10298: Array#float_sum (like math.fsum of Python)
https://bugs.ruby-lang.org/issues/10298#change-49149
* Author: Takeshi Nishimatsu
* Status: Open
* Priority: Low
* Assignee:
* Category: math
* Target version:
----------------------------------------
Here, I propose Array#float_sum in array.c (or math.c).
Array#float_sum returns an accurate total summation of Float
elements in an array using the Kahan summation algorithm
http://en.wikipedia.org/wiki/Kahan_summation_algorithm .
This algorithm can significantly reduce the numerical
error in the total obtained by adding a sequence of
finite precision floating point numbers, compared to the
obvious approach. Python already have math.fsum
https://docs.python.org/2/library/math.html#math.fsum .
```
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1].float_sum #=> 1.0
[].float_sum #=> 0.0
Array.new( 10, 0.1).float_sum #=> 1.0
Array.new(100, 0.1).float_sum #=> 10.0
# cf.
Array.new( 10, 0.1).reduce(:+) #=> 0.9999999999999999
Array.new(100, 0.1).reduce(:+) #=> 9.99999999999998
```
The name of method can be fsum, sum_float, etc., though
I propose float_sum.
This Array#float_sum is inspired by Feature #9834 Float#{next_float,prev_float}.
---Files--------------------------------
array.float_sum.patch (1.32 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-dev:48621] [ruby-trunk - Feature #10298] Array#float_sum (like math.fsum of Python)
[not found] <redmine.issue-10298.20140926094937@ruby-lang.org>
2014-09-26 9:49 ` [ruby-dev:48579] [ruby-trunk - Feature #10298] [Open] Array#float_sum (like math.fsum of Python) t_nissie
2014-10-01 5:04 ` [ruby-dev:48588] [ruby-trunk - Feature #10298] " t_nissie
@ 2014-10-13 6:46 ` akr
2014-10-13 6:52 ` [ruby-dev:48622] [ruby-trunk - Feature #10298] [Feedback] " akr
` (3 subsequent siblings)
6 siblings, 0 replies; 7+ messages in thread
From: akr @ 2014-10-13 6:46 UTC (permalink / raw
To: ruby-dev
Issue #10298 has been updated by Akira Tanaka.
It is not fit to Array class because Array is not only for Float.
I think it is better to implement it as an optimization of reduce(:+).
----------------------------------------
Feature #10298: Array#float_sum (like math.fsum of Python)
https://bugs.ruby-lang.org/issues/10298#change-49376
* Author: Takeshi Nishimatsu
* Status: Open
* Priority: Low
* Assignee:
* Category: math
* Target version:
----------------------------------------
Here, I propose Array#float_sum in array.c (or math.c).
Array#float_sum returns an accurate total summation of Float
elements in an array using the Kahan summation algorithm
http://en.wikipedia.org/wiki/Kahan_summation_algorithm .
This algorithm can significantly reduce the numerical
error in the total obtained by adding a sequence of
finite precision floating point numbers, compared to the
obvious approach. Python already have math.fsum
https://docs.python.org/2/library/math.html#math.fsum .
```
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1].float_sum #=> 1.0
[].float_sum #=> 0.0
Array.new( 10, 0.1).float_sum #=> 1.0
Array.new(100, 0.1).float_sum #=> 10.0
# cf.
Array.new( 10, 0.1).reduce(:+) #=> 0.9999999999999999
Array.new(100, 0.1).reduce(:+) #=> 9.99999999999998
```
The name of method can be fsum, sum_float, etc., though
I propose float_sum.
This Array#float_sum is inspired by Feature #9834 Float#{next_float,prev_float}.
---Files--------------------------------
array.float_sum.patch (1.32 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-dev:48622] [ruby-trunk - Feature #10298] [Feedback] Array#float_sum (like math.fsum of Python)
[not found] <redmine.issue-10298.20140926094937@ruby-lang.org>
` (2 preceding siblings ...)
2014-10-13 6:46 ` [ruby-dev:48621] " akr
@ 2014-10-13 6:52 ` akr
2014-10-14 2:07 ` [ruby-dev:48624] [ruby-trunk - Feature #10298] " nobu
` (2 subsequent siblings)
6 siblings, 0 replies; 7+ messages in thread
From: akr @ 2014-10-13 6:52 UTC (permalink / raw
To: ruby-dev
Issue #10298 has been updated by Akira Tanaka.
Status changed from Open to Feedback
----------------------------------------
Feature #10298: Array#float_sum (like math.fsum of Python)
https://bugs.ruby-lang.org/issues/10298#change-49377
* Author: Takeshi Nishimatsu
* Status: Feedback
* Priority: Low
* Assignee:
* Category: math
* Target version:
----------------------------------------
Here, I propose Array#float_sum in array.c (or math.c).
Array#float_sum returns an accurate total summation of Float
elements in an array using the Kahan summation algorithm
http://en.wikipedia.org/wiki/Kahan_summation_algorithm .
This algorithm can significantly reduce the numerical
error in the total obtained by adding a sequence of
finite precision floating point numbers, compared to the
obvious approach. Python already have math.fsum
https://docs.python.org/2/library/math.html#math.fsum .
```
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1].float_sum #=> 1.0
[].float_sum #=> 0.0
Array.new( 10, 0.1).float_sum #=> 1.0
Array.new(100, 0.1).float_sum #=> 10.0
# cf.
Array.new( 10, 0.1).reduce(:+) #=> 0.9999999999999999
Array.new(100, 0.1).reduce(:+) #=> 9.99999999999998
```
The name of method can be fsum, sum_float, etc., though
I propose float_sum.
This Array#float_sum is inspired by Feature #9834 Float#{next_float,prev_float}.
---Files--------------------------------
array.float_sum.patch (1.32 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-dev:48624] [ruby-trunk - Feature #10298] Array#float_sum (like math.fsum of Python)
[not found] <redmine.issue-10298.20140926094937@ruby-lang.org>
` (3 preceding siblings ...)
2014-10-13 6:52 ` [ruby-dev:48622] [ruby-trunk - Feature #10298] [Feedback] " akr
@ 2014-10-14 2:07 ` nobu
2014-10-15 11:20 ` [ruby-dev:48638] " t_nissie
2016-11-05 16:32 ` [ruby-dev:49859] [Ruby trunk Feature#10298][Rejected] " akr
6 siblings, 0 replies; 7+ messages in thread
From: nobu @ 2014-10-14 2:07 UTC (permalink / raw
To: ruby-dev
Issue #10298 has been updated by Nobuyoshi Nakada.
https://github.com/nobu/ruby/compare/Feature%2310298-float_sum
It doesn't improve the performance as `Array.float_sum`, though.
----------------------------------------
Feature #10298: Array#float_sum (like math.fsum of Python)
https://bugs.ruby-lang.org/issues/10298#change-49420
* Author: Takeshi Nishimatsu
* Status: Feedback
* Priority: Low
* Assignee:
* Category: math
* Target version:
----------------------------------------
Here, I propose Array#float_sum in array.c (or math.c).
Array#float_sum returns an accurate total summation of Float
elements in an array using the Kahan summation algorithm
http://en.wikipedia.org/wiki/Kahan_summation_algorithm .
This algorithm can significantly reduce the numerical
error in the total obtained by adding a sequence of
finite precision floating point numbers, compared to the
obvious approach. Python already have math.fsum
https://docs.python.org/2/library/math.html#math.fsum .
```
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1].float_sum #=> 1.0
[].float_sum #=> 0.0
Array.new( 10, 0.1).float_sum #=> 1.0
Array.new(100, 0.1).float_sum #=> 10.0
# cf.
Array.new( 10, 0.1).reduce(:+) #=> 0.9999999999999999
Array.new(100, 0.1).reduce(:+) #=> 9.99999999999998
```
The name of method can be fsum, sum_float, etc., though
I propose float_sum.
This Array#float_sum is inspired by Feature #9834 Float#{next_float,prev_float}.
---Files--------------------------------
array.float_sum.patch (1.32 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-dev:48638] [ruby-trunk - Feature #10298] Array#float_sum (like math.fsum of Python)
[not found] <redmine.issue-10298.20140926094937@ruby-lang.org>
` (4 preceding siblings ...)
2014-10-14 2:07 ` [ruby-dev:48624] [ruby-trunk - Feature #10298] " nobu
@ 2014-10-15 11:20 ` t_nissie
2016-11-05 16:32 ` [ruby-dev:49859] [Ruby trunk Feature#10298][Rejected] " akr
6 siblings, 0 replies; 7+ messages in thread
From: t_nissie @ 2014-10-15 11:20 UTC (permalink / raw
To: ruby-dev
Issue #10298 has been updated by Takeshi Nishimatsu.
Thank you for the quick patch for enum.c.
Timing and test.
I see. performance is not improved.
```
$ uname -sprsv
Darwin 13.3.0 Darwin Kernel Version 13.3.0: Tue Jun 3 21:27:35 PDT 2014; root:xnu-2422.110.17~1/RELEASE_X86_64 i386
$ sysctl -n machdep.cpu.brand_string
Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz
$ ./miniruby --version
ruby 2.2.0dev (2014-10-15 trunk 47735) [x86_64-darwin13]
$ /usr/bin/time ./miniruby -e 'p Array.new(10000000,0.1).reduce(:+)'
999999.9998389754
0.69 real 0.65 user 0.03 sys
$ mv optimized/enum.c .
$ make -j2 miniruby
compiling enum.c
linking miniruby
$ /usr/bin/time ./miniruby -e 'p Array.new(10000000,0.1).reduce(:+)'
1000000.0
0.55 real 0.51 user 0.04 sys
$ ./miniruby -e 'p Array.new(10000000,0.1).unshift(0.0).reduce(:-)'
-1000000.0
```
I understand that Array is not only for Float.
```
$ ./miniruby -e '[1,2,3].float_sum'
-e:1: [BUG] Segmentation fault at 0x00000000000013
```
----------------------------------------
Feature #10298: Array#float_sum (like math.fsum of Python)
https://bugs.ruby-lang.org/issues/10298#change-49459
* Author: Takeshi Nishimatsu
* Status: Feedback
* Priority: Low
* Assignee:
* Category: math
* Target version:
----------------------------------------
Here, I propose Array#float_sum in array.c (or math.c).
Array#float_sum returns an accurate total summation of Float
elements in an array using the Kahan summation algorithm
http://en.wikipedia.org/wiki/Kahan_summation_algorithm .
This algorithm can significantly reduce the numerical
error in the total obtained by adding a sequence of
finite precision floating point numbers, compared to the
obvious approach. Python already have math.fsum
https://docs.python.org/2/library/math.html#math.fsum .
```
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1].float_sum #=> 1.0
[].float_sum #=> 0.0
Array.new( 10, 0.1).float_sum #=> 1.0
Array.new(100, 0.1).float_sum #=> 10.0
# cf.
Array.new( 10, 0.1).reduce(:+) #=> 0.9999999999999999
Array.new(100, 0.1).reduce(:+) #=> 9.99999999999998
```
The name of method can be fsum, sum_float, etc., though
I propose float_sum.
This Array#float_sum is inspired by Feature #9834 Float#{next_float,prev_float}.
---Files--------------------------------
array.float_sum.patch (1.32 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-dev:49859] [Ruby trunk Feature#10298][Rejected] Array#float_sum (like math.fsum of Python)
[not found] <redmine.issue-10298.20140926094937@ruby-lang.org>
` (5 preceding siblings ...)
2014-10-15 11:20 ` [ruby-dev:48638] " t_nissie
@ 2016-11-05 16:32 ` akr
6 siblings, 0 replies; 7+ messages in thread
From: akr @ 2016-11-05 16:32 UTC (permalink / raw
To: ruby-dev
Issue #10298 has been updated by Akira Tanaka.
Status changed from Feedback to Rejected
Ruby 2.4 implements Array#sum and Enumerable#sum.
----------------------------------------
Feature #10298: Array#float_sum (like math.fsum of Python)
https://bugs.ruby-lang.org/issues/10298#change-61337
* Author: Takeshi Nishimatsu
* Status: Rejected
* Priority: Normal
* Assignee:
----------------------------------------
Here, I propose Array#float_sum in array.c (or math.c).
Array#float_sum returns an accurate total summation of Float
elements in an array using the Kahan summation algorithm
http://en.wikipedia.org/wiki/Kahan_summation_algorithm .
This algorithm can significantly reduce the numerical
error in the total obtained by adding a sequence of
finite precision floating point numbers, compared to the
obvious approach. Python already have math.fsum
https://docs.python.org/2/library/math.html#math.fsum .
```
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1].float_sum #=> 1.0
[].float_sum #=> 0.0
Array.new( 10, 0.1).float_sum #=> 1.0
Array.new(100, 0.1).float_sum #=> 10.0
# cf.
Array.new( 10, 0.1).reduce(:+) #=> 0.9999999999999999
Array.new(100, 0.1).reduce(:+) #=> 9.99999999999998
```
The name of method can be fsum, sum_float, etc., though
I propose float_sum.
This Array#float_sum is inspired by Feature #9834 Float#{next_float,prev_float}.
---Files--------------------------------
array.float_sum.patch (1.32 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-11-05 16:01 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <redmine.issue-10298.20140926094937@ruby-lang.org>
2014-09-26 9:49 ` [ruby-dev:48579] [ruby-trunk - Feature #10298] [Open] Array#float_sum (like math.fsum of Python) t_nissie
2014-10-01 5:04 ` [ruby-dev:48588] [ruby-trunk - Feature #10298] " t_nissie
2014-10-13 6:46 ` [ruby-dev:48621] " akr
2014-10-13 6:52 ` [ruby-dev:48622] [ruby-trunk - Feature #10298] [Feedback] " akr
2014-10-14 2:07 ` [ruby-dev:48624] [ruby-trunk - Feature #10298] " nobu
2014-10-15 11:20 ` [ruby-dev:48638] " t_nissie
2016-11-05 16:32 ` [ruby-dev:49859] [Ruby trunk Feature#10298][Rejected] " akr
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).