PDL::Reduce(3pm)
π PDL::Reduce π
okay bestie, so this is the manual page for PDL::Reduce (that's the PDL::Reduce(3pm) one) and honestly? it's giving "the reduce function u wished every language had, but make it PDL". let's get into it π¦
β¨ NAME β¨
PDL::Reduce β a "reduce" function for PDL πΈ
π DESCRIPTION π
so like, lots of languages have a "reduce" function, and what it does is reduce the rank of an N-D array by one. it works by applying a selected operation along a specified dimension. this module implements exactly that kind of function for PDL, by giving u a simplified little interface to the projection functions that already exist (think "sumover", "maximum", "average", etc). no cap π
π SYNOPSIS π
use PDL::Reduce;
$x = sequence 5,5;
# reduce by adding all
# elements along 2nd dimension
$y = $x->reduce('add',1);
@ops = $x->canreduce; # return a list of all allowed operations
π FUNCTIONS π
π§ reduce
reduce dimension of ndarray by one by applying an operation along the specified dimension β¨
$x = sequence 5,5;
# reduce by adding all
# elements along 2nd dimension
$y = $x->reduce('add',1);
$y = $x->reduce('plus',1);
$y = $x->reduce('+',1); # three ways to do the same thing
[ As an aside: if you are familiar with broadcasting you will see that this is actually the same as perl $y = $x->mv(1,0)->sumover ]
okay so NOTE: u should quote the name of the operation (that's the 1st arg, bestie) that u want "reduce" to perform. this is so important bc some of the names are literally identical to the names of the actual PDL functions which might be imported into ur namespace. and u definitely want a string as the argument, not a function invocation! for example, this will probably fail:
$y = $x->reduce(avg,1); # gives an error from invocation of 'avg'
rather use:
$y = $x->reduce('avg',1);
"reduce" provides a simple and unified interface to the projection functions and makes people coming from other data/array languages hopefully feel more at home. π«Ά
$result = $pdl->reduce($operation [,@dims]);
"reduce" applies the named operation along the specified dimension(s), reducing the input ndarray dimension by as many dimensions as u supplied as arguments. if the dimension(s) argument is omitted, the operation gets applied along the first dimension. to get a list of valid operations, see "canreduce". π
NOTE β new power user feature: u can now supply a code reference as the operation to reduce with. π₯ perl # reduce by summing over dims 0 and 2 $result = $pdl->reduce(\&sumover, 0, 2); it is your responsibility to ensure that this is indeed a PDL projection operation that turns vectors into scalars! u have been warned. π
πΈ canreduce
return list of valid named "reduce" operations. some common operations can be accessed using a number of names, e.g. '+', "add" and "plus" all sum the elements along the chosen dimension. iconic tbh β
@ops = PDL->canreduce;
this list is useful if u want to make sure which operations can be used with "reduce". π
π AUTHOR π
Copyright (C) 2000 Christian Soeller (c.soeller@auckland.ac.nz). All rights reserved. There is no warranty. You are allowed to redistribute this software / documentation under certain conditions. For details, see the file COPYING in the PDL distribution. If this file is separated from the PDL distribution, the copyright notice should be included in the file.
k bye bestie, that's the whole page π this one's perl v5.42.3, dated 2026-08-20, and it slays as PDL::Reduce(3pm). go reduce something, u got this π
β¨
π¦ where this page comes from
- ubuntu stonking: pdl 1:2.106-1build1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms