PDL::Lite, NiceSlice and OO interface is very good.

I am using PDL. I become to know PDL can write clean code than I had expected. PDL::Lite, NiceSlice and OO interface is good.

PDL have PDL::Lite module. This module don't import any functions to current name space. and piddle(PDL varialbe) can call many function as method call.

The following are example codes.

use strict;
use warnings;

use PDL::Lite;
use PDL::NiceSlice;

# Create data
my $nums = pdl [2, 4, 7];

# Output data
print $nums->at(0) . "\n";
print $nums->at(1) . "\n";

# Get PDL varaible
my $pdl_first = $nums(0);
my $pdl_second = $nums(1);

# Assignment
$nums(0) .= 5;

# Get PDL variable which contains multiple elements
my $pdl_parts = $nums(1:2);

# Assignment multiple values to PDL variable
$nums(1:2) .= 8;

print $nums . "\n";

And PDL can call many functions as method from PDL variable.

use PDL::Lite;

# Create data
my $nums = pdl [4, 4, 2, 2, 2, 7];

# Max
my $max = $nums->max;

# Min
my $min = $nums->min;

# Total
my $total = $nums->sum;

# Initialize 0
my $data_zeros = pdl->zeros(2, 3);

# Initialize 0~19
my $data_seq = pdl->sequence(20);

In formal documentation, function style is used in many examples. but you can use OO style if you like OO.

2 Comments

Adding a module that is fragile and concise (PDL::NiceSlice, which is a source filter), while adding another that is robust and verbose (PDL::Lite, which makes you write a bunch of useless arrows), seems pointless.

Leave a comment

About Yuki Kimoto

user-pic I'm Perl Programmer. I LOVE Perl. I want to contribute Perl community and Perl users.