You are running into a wart with auto promotion and the threading engine.  The 
PDL case is either a wart or a bug.  It should almost certainly throw an error 
since the output of the sum cannot fit in the original PDL.  

The answer would be to tweak the threading rules to handle the asymmetric 
requirements for computed assignment.  The workaround is to use a construction 
like "$a = $a + $b" instead of "$a += $b".

Sent from my iPad

> On Mar 4, 2015, at 11:46 PM, PDL users list 
> <[email protected]> wrote:
> 
> Hello all,
> 
> I was trying something out and wanted to create a new piddle from a
> scalar that matched the dimensions of another piddle, so I tried the
> following:
> 
>    use PDL;
>    my $other = zeros(3,2);
>    my $cases = {
>        'scalar' => 1,      # Just a Perl scalar
>        'pdl'    => pdl(1), # a 0-dim piddle
>    };
> 
>    $_ += $other  for values %$cases;
> 
> 
>    use DDP; p $cases;
> 
> and I got the following output:
> 
>    \ {
>        pdl      PDL {
>            Data     : 1
>            Type     : double
>            Shape    : Empty[0]
>            Nelem    : 1
>            Min      : 1
>            Max      : 1
>            Badflag  : No
>            Has Bads : No
>        },
>        scalar   PDL {
>            Data     : [
>                        [1 1 1]
>                        [1 1 1]
>                       ]
>            Type     : double
>            Shape    : [3 2]
>            Nelem    : 6
>            Min      : 1
>            Max      : 1
>            Badflag  : No
>            Has Bads : No
>        }
>    }
> 
> I think I understand the reasoning behind this behaviour, but what I
> would like to know is if there is a way to be able to get the same
> output as in the scalar case when using the 0-dim piddle `pdl(1)` ( or
> even `pdl([ 1 ])` ).
> 
> Regards,
> - Zaki Mughal
> 
> ------------------------------------------------------------------------------
> Dive into the World of Parallel Programming The Go Parallel Website, sponsored
> by Intel and developed in partnership with Slashdot Media, is your hub for all
> things parallel software development, from weekly thought leadership blogs to
> news, videos, case studies, tutorials and more. Take a look and join the 
> conversation now. http://goparallel.sourceforge.net/
> _______________________________________________
> pdl-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/pdl-general
> 

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
pdl-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pdl-general

Reply via email to