Perl Data Language
Encyclopedia
PDL is a set of array programming extensions to the Perl programming language
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...

.

PDL is an extension to Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...

 v5, intended for scientific and other data intensive programming tasks. Perl's data structures are intended for small to medium sized analysis tasks: they embody simple data structures and include considerable behind-the-scenes magic
Magic (programming)
In the context of computer programming, magic is an informal term for abstraction - it is used to describe code that handles complex tasks while hiding that complexity to present a simple interface. The term is somewhat tongue-in-cheek and carries good connotations, implying that the interface...

 for type conversion, variable size, and the like. Numerical tasks such as image processing
Image processing
In electrical engineering and computer science, image processing is any form of signal processing for which the input is an image, such as a photograph or video frame; the output of image processing may be either an image or, a set of characteristics or parameters related to the image...

 and computer modeling of physical systems require more structured data, and PDL supplies this need by including more traditional array constructs and additional syntax to describe vector processes. On a computer with both Perl and PDL installed, any Perl script can use the PDL functionality by declaring "use PDL;".

Like Perl, PDL is free software
Free software
Free software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...

.

Language design

PDL is a vectorized array programming
Array programming
In computer science, array programming languages generalize operations on scalars to apply transparently to vectors, matrices, and higher dimensional arrays....

 language: the expression syntax is a variation on standard mathematical vector notation, so that the user can combine and operate on large arrays with simple expressions. In this respect, PDL follows in the footsteps of the APL programming language
APL programming language
APL is an interactive array-oriented language and integrated development environment, which is available from a number of commercial and noncommercial vendors and for most computer platforms. It is based on a mathematical notation developed by Kenneth E...

, and it has been compared to commercial languages such as MATLAB
MATLAB
MATLAB is a numerical computing environment and fourth-generation programming language. Developed by MathWorks, MATLAB allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages,...

 and Interactive Data Language, and to other free languages such as NumPy and Octave. Unlike MATLAB and IDL, PDL allows great flexibility in indexing and vectorization: for example, if a subroutine normally operates on a 2-D matrix
Matrix (mathematics)
In mathematics, a matrix is a rectangular array of numbers, symbols, or expressions. The individual items in a matrix are called its elements or entries. An example of a matrix with six elements isMatrices of the same size can be added or subtracted element by element...

 array, passing it a 3-D data cube
Data cube
In computer programming contexts, a data cube is a three- dimensional array of values, commonly used to describe a time series of image data...

 will generally cause the same operation to happen to each 2-D layer of the cube.

PDL borrows from perl at least three basic types of program structure: imperative programming
Imperative programming
In computer science, imperative programming is a programming paradigm that describes computation in terms of statements that change a program state...

, functional programming
Functional programming
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state...

, and pipeline programming
Pipeline programming
When a programming language is originally designed without any syntax to nest function calls, pipeline programming is a simple syntax change to add it. The programmer connects notional program modules into a flow structure, by analogy to a physical pipeline carrying reaction products through a...

 forms may be combined. Subroutines may be loaded either via a built-in autoload
Autoload
In computer programming, autoloading is the capability of loading and linking portions of a program from mass storage automatically when needed, so that the programmer is not required to define or include those portions of the program explicitly...

 mechanism or via the usual Perl module mechanism.

As of early 2005, PDL-like functionality is being included in the Perl 6
Perl 6
Perl 6 is a major revision to the Perl programming language. It is still in development, as a specification from which several interpreter and compiler implementations are being written. It is introducing elements of many modern and historical languages. Perl 6 is intended to have many...

 language design.

Graphics

True to the glue language
Glue language
A glue language is a programming language used for connecting software components together.Examples of glue languages:* Unix Shell scripts * Windows NT type Shell scripts...

 roots of Perl, PDL borrows from several different modules for graphics and plotting support. NetPBM
Netpbm
Netpbm is an open source package of graphics programs and a programming library, used mainly in the Unix world. It is a highly portable package, working under many Unix platforms, Windows, Mac OS X, VMS, Amiga OS and others and is included in all major open source Unix-like operating system...

 provides
image file I/O (though FITS is supported natively). PLplot
PLplot
PLplot is a library of functions that are often used to make scientific plots in compiled languages such as C, C++, D, Fortran, Ada, OCaml and Java. PLplot can also be used interactively by interpreted languages such as Octave, Python, Perl and Tcl. The current version was written primarily by...

, PGPLOT
PGPLOT
PGPLOT is a device-independent graphics subroutine library written starting in 1983 by Tim Pearson, a professor at Caltech. PGPLOT is written mostly in FORTRAN with a modular output API that allows output to several dozen types of plotting device...

, and Karma modules are all supported for 2-D graphics and plotting applications, and an interface to OpenGL
OpenGL
OpenGL is a standard specification defining a cross-language, cross-platform API for writing applications that produce 2D and 3D computer graphics. The interface consists of over 250 different function calls which can be used to draw complex three-dimensional scenes from simple primitives. OpenGL...

 is available for 3-D plotting and rendering.

I/O

PDL provides facilities to read and write many open data formats, including JPEG
JPEG
In computing, JPEG . The degree of compression can be adjusted, allowing a selectable tradeoff between storage size and image quality. JPEG typically achieves 10:1 compression with little perceptible loss in image quality....

, PNG, GIF
GIF
The Graphics Interchange Format is a bitmap image format that was introduced by CompuServe in 1987 and has since come into widespread usage on the World Wide Web due to its wide support and portability....

, PPM
Portable pixmap
The phrase Netpbm format commonly refers to any or all of the members of a set of closely related graphics formats used and defined by the Netpbm project....

, MPEG, FITS
FITS
Flexible Image Transport System is a digital file format used to store, transmit, and manipulate scientific and other images. FITS is the most commonly used digital file format in astronomy...

, NetCDF
NetCDF
NetCDF is a set of software libraries and self-describing, machine-independent data formats that support the creation, access, and sharing of array-oriented scientific data. The project homepage is hosted by the Unidata program at the University Corporation for Atmospheric Research...

, GRIB
GRIB
GRIB is a mathematically concise data format commonly used in meteorology to store historical and forecast weather data...

, raw binary files, and delimited ASCII tables. PDL programmers can use the CPAN
CPAN
CPAN, the Comprehensive Perl Archive Network, is an archive of nearly 100,000 modules of software written in Perl, as well as documentation for it. It has a presence on the World Wide Web at and is mirrored worldwide at more than 200 locations...

 Perl I/O libraries to read and write data in hundreds of standard and niche file formats.

perldl

An installation of PDL usually comes with an interactive shell
Shell (computing)
A shell is a piece of software that provides an interface for users of an operating system which provides access to the services of a kernel. However, the term is also applied very loosely to applications and may include any software that is "built around" a particular component, such as web...

 known as perldl, which can be used to perform simple calculations without requiring the user to create a perl program file. A typical session of perldl would look something like the following:

perldl> $x = pdl [[1, 2], [3, 4]];

perldl> $y = pdl [[5, 6, 7], [8, 9, 0]];

perldl> $z = $x x $y;

perldl> p $z;

[
[21 24 7]
[47 54 21]
]

The commands used in the shell are perl statements that can be used in a program with PDL module included. x is an overloaded operator for matrix multiplication, and p in the last command is a shortcut for print.

Implementation

The core of PDL is written in C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

. Most of the functionality is written in PP, a PDL-specific metalanguage that handles the vectorization of simple C snippets and interfaces them with the perl host language via Perl's XS
XS (Perl)
XS is an interface through which a Perl program can call a C or C++ language subroutine. The letters stand for eXternal Subroutine, or xsub, where external means external to Perl, i.e...

 compiler. Some modules are written in FORTRAN
Fortran
Fortran is a general-purpose, procedural, imperative programming language that is especially suited to numeric computation and scientific computing...

, with a C/PP interface layer. Many of the supplied functions are written in PDL itself. PP is available to the user to write C-language extensions to PDL. There is also an Inline module (Inline::Pdlpp) that allows PP function definitions to be inserted directly into a perl script; the relevant code is low-level compiled and made available as a Perl subroutine.

The PDL API uses the basic Perl 5 object-oriented functionality: PDL defines a new type of perl scalar object (eponym
Eponym
An eponym is the name of a person or thing, whether real or fictitious, after which a particular place, tribe, era, discovery, or other item is named or thought to be named...

ously called a "PDL", pronounced "piddle") that acts as a Perl scalar, but that contains a conventional typed
Data type
In computer programming, a data type is a classification identifying one of various types of data, such as floating-point, integer, or Boolean, that determines the possible values for that type; the operations that can be done on values of that type; the meaning of the data; and the way values of...

 array
Array data type
In computer science, an array type is a data type that is meant to describe a collection of elements , each selected by one or more indices that can be computed at run time by the program. Such a collection is usually called an array variable, array value, or simply array...

 of numeric or character values. All of the standard Perl operators are overloaded so that they can be used on PDL objects transparently, and PDLs can be mixed-and-matched with normal Perl scalars. Several hundred object methods for operating on PDLs are supplied by the core modules.

See also


External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK