I am using pdl 2.4.9. In both cases the data was initialized the exact same way. This is part of a much larger body of code but if you'd like for me to do so I can try and create a small test case to replicate this behavior.
> Date: Thu, 2 Feb 2012 12:49:24 -0500 > Subject: Re: [Perldl] how to sort a piddle ??? > From: [email protected] > To: [email protected] > CC: [email protected] > > If ->at() works but ->sclr doesn't that would suggest > a problem. What version of PDL are you running? > Is it possible that @t_stats was initialized to piddle > values for the slow case. at and sclr should give > the same results.... > > --Chris > > On Thu, Feb 2, 2012 at 12:24 PM, Adam Russell <[email protected]> wrote: > > Well, the docs > > http://pdl.perl.org/PDLdocs/Core.html#sclr > > state "The sclr method is useful to turn a piddle into a normal Perl > > scalar." > > If at works and sclr doesn't than maybe something is wrong with the sclr > > code? > > The docs say they should have the same output with the convenience that sclr > > doesn't require you to specify a position. > > So, lets see what happens when I use at... > > Ok, I now see this in the profiler output > > > > @s_t_stats=sort {$b <=> $a} @t_stats; > > # spent 3.92ms making 4 calls to CORE:sort, avg 980µs/call > > So, ok, at wins! > > Thanks for the advice! > > Finally though, does this indicate a problem with sclr? > > > > ________________________________ > > Date: Thu, 2 Feb 2012 10:31:53 -0600 > > > > Subject: Re: [Perldl] how to sort a piddle ??? > > From: [email protected] > > To: [email protected] > > CC: [email protected] > > > > > > Hmm, looks to me like "sclr" may not be doing what you mean. I'm not sure, > > though, because I've never noticed sclr before. At any rate, it looks like > > the sort is calling the spaceship operator on piddles, but it should be > > using the built-in spaceship operator because it should be sorting scalars. > > > > What happens to your sort if you use "at" instead of "sclr"? > > > > David > > > > On Thu, Feb 2, 2012 at 10:01 AM, Adam Russell <[email protected]> wrote: > > > > This thread reminded me of a pdl sort issue I was having. > > I hope I not too off topic... > > So, I am using pdl from within a larger body of Perl code. > > I am using PDL::Stats to perform a t_test on a bunch of data I store in > > pdls. > > Once I get done with this I sort the t-statistics and then throw away the > > pdls. > > I noticed my code was running somewhat slower than I would have thought it > > shoud. > > So, I ran the code under the NYT profiler. My code was spending the majority > > of its time (~80% of total execution time!) > > on the last line below(yeah, I uncreatively named the pdls "pdls"): > > > > foreach my $dim_n (0..$self->{dimension}-1){ > > my ($t, $df) = t_test($pdls[$dim_n][$cat_n][0], > > $pdls[$dim_n][$cat_n][1]); > > $t_stats[$dim_n]=$t->abs->sclr; > > } > > @s_t_stats=sort {$b <=> $a} @t_stats; > > > > Here is what profiler output for that line looks like: > > @s_t_stats=sort {$b <=> $a} @t_stats; > > # spent 5.18s making 4 calls to CORE:sort, avg 1.29s/call > > # spent 3.43s making 91451 calls to PDL::string, avg 38µs/call > > # spent 939ms making 91451 calls to PDL::spaceship, avg 10µs/call > > # spent 44µs making 15 calls to PDL::DESTROY, avg 3µs/call > > > > 1.29 seconds for each call to sort is very long time! From the calls made > > when that line is executed it seems that for some reason > > it is doing some sort of string conversion? But why? Surely $t->abs->sclr is > > returning a numeric, right? > > The code currently takes about 10 seconds to run. If I take care of this > > sort problem I could probably get runs in > > under 3 seconds. > > > > Any advice on why this sort is so slow? > > Best Regards, > > Adam > > > > > >> Date: Thu, 2 Feb 2012 07:07:24 -0600 > >> From: [email protected] > >> To: [email protected] > >> CC: [email protected] > >> Subject: Re: [Perldl] how to sort a piddle ??? > > > >> > >> I agree with Matt that you are probably looking for `qsort`. > >> > >> As to what > >> > >> @e = pdl(3,2,6,4,8,6); > >> @r = sort{$a <=> $b} @e; > >> > >> is doing, its working perfectly; its just not doing what you mean. @e > >> is a one element Perl-level array, its one element is a PDL object. > >> Any sort on a one element array will return the same order, what else > >> could it do. > >> > >> You have to remember that a PDL object is just another scalar in > >> Perl's eyes, as are all objects. > >> > >> Here is another example > >> > >> @e = (pdl(3,2,6,4,8,6), pdl(5,6,2,1)); > >> @r = sort{$a <=> $b} @e; > >> > >> Here @e has two PDL object. When you sort objects numerically ( using > >> <=> ), what you will actually sort on is not their contents, but their > >> address in memory. > >> > >> The take-away message is this: PDL overloads many of the Perl > >> operators, and it can feel like PDL and Perl are fully integrated, but > >> in truth a PDL object is still an object, that is a scalar reference > >> with methods and overloads. PDL tries to Do What You Mean when it can, > >> this is not one of those times. > > > > > > _______________________________________________ > > Perldl mailing list > > [email protected] > > http://mailman.jach.hawaii.edu/mailman/listinfo/perldl > > > > > > > > > > -- > > "Debugging is twice as hard as writing the code in the first place. > > Therefore, if you write the code as cleverly as possible, you are, > > by definition, not smart enough to debug it." -- Brian Kernighan > > > > > > _______________________________________________ > > Perldl mailing list > > [email protected] > > http://mailman.jach.hawaii.edu/mailman/listinfo/perldl > >
_______________________________________________ Perldl mailing list [email protected] http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
