----- Original Message ----- From: "David Mertens" <[email protected]>
To: "Sisyphus" <[email protected]>
Cc: "Diab Jerius" <[email protected]>; <[email protected]>
Sent: Tuesday, June 26, 2012 11:45 PM
Subject: Re: [Perldl] [ANN] PDL::FuncND


Hmm, I wonder if we could copy lgamma directly into our source code and
only define it for #ifdef MSVCC or some such.

I expect that could probably be done in math.pd.

It turns out that the MinGW implementation of lgamma returns only the value, not the sign (signgam) of the value returned by the gamma function. So, for the moment, I implemented it in a local copy of the latest (git) math.pd as per the attached diff.

Basically we calculate
double b = lgamma(arg);
int s = gamma(arg) < 0 ? -1 :1;
return both b and s.

Seems to be doing the right thing - though s should really (but won't) be set to -1 if arg is -0. (At least that's what the mpfr library does ... and those guys generally follow the IEEE standards rigorously.) Anyway, with that in place, PDL::FuncND then passes all of its tests on MS Windows.

In order to have math.pd provide an "lgamma" implementation for MS compilers, I guess we just need to provide another elsif block:

elsif($Config{cc} eq 'cl') {
     pp_def("lgamma",
     ..............
}

I can't find any gamma or lgamma implementation in any of my MS compilers' headers, so it would have to be a "back to basics" implementation. (At least their math.h provides a 'log' function ..... I think :-)

I ran the following script as a basic sanity check of the MinGW implementation:

############################
use strict;
use warnings;
use PDL;
use PDL::Math;

my @x = lgamma(-0.1);
print "@x\n";

@x = lgamma(1.1);
print "@x\n";

@x = lgamma(-0.0);
print "@x\n";

@x = lgamma('inf' + 0);
print "@x\n";

@x = lgamma('nan' + 0);
print "@x\n";
############################

It output:
2.36896133272879 -1
-0.0498724412598397 1
1.#INF 1
1.#INF 1
-1.#IND 1

I think that's reasonable enough.
But one thing that dumbarse me couldn't work out how to do, is to verify that the BAD value implementation is behaving sanely.
How do I construct an example that will test that ?

AFAICT, there's no testing of the PDL::Math::lgamma function in the PDL test suite - not even for non-windows platforms.

Cheers,
Rob

Attachment: math.pd.diff
Description: Binary data

_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to