Inspired by the other mail thread that discusses possible PDL doc
improvements, I hereby would like mention several things I feel awkward in
PDL. I see these points a from a library developer's perspective. And I
should say that I started to learn PDL only since sometime last year when I
started to work on my ggplot project [1], these points could be completely
wrong, so let me know if there are good ways to do it as I may not be aware
of.


1. As a library developer I normally don't simply "use PDL;", instead I
sometimes "use PDL::Core qw(pdl);", this gives me the pdl() function that
can create a piddle in my module namespace. But I found I have to also "use
PDL::Lite" as otherwise I could not call some object methods on the piddle
I created by the pdl() function. For example with out PDL::Lite,

use PDL::Core qw(pdl)
my $x = pdl(1,2,3)
$x->minmax;  # Can't locate object method "minmax" via package "PDL"...

I think this PDL::Lite was not very clearly mentioned in the doc. And why
not let it be implicitly loaded by other PDL modules like PDL::Core in this
case?


2. use PDL subclasses can polute the namespace. For example,

use 5.010;
use PDL::DateTime;
my $x = double(1,2,3);
say $x;    # prints [1 2 3]

You see PDL::DateTime, while it looks like designed to be used in an OO
manner, "use" it actually polute's the call's namespace. And to avoid the
pollution I had to explicitly do,

use PDL::DateTime ();

I think it's because PDL defaultly exports its functions. Can there be a
easy way to allow subclass developer to disable the default exports? I
don't find such a thing mentioned in the docs.


3. IMO this is not PDL's problem but Perl 5's problem: while a piddle is in
some sense similar to an Perl 5 native arrayref, the interfaces are quite
different between the two. For example you can't do $piddle[$index], and
you have to $piddle->dim(0) to get its first dimension's length. In case I
would like to mix the use of piddles and Perl native arrayrefs, I felt
difficult as there is not a duck typing interface, like Python's
numpy/native array behavior of [] and len(). Eventually I came up with a
solution that is to use Moose::Autobox to get the Perl native arrayrefs to
be OO-style, and I wrote a role that applies to PDL to provide some similar
methods as what's from Moose::Autobox::Array[3].

Not sure if there are Perl 6 people in the two mailgroups or not. I belive
this duck typing thing can be eaiser to implement in Perl 6, but is there
plan for PDL in Perl 6?


4. setbadtoval() does not work well with some PDL types. For example,

use 5.010;
use PDL;
my $x = indx(1,2,3)->setbadat(1);
say $x;    # [1 BAD 3]
$x->setbadtoval(100);
say $x;    # still [1 BAD 3]

Is this a bug or a feature?


[1] https://metacpan.org/pod/Chart::GGPlot
[2] https://metacpan.org/pod/Data::Frame::PDL
[3] https://metacpan.org/pod/Moose::Autobox::Array


Thanks,
Stephan
_______________________________________________
pdl-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pdl-general

Reply via email to