Discussion:
[Pdl-porters] scalar to piddle conversion problem
Chris Marshall
2014-04-30 18:44:29 UTC
Permalink
It appears that one of the remaining problems
of the longlong-double-fix branch of PDL git is
that perl scalars are not correctly promoted
to piddles which leads to some sort of truncation
in mixed operations.

Here is a short session in pdl2 showing the
problem:

pdl> $d = 2 # ordinary perl scalar

pdl> $dpdl = pdl(2) # piddle with same value
pdl> p $d - $dpdl # subtracting gives 0, good
0
pdl> p $d - 2 # subtracting 2 from $d is 0
0
pdl> p $dpdl - 2 # subtracting 2 from $dpdl is 0
0
pdl> p $d - 2.0 # subtracting 2.0 from $d is 0
0
pdl> p $dpdl - 2.0 # BUT from $dpdl gives 2!!!
2

Any ideas where such a symptom could arise
or where the relevant code is? I don't have any
idea on where or how to trace the values here and
haven't been making much progress with fprintf
(not surprising since I don't know where to go...)

The latest version has been pushed to PDL git
on sf.net in the longlong-double-fix branch.


Thanks in advance!
Chris
Chris Marshall
2014-04-30 20:39:11 UTC
Permalink
That matches my reasoning. I thought it might be related to
the typemap to convert a perl scalar into a PDL_Anyval but
I can't see how that connects with the problem below. Maybe
it is in the SvPDLV() part....

--Chris
I believe, based on reading the docs for Devel::Peek, that the fact
that you tried both $d and 2 is a red herring. This shows (which I didn’t
$ perl -MDevel::Peek -e 'Dump 2'
SV = IV(0x14ea698) at 0x14ea6a8
REFCNT = 1
FLAGS = (IOK,READONLY,pIOK)
IV = 2
$ perl -MDevel::Peek -e 'Dump 2.0'
SV = NV(0xadf1f0) at 0xabe6a8
REFCNT = 1
FLAGS = (NOK,READONLY,pNOK)
NV = 2
Therefore I predict that you will see the difference in behaviour between
“$dpdl – 2” and “$dpdl – 2.0”. It looks like a difference in behaviour
between an IV (int) and an NV (floating-point).
*Sent:* Wednesday, April 30, 2014 7:44 PM
*Subject:* [Pdl-porters] scalar to piddle conversion problem
It appears that one of the remaining problems
of the longlong-double-fix branch of PDL git is
that perl scalars are not correctly promoted
to piddles which leads to some sort of truncation
in mixed operations.
Here is a short session in pdl2 showing the
pdl> $d = 2 # ordinary perl scalar
pdl> $dpdl = pdl(2) # piddle with same value
pdl> p $d - $dpdl # subtracting gives 0, good
0
pdl> p $d - 2 # subtracting 2 from $d is 0
0
pdl> p $dpdl - 2 # subtracting 2 from $dpdl is 0
0
pdl> p $d - 2.0 # subtracting 2.0 from $d is 0
0
pdl> p $dpdl - 2.0 # BUT from $dpdl gives 2!!!
2
Any ideas where such a symptom could arise
or where the relevant code is? I don't have any
idea on where or how to trace the values here and
haven't been making much progress with fprintf
(not surprising since I don't know where to go...)
The latest version has been pushed to PDL git
on sf.net in the longlong-double-fix branch.
Thanks in advance!
Chris
------------------------------
_______________________________________________
PDL-porters mailing list
http://mailman.jach.hawaii.edu/mailman/listinfo/pdl-porters
Ed .
2014-04-30 20:33:43 UTC
Permalink
I believe, based on reading the docs for Devel::Peek, that the fact that you tried both $d and 2 is a red herring. This shows (which I didn’t know, so please bear with me) that constants are turned into scalars:
$ perl -MDevel::Peek -e 'Dump 2'
SV = IV(0x14ea698) at 0x14ea6a8
REFCNT = 1
FLAGS = (IOK,READONLY,pIOK)
IV = 2
$ perl -MDevel::Peek -e 'Dump 2.0'
SV = NV(0xadf1f0) at 0xabe6a8
REFCNT = 1
FLAGS = (NOK,READONLY,pNOK)
NV = 2
Therefore I predict that you will see the difference in behaviour between “$dpdl – 2” and “$dpdl – 2.0”. It looks like a difference in behaviour between an IV (int) and an NV (floating-point).

From: Chris Marshall
Sent: Wednesday, April 30, 2014 7:44 PM
To: pdl-porters
Subject: [Pdl-porters] scalar to piddle conversion problem

It appears that one of the remaining problems
of the longlong-double-fix branch of PDL git is
that perl scalars are not correctly promoted
to piddles which leads to some sort of truncation
in mixed operations.


Here is a short session in pdl2 showing the

problem:

pdl> $d = 2 # ordinary perl scalar

pdl> $dpdl = pdl(2) # piddle with same value
pdl> p $d - $dpdl # subtracting gives 0, good
0
pdl> p $d - 2 # subtracting 2 from $d is 0
0
pdl> p $dpdl - 2 # subtracting 2 from $dpdl is 0
0
pdl> p $d - 2.0 # subtracting 2.0 from $d is 0
0
pdl> p $dpdl - 2.0 # BUT from $dpdl gives 2!!!
2


Any ideas where such a symptom could arise
or where the relevant code is? I don't have any
idea on where or how to trace the values here and
haven't been making much progress with fprintf

(not surprising since I don't know where to go...)


The latest version has been pushed to PDL git
on sf.net in the longlong-double-fix branch.



Thanks in advance!
Chris



--------------------------------------------------------------------------------
Loading...