#69 Create nan PDL

open-fixed
None
8
2012-07-03
2012-05-21
No

The following code return a -nan PDL for both values. Expected the first to be nan and the second to be -nan.

#!/usr/bin/perl

use strict;
use warnings;

use PDL;

my $c = PDL->new("nan");
print "nan: ".ref($c)." ".$c."\n";
$c = PDL->new("-nan");
print "-nan: ".ref($c)." ".$c."\n";

Discussion

1 2 3 4 > >> (Page 1 of 4)
  • Chris Marshall

    Chris Marshall - 2012-05-21

    I'm not sure that -NaN and +NaN is significant but we should
    definitely be self-consistent.

     
  • Chris Marshall

    Chris Marshall - 2012-05-21

    Please update this ticket with the output from perldl -V
    and any other relevant version information. Thanks

     
  • Chris Marshall

    Chris Marshall - 2012-05-22

    In what context is this causing problems?

     
  • Matthew McGillis

    nan and -nan are two very different things and not being able to differentiate is significant. So if assigning something nan results in -nan your results will be wrong.

    The context outlined is causing the problem I need to be able to create a PDL with values that include nan -nan inf numbers etc and they need to be kept consistent with what I assign.

    One environment:

    perldl -V
    perlDL shell v1.354
    PDL comes with ABSOLUTELY NO WARRANTY. For details, see the file
    'COPYING' in the PDL distribution. This is free software and you
    are welcome to redistribute it under certain conditions, see
    the same file for details.

    Summary of my PDL configuration

    VERSION: PDL v2.4.10 (supports bad values)

    $%PDL::Config = {
    'BADVAL_PER_PDL' => '0',
    'WITH_PROJ' => '0',
    'PDL_CONFIG_VERSION' => '0.005',
    'POSIX_THREADS_INC' => undef,
    'FFTW_TYPE' => 'double',
    'PDL_BUILD_DIR' => '/home/OCHZIFF/risk_mmcgillis/src/perl/PDL-2.4.10',
    'FFTW_LIBS' => undef,
    'WITH_FFTW' => '0',
    'GSL_LIBS' => undef,
    'WITH_IO_BROWSER' => '0',
    'PROJ_INC' => undef,
    'WHERE_PLPLOT_INCLUDE' => undef,
    'HTML_DOCS' => '1',
    'SKIP_KNOWN_PROBLEMS' => '0',
    'WHERE_PLPLOT_LIBS' => undef,
    'WITH_3D' => '0',
    'WITH_POSIX_THREADS' => '1',
    'POGL_VERSION' => '0.65',
    'FFTW_INC' => undef,
    'HIDE_TRYLINK' => '1',
    'HDF_INC' => undef,
    'WITH_HDF' => '0',
    'POGL_WINDOW_TYPE' => 'glut',
    'WITH_GD' => '0',
    'WITH_BADVAL' => '1',
    'FITS_LEGACY' => '1',
    'WITH_SLATEC' => '1',
    'BADVAL_USENAN' => '0',
    'WITH_DEVEL_REPL' => '1',
    'TEMPDIR' => '/tmp',
    'PROJ_LIBS' => undef,
    'USE_POGL' => '0',
    'PDL_BUILD_VERSION' => '2.4.10',
    'GD_LIBS' => undef,
    'GSL_INC' => undef,
    'GD_INC' => undef,
    'WITH_GSL' => '1',
    'OPTIMIZE' => undef,
    'PDLDOC_IGNORE_AUTOLOADER' => '0',
    'HDF_LIBS' => undef,
    'POSIX_THREADS_LIBS' => undef,
    'MALLOCDBG' => {},
    'WITH_MINUIT' => '1',
    'WITH_PLPLOT' => '0',
    'MINUIT_LIB' => undef
    };
    Summary of my perl5 (revision 5 version 10 subversion 1) configuration:

    Platform:
    osname=linux, osvers=2.6.18-194.26.1.el5, archname=x86_64-linux-thread-multi
    uname='linux x86-003.build.bos.redhat.com 2.6.18-194.26.1.el5 #1 smp fri oct 29 14:21:16 edt 2010 x86_64 x86_64 x86_64 gnulinux '
    config_args='-des -Doptimize=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -DDEBUGGING=-g -Dversion=5.10.1 -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dprefix=/usr -Dvendorprefix=/usr -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl5 -Dsitearch=/usr/local/lib64/perl5 -Dprivlib=/usr/share/perl5 -Darchlib=/usr/lib64/perl5 -Dvendorlib=/usr/share/perl5/vendor_perl -Dvendorarch=/usr/lib64/perl5/vendor_perl -Dinc_version_list=5.10.0 -Darchname=x86_64-linux-thread-multi -Dlibpth=/usr/local/lib64 /lib64 /usr/lib64 -Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl=n -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr -Dd_gethostent_r_proto -Ud_endhostent_r_proto -Ud_sethostent_r_proto -Ud_endprotoent_r_proto -Ud_setprotoent_r_proto -Ud_endservent_r_proto -Ud_setservent_r_proto -Dscriptdir=/usr/bin'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
    Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.4.4 20100726 (Red Hat 4.4.4-13)', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
    Linker and Libraries:
    ld='gcc', ldflags =' -fstack-protector'
    libpth=/usr/local/lib64 /lib64 /usr/lib64
    libs=-lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.12'
    Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib64/perl5/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'

    Another Environment:

    perldl -V
    perlDL shell v1.354
    PDL comes with ABSOLUTELY NO WARRANTY. For details, see the file
    'COPYING' in the PDL distribution. This is free software and you
    are welcome to redistribute it under certain conditions, see
    the same file for details.

    Summary of my PDL configuration

    VERSION: PDL v2.4.11 (supports bad values)

    $%PDL::Config = {
    'BADVAL_PER_PDL' => '0',
    'WITH_PROJ' => '0',
    'PDL_CONFIG_VERSION' => '0.005',
    'POSIX_THREADS_INC' => undef,
    'FFTW_TYPE' => 'double',
    'PDL_BUILD_DIR' => '/home/OCHZIFF/risk_mmcgillis/src/perl/PDL-2.4.11',
    'FFTW_LIBS' => undef,
    'WITH_FFTW' => '0',
    'GSL_LIBS' => undef,
    'WITH_IO_BROWSER' => '0',
    'PROJ_INC' => undef,
    'WHERE_PLPLOT_INCLUDE' => undef,
    'HTML_DOCS' => '1',
    'SKIP_KNOWN_PROBLEMS' => '0',
    'WHERE_PLPLOT_LIBS' => undef,
    'WITH_3D' => '0',
    'WITH_POSIX_THREADS' => '1',
    'POGL_VERSION' => '0.65',
    'FFTW_INC' => undef,
    'HIDE_TRYLINK' => '1',
    'HDF_INC' => undef,
    'WITH_HDF' => '0',
    'POGL_WINDOW_TYPE' => 'glut',
    'WITH_GD' => '0',
    'WITH_BADVAL' => '1',
    'FITS_LEGACY' => '1',
    'WITH_SLATEC' => '1',
    'BADVAL_USENAN' => '0',
    'WITH_DEVEL_REPL' => '1',
    'TEMPDIR' => '/tmp',
    'PROJ_LIBS' => undef,
    'USE_POGL' => '0',
    'PDL_BUILD_VERSION' => '2.4.11',
    'GD_LIBS' => undef,
    'GSL_INC' => undef,
    'GD_INC' => undef,
    'WITH_GSL' => '1',
    'OPTIMIZE' => undef,
    'PDLDOC_IGNORE_AUTOLOADER' => '0',
    'HDF_LIBS' => undef,
    'POSIX_THREADS_LIBS' => undef,
    'MALLOCDBG' => {},
    'WITH_MINUIT' => '1',
    'WITH_PLPLOT' => '0',
    'MINUIT_LIB' => undef
    };
    Summary of my perl5 (revision 5 version 10 subversion 1) configuration:

    Platform:
    osname=linux, osvers=2.6.18-194.26.1.el5, archname=x86_64-linux-thread-multi
    uname='linux x86-003.build.bos.redhat.com 2.6.18-194.26.1.el5 #1 smp fri oct 29 14:21:16 edt 2010 x86_64 x86_64 x86_64 gnulinux '
    config_args='-des -Doptimize=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -DDEBUGGING=-g -Dversion=5.10.1 -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dprefix=/usr -Dvendorprefix=/usr -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl5 -Dsitearch=/usr/local/lib64/perl5 -Dprivlib=/usr/share/perl5 -Darchlib=/usr/lib64/perl5 -Dvendorlib=/usr/share/perl5/vendor_perl -Dvendorarch=/usr/lib64/perl5/vendor_perl -Dinc_version_list=5.10.0 -Darchname=x86_64-linux-thread-multi -Dlibpth=/usr/local/lib64 /lib64 /usr/lib64 -Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl=n -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr -Dd_gethostent_r_proto -Ud_endhostent_r_proto -Ud_sethostent_r_proto -Ud_endprotoent_r_proto -Ud_setprotoent_r_proto -Ud_endservent_r_proto -Ud_setservent_r_proto -Dscriptdir=/usr/bin'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
    Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.4.4 20100726 (Red Hat 4.4.4-13)', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
    Linker and Libraries:
    ld='gcc', ldflags =' -fstack-protector'
    libpth=/usr/local/lib64 /lib64 /usr/lib64
    libs=-lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.12'
    Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib64/perl5/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'

     
  • Chris Marshall

    Chris Marshall - 2012-05-22

    Both print out as PDL [nan] with no -nan. for me.

     
  • Chris Marshall

    Chris Marshall - 2012-05-22

    The problem here appears to be how perl itself
    handles NaN values and not PDL. Could you give
    a specific example in plain perl where you use the
    difference between a -nan and +nan values? E.g.,
    where the actual content of the NaN is needed.

    That will help to formulate a way forward. Of course,
    patches are always welcome...

     
  • Chris Marshall

    Chris Marshall - 2012-05-22
    • milestone: --> 100443
     
  • Chris Marshall

    Chris Marshall - 2012-05-22

    More specifically, the issue is how perl handles stringification of
    NaN values.

     
  • Matthew McGillis

    Not sure if this is what your after but I have code in 2.4.9 that effectively does this:

    #!/usr/bin/perl

    use strict;
    use warnings;

    use PDL;

    my $c = PDL->new("nan");
    my $z = PDL->ones(1,1,1);
    $z->set(0,0,0,$c);
    print $z;

    Which produces the following:

    [
    [
    [nan]
    ]
    ]

    However for me with 2.4.10 and 2.4.11 the above produces:

    [
    [
    [0]
    ]
    ]

     
  • Chris Marshall

    Chris Marshall - 2012-05-22

    It appears that there is a bug/feature in using set()
    with a nan piddle, a work around is to use $nan->sclr
    to convert the pdl value into a perl scalar. E.g.,
    pdl> $z->set(0,0,0,$c)

    pdl> p $z

    [
    [
    [0]
    ]
    ]

    pdl> $z->set(0,0,0,$c->sclr)

    pdl> p $z

    [
    [
    [nan]
    ]
    ]

     
1 2 3 4 > >> (Page 1 of 4)

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks