Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Patches to 1.8.0p4 to add Bessel functions for those that have 'em

Reply
Thread Tools

Patches to 1.8.0p4 to add Bessel functions for those that have 'em

 
 
Mike Hall
Guest
Posts: n/a
 
      07-25-2003
Here's some simple patches to configure.in, configure and math.c
to add the Bessel functions on those systems that have them
in their math library. They were made against 1.8.0 preview 4.

It's probably better to have one #define for all the Bessels,
and avoid the pollution of all the little #define's.

$ diff -p configure.in configure.in.orig
*** configure.in Fri Jul 25 01:03:32 2003
--- configure.in.orig Thu Jul 24 02:37:56 2003
*************** AC_CHECK_FUNCS(fmod killpg wait4 waitpid
*** 373,380 ****
setrgid setegid setregid setresgid issetugid pause lchown lchmod\
getpgrp setpgrp getpgid setpgid initgroups getgroups setgroups\
getpriority getrlimit dlopen sigprocmask sigaction _setjmp\
! setsid telldir seekdir fchmod mktime timegm cosh sinh tanh \
! j0 j1 y0 y1 jn yn)
AC_ARG_ENABLE(setreuid,
[ --enable-setreuid use setreuid()/setregid() according to need ev
en if obsolete.],
[use_setreuid=$enableval])
--- 373,379 ----
setrgid setegid setregid setresgid issetugid pause lchown lchmod\
getpgrp setpgrp getpgid setpgid initgroups getgroups setgroups\
getpriority getrlimit dlopen sigprocmask sigaction _setjmp\
! setsid telldir seekdir fchmod mktime timegm cosh sinh tanh)
AC_ARG_ENABLE(setreuid,
[ --enable-setreuid use setreuid()/setregid() according to need ev
en if obsolete.],
[use_setreuid=$enableval])


$ diff -p configure configure.orig
*** configure Fri Jul 25 01:02:15 2003
--- configure.orig Thu Jul 24 02:53:33 2003
*************** for ac_func in fmod killpg wait4 waitpid
*** 10311,10318 ****
setrgid setegid setregid setresgid issetugid pause lchown lchmod\
getpgrp setpgrp getpgid setpgid initgroups getgroups setgroups\
getpriority getrlimit dlopen sigprocmask sigaction _setjmp\
! setsid telldir seekdir fchmod mktime timegm cosh sinh tanh\
! j0 j1 jn y0 y1 yn
do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
echo "$as_me:$LINENO: checking for $ac_func" >&5
--- 10311,10317 ----
setrgid setegid setregid setresgid issetugid pause lchown lchmod\
getpgrp setpgrp getpgid setpgid initgroups getgroups setgroups\
getpriority getrlimit dlopen sigprocmask sigaction _setjmp\
! setsid telldir seekdir fchmod mktime timegm cosh sinh tanh
do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
echo "$as_me:$LINENO: checking for $ac_func" >&5


$ diff -p math.c math.c.orig
*** math.c Fri Jul 25 01:01:47 2003
--- math.c.orig Thu Jul 10 02:36:46 2003
*************** math_erfc(obj, x)
*** 291,347 ****
return rb_float_new(erfc(RFLOAT(x)->value));
}

- #ifdef HAVE_J0
- static VALUE math_j0(VALUE obj, VALUE x)
- {
- Need_Float(x);
- return rb_float_new(j0(RFLOAT(x)->value));
- }
- #endif
-
- #ifdef HAVE_J1
- static VALUE math_j1(VALUE obj, VALUE x)
- {
- Need_Float(x);
- return rb_float_new(j1(RFLOAT(x)->value));
- }
- #endif
-
- #ifdef HAVE_JN
- static VALUE math_jn(VALUE obj, VALUE n, VALUE x)
- {
- Need_Float(x);
- n = rb_Integer(n);
- return rb_float_new(jn(FIX2LONG(n), RFLOAT(x)->value));
- }
- #endif
-
- #ifdef HAVE_Y0
- static VALUE math_y0(VALUE obj, VALUE x)
- {
- Need_Float(x);
- return rb_float_new(y0(RFLOAT(x)->value));
- }
- #endif
-
- #ifdef HAVE_Y1
- static VALUE math_y1(VALUE obj, VALUE x)
- {
- Need_Float(x);
- return rb_float_new(y1(RFLOAT(x)->value));
- }
- #endif
-
- #ifdef HAVE_YN
- static VALUE math_yn(VALUE obj, VALUE n, VALUE x)
- {
- Need_Float(x);
- n = rb_Integer(n);
- return rb_float_new(yn(FIX2LONG(n), RFLOAT(x)->value));
- }
- #endif
-
void
Init_Math()
{
--- 291,296 ----
*************** Init_Math()
*** 388,410 ****

rb_define_module_function(rb_mMath, "erf", math_erf, 1);
rb_define_module_function(rb_mMath, "erfc", math_erfc, 1);
-
- #ifdef HAVE_J0
- rb_define_module_function(rb_mMath, "j0", math_j0, 1);
- #endif
- #ifdef HAVE_J1
- rb_define_module_function(rb_mMath, "j1", math_j1, 1);
- #endif
- #ifdef HAVE_JN
- rb_define_module_function(rb_mMath, "jn", math_jn, 2);
- #endif
- #ifdef HAVE_Y0
- rb_define_module_function(rb_mMath, "y0", math_y0, 1);
- #endif
- #ifdef HAVE_Y1
- rb_define_module_function(rb_mMath, "y1", math_y1, 1);
- #endif
- #ifdef HAVE_YN
- rb_define_module_function(rb_mMath, "yn", math_yn, 2);
- #endif
}
--- 337,340 ----



 
Reply With Quote
 
 
 
 
Yukihiro Matsumoto
Guest
Posts: n/a
 
      07-25-2003
Hi,

In message "Patches to 1.8.0p4 to add Bessel functions for those that have 'em"
on 03/07/25, Mike Hall <(E-Mail Removed)> writes:

|Here's some simple patches to configure.in, configure and math.c
|to add the Bessel functions on those systems that have them
|in their math library. They were made against 1.8.0 preview 4.
|
|It's probably better to have one #define for all the Bessels,
|and avoid the pollution of all the little #define's.

I want Ruby to be as portable as possible among platforms, so that I
decided when we add Bessel functions to Math module, we will prepare
substitution functions for those who don't have them.

If you (or others) come up with your version of Bessel functions (that
need not to be elegant) in a few days, I can merge them before 1.8.0.

matz.

 
Reply With Quote
 
 
 
 
Josef 'Jupp' Schugt
Guest
Posts: n/a
 
      07-25-2003
Saluton!

* Yukihiro Matsumoto; 2003-07-25, 18:41 UTC:
> If you (or others) come up with your version of Bessel functions
> (that need not to be elegant) in a few days, I can merge them
> before 1.8.0.


Numerical Recipes in... (e.g. ...in C) has implementations of
different kinds of Bessel functions. I see no technical problem
porting them to Ruby but up to now I did not do that because I am
usure about wether such code can be released under Ruby's license or
not. Besides that it's nothing but a quick hack.

Gis,

Josef 'Jupp' Schugt
--
N'attribuez jamais à la malice ce que l'incompétence explique !
-- Napoléon

 
Reply With Quote
 
Martin Weber
Guest
Posts: n/a
 
      07-25-2003
On Sat, Jul 26, 2003 at 01:41:35AM +0900, Yukihiro Matsumoto wrote:
> Hi,
>
> In message "Patches to 1.8.0p4 to add Bessel functions for those that have 'em"
> on 03/07/25, Mike Hall <(E-Mail Removed)> writes:
>
> |Here's some simple patches to configure.in, configure and math.c
> |to add the Bessel functions on those systems that have them
> |in their math library. They were made against 1.8.0 preview 4.
> |
> |It's probably better to have one #define for all the Bessels,
> |and avoid the pollution of all the little #define's.
>
> I want Ruby to be as portable as possible among platforms, so that I
> decided when we add Bessel functions to Math module, we will prepare
> substitution functions for those who don't have them.
>
> If you (or others) come up with your version of Bessel functions (that
> need not to be elegant) in a few days, I can merge them before 1.8.0.


Why not simply use those of BSD ? Okay, the originate from Sun (due
to the comment at the start of the files) but you can basically do
what you want as long as the comment stays in the source file, so
could include those in the ruby distribution ? *shrug* I mean why
reinvent the wheel when usable code is out there.

-martin

 
Reply With Quote
 
Josef 'Jupp' Schugt
Guest
Posts: n/a
 
      07-26-2003
Saluton!

* Martin Weber; 2003-07-25, 22:53 UTC:
> Why not simply use those of BSD ? Okay, the originate from Sun (due
> to the comment at the start of the files) but you can basically do
> what you want as long as the comment stays in the source file, so
> could include those in the ruby distribution ? *shrug* I mean why
> reinvent the wheel when usable code is out there.


Out where exactly?

Gis,

Josef 'Jupp' Schugt
--
N'attribuez jamais à la malice ce que l'incompétence explique !
-- Napoléon

 
Reply With Quote
 
Martin Weber
Guest
Posts: n/a
 
      07-27-2003
On Sun, Jul 27, 2003 at 07:08:09AM +0900, Josef 'Jupp' Schugt wrote:
> Saluton!
>
> * Martin Weber; 2003-07-25, 22:53 UTC:
> > Why not simply use those of BSD ? Okay, the originate from Sun (due
> > to the comment at the start of the files) but you can basically do
> > what you want as long as the comment stays in the source file, so
> > could include those in the ruby distribution ? *shrug* I mean why
> > reinvent the wheel when usable code is out there.

>
> Out where exactly?


E.g. in the netbsd source tree, e.g. j0 in src/lib/libm/src/ej0.c.
The other bessel funcs are lurking there (in this dir), too.

-Martin

 
Reply With Quote
 
Josef 'Jupp' Schugt
Guest
Posts: n/a
 
      07-29-2003
Saluton!

* Yukihiro Matsumoto; 2003-07-25, 18:41 UTC:
> If you (or others) come up with your version of Bessel functions
> (that need not to be elegant) in a few days, I can merge them
> before 1.8.0.


When implementating special functions like Bessel ones, care must be
taken about limited precision of floating point numbers - a problem
alien to most programmers. Moreover the algorithms used to evaluate
special functions often depend on quite a number of constants each of
wich may for some reason or another be imprecise. For these reasons I
suggest *not* adding Bessel functions to Ruby 1.8. In my opinion we
should rather strive for including GSL (GNU Scientific Library)
support in core Ruby 2.0.

Gis,

Josef 'Jupp' Schugt
--
N'attribuez jamais à la malice ce que l'incompétence explique !
-- Napoléon

 
Reply With Quote
 
Josef 'Jupp' Schugt
Guest
Posts: n/a
 
      07-30-2003
Saluton!

* Guillaume Marcais; 2003-07-30, 13:57 UTC:
> >In my opinion we
> >should rather strive for including GSL (GNU Scientific Library)
> >support in core Ruby 2.0.
> >

> Isn't GSL GPL licensed? And that could cause problem to include it
> into the core of Ruby.


I did not write 'include GSL' but include 'GSL support'. The GPL does
only apply to software released under it and software based on it
where 'based on it' means that you took the GPLd software and did
modify it.

What are you doing when you create Ruby bindings for GSL? You write a
wrapper for some library that implements functionality and API of
GSL. By *no* means do you require that GSL is the library that is
actually being used.

Therefore Ruby bindings to GSL are completely independent of GSL.
Once we have a Ruby way of using GSL we can still think about
creating a RLSL (Ruby's License Scientific Library).

Taking into account the typical use of special functions I don't see
the need for reinventing the wheel.

> Is there already a Ruby binding to GSL?


Yes.

Gis,

Josef 'Jupp' Schugt
--
N'attribuez jamais à la malice ce que l'incompétence explique !
-- Napoléon

 
Reply With Quote
 
Mike Hall
Guest
Posts: n/a
 
      08-01-2003

I reworked the patches for the Bessel et.al. math functions into an extension.
Direct link: http://users.rcn.com/m3ha11/ruby/mathext-0.1.tar.gz
Tested on 1.8.0preview6 on OS X last night.

I don't know why this bugs me so much. I guess it's just a matter of:
if ruby has access to _some_ functions in 'libm', then it should have
access to all of them. That doesn't really make sense, I know.

I agree with Josef that if we were to rewrite our own Bessels (etc.),
we'd want someone who really knows what they are doing.
I re-read 'What Every Computer Scientist Should Know About Floating Point"
last night -- very scarey stuff!



 
Reply With Quote
 
Hal E. Fulton
Guest
Posts: n/a
 
      08-01-2003
----- Original Message -----
From: "Mike Hall" <(E-Mail Removed)>
Newsgroups: comp.lang.ruby
To: "ruby-talk ML" <(E-Mail Removed)>
Sent: Friday, August 01, 2003 12:13 PM
Subject: Re: Patches to 1.8.0p4 to add Bessel functions for those that have
'em


> I agree with Josef that if we were to rewrite our own Bessels (etc.),
> we'd want someone who really knows what they are doing.
> I re-read 'What Every Computer Scientist Should Know About Floating Point"
> last night -- very scarey stuff!


Hmm, I don't know that. Is it on the web?

Hal

--
Hal Fulton
http://www.velocityreviews.com/forums/(E-Mail Removed)


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Remember those patches you delayed Shane NZ Computing 0 06-23-2007 12:54 AM
Good news to all those who are seeking for job in dotnet(Only those who are leaving in Hyderabad -India) BinnuChowdary ASP .Net 1 05-02-2006 06:42 AM
Good news to all those who are seeking for job in dotnet(Only those who are leaving in Hyderabad -India) BinnuChowdary ASP .Net 0 05-02-2006 04:13 AM
Good news to all those who are seeking for job in dotnet(Only those who are leaving in Hyderabad -India) BinnuChowdary ASP .Net 1 05-01-2006 01:03 PM



Advertisments