Chris,
Your 'where' option works well, but not so much for multi-dimensional arrays.
It's possible to use whereND, but it gets awfully convoluted having to reorder
dimensions so that it threads over the required dimensions, e.g. for 2
dimensions something like this:
$data = $data(:,which($data(1,:)>=0))->sever;
becomes:
$data = $data->transpose->whereND($data((1),:) > 0)->transpose->sever;
I ended up sticking with my usage of which() and adding some tests to catch the
singular dimension cases.
Looking forward to a future release that might iron out this issue :-).
Kind regards,
Trevor
-----Original Message-----
From: Chris Marshall [mailto:[email protected]]
Sent: Tuesday, 23 January 2018 3:56 p.m.
To: Trevor Carey-Smith <[email protected]>
Cc: perldl <[email protected]>
Subject: Re: [Pdl-general] Slicing pdl with empty index variable
Trevor-
Did the where work around work or did you come up with a better solution?
--Chris
On 1/13/2018 12:53, Chris Marshall wrote:
> If you skip the index part using where does it work?
> E.g.,
>
> $a->where($a==0) .= 1;
> $b = $b->where($b>0)->sever;
>
> --Chris
>
> On 1/12/2018 20:07, Trevor Carey-Smith wrote:
>> Thanks Craig.
>>
>> In the interim, is there a better way to do the following:
>>
>> $a(which($a==0)).=1;
>> $b = $b(which($b > 0))->sever;
>>
>> as now I'll have to replace all this sort of thing with something like:
>>
>> $tmp=which($a==0);
>> if ($tmp->nelem > 0) { a($tmp) .= 1; }
>>
>> $tmp = which($b > 0);
>> if ($tmp->nelem > 0) {
>> $b = $b($tmp)->sever;
>> } else {
>> $b = pdl([ ]);
>> }
>>
>> Cheers,
>> Trevor
>>
>> ________________________________________
>> From: Craig DeForest <[email protected]>
>> Sent: Saturday, 13 January 2018 9:35 a.m.
>> To: Trevor Carey-Smith
>> Cc: Craig DeForest; [email protected]
>> Subject: Re: [Pdl-general] Slicing pdl with empty index variable
>>
>> Hmmm. Looks like you've discovered a wart. Indexing pdl(1,2) with
>> an Empty does the right thing and returns Empty. But indexing a
>> scalar or a 1-D PDL with one element fails. I think it's because
>> Empties are implemented under the hood as 1x0 PDLs (to distinguish
>> them from Nulls, which have 0 in the first position).
>>
>>
>>
>>> On Jan 11, 2018, at 8:52 PM, Trevor Carey-Smith
>>> <[email protected]> wrote:
>>>
>>> Hi,
>>>
>>> Sorry I've been out of the PDL loop for a long time, but have an old
>>> script written in PDL that I use a lot. After a recent IT upgrade
>>> here we have shifted to PDL v2.018 and I'm getting some behaviour
>>> that is new from our previous install (2.4 in the old numbering
>>> system???).
>>>
>>> The script uses some which() statements to create indexing vectors
>>> to slice the original pdl. Normally when the which statement comes
>>> back empty, the slice command returns an empty pdl itself. But if
>>> the slicing dimension (regardless of the total number of dimensions)
>>> of the original pdl is of length 1 bad things happen. Perhaps an
>>> example is clearer:
>>>
>>> pdl> p $empty=pdl([])
>>> Empty[0]
>>> pdl> p $d2=pdl([1,2])
>>> [1 2]
>>> pdl> p $d2($empty)
>>> Empty[0]
>>> pdl> p $d1=pdl([1])
>>> [1]
>>> pdl> p $d1($empty)
>>> Stringizing problem: slice: slice starts out of bounds in pos 0
>>> (start is 1; source dim 0 runs 0 to 0). eval {...} called at
>>> /scale_akl_persistent/filesets/opt_niwa/centos7-x86_64-skl_prelim/GC
>>> C-4.8.5/Perl/5.24.1-GCC-4.8.5/lib/perl5/site_perl/5.24.1/x86_64-linu
>>> x-thread-multi/PDL/Core.pm
>>> line 2857
>>> PDL::string(PDL=SCALAR(0x1053d10), undef, "") called at
>>> /scale_akl_persistent/filesets/opt_niwa/centos7-x86_64-skl_prelim/GC
>>> C-4.8.5/Perl/5.24.1-GCC-4.8.5/bin/perldl
>>> line 402
>>> main::p(PDL=SCALAR(0x1053d10)) called at (eval 151) line 4
>>> main::__ANON__() called at
>>> /scale_akl_persistent/filesets/opt_niwa/centos7-x86_64-skl_prelim/GC
>>> C-4.8.5/Perl/5.24.1-GCC-4.8.5/bin/perldl
>>> line 719
>>> eval {...} called at
>>> /scale_akl_persistent/filesets/opt_niwa/centos7-x86_64-skl_prelim/GC
>>> C-4.8.5/Perl/5.24.1-GCC-4.8.5/bin/perldl
>>> line 719
>>> main::eval_and_report("p \$d1->slice(\$empty)\x{a}") called
>>> at
>>> /scale_akl_persistent/filesets/opt_niwa/centos7-x86_64-skl_prelim/GC
>>> C-4.8.5/Perl/5.24.1-GCC-4.8.5/bin/perldl
>>> line 655
>>> main::process_input() called at
>>> /scale_akl_persistent/filesets/opt_niwa/centos7-x86_64-skl_prelim/GC
>>> C-4.8.5/Perl/5.24.1-GCC-4.8.5/bin/perldl
>>> line 675
>>> eval {...} called at
>>> /scale_akl_persistent/filesets/opt_niwa/centos7-x86_64-skl_prelim/GC
>>> C-4.8.5/Perl/5.24.1-GCC-4.8.5/bin/perldl
>>> line 675
>>> at
>>> /scale_akl_persistent/filesets/opt_niwa/centos7-x86_64-skl_prelim/GC
>>> C-4.8.5/Perl/5.24.1-GCC-4.8.5/lib/perl5/site_perl/5.24.1/x86_64-linu
>>> x-thread-multi/PDL/Core.pm
>>> line 2888, <STDIN> line 92.
>>> PDL::string(PDL=SCALAR(0x1053d10), undef, "") called at
>>> /scale_akl_persistent/filesets/opt_niwa/centos7-x86_64-skl_prelim/GC
>>> C-4.8.5/Perl/5.24.1-GCC-4.8.5/bin/perldl
>>> line 402
>>> main::p(PDL=SCALAR(0x1053d10)) called at (eval 151) line 4
>>> main::__ANON__() called at
>>> /scale_akl_persistent/filesets/opt_niwa/centos7-x86_64-skl_prelim/GC
>>> C-4.8.5/Perl/5.24.1-GCC-4.8.5/bin/perldl
>>> line 719
>>> eval {...} called at
>>> /scale_akl_persistent/filesets/opt_niwa/centos7-x86_64-skl_prelim/GC
>>> C-4.8.5/Perl/5.24.1-GCC-4.8.5/bin/perldl
>>> line 719
>>> main::eval_and_report("p \$d1->slice(\$empty)\x{a}") called
>>> at
>>> /scale_akl_persistent/filesets/opt_niwa/centos7-x86_64-skl_prelim/GC
>>> C-4.8.5/Perl/5.24.1-GCC-4.8.5/bin/perldl
>>> line 655
>>> main::process_input() called at
>>> /scale_akl_persistent/filesets/opt_niwa/centos7-x86_64-skl_prelim/GC
>>> C-4.8.5/Perl/5.24.1-GCC-4.8.5/bin/perldl
>>> line 675
>>> eval {...} called at
>>> /scale_akl_persistent/filesets/opt_niwa/centos7-x86_64-skl_prelim/GC
>>> C-4.8.5/Perl/5.24.1-GCC-4.8.5/bin/perldl
>>> line 675
>>>
>>> Can anyone shed any light on what's going on here??
>>>
>>> Thanks,
>>> Trevor.
>>>
>>> --------------------------------------------------------------------
>>> ----------
>>>
>>> Check out the vibrant tech community on one of the world's most
>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>>> _______________________________________________
>>> pdl-general mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/pdl-general
>>>
>>
>> ---------------------------------------------------------------------
>> ---------
>>
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> _______________________________________________
>> pdl-general mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/pdl-general
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
pdl-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pdl-general