NAME

PDL::CCS::Functions - Useful perl-level functions for PDL::CCS

SYNOPSIS

use PDL;
use PDL::CCS::Functions;

##---------------------------------------------------------------------
## ... stuff happens

Decoding

ccs_pointerlen

Signature: (int ptr(N+1); int len(N))

Get number of non-missing values for each axis value from a CCS-encoded offset pointer vector $ptr().

ccs_decode

Signature: (int whichnd(Ndims,Nnz); nzvals(Nnz); missing(); \@Dims; [o]a(@Dims))

Decode a CCS-encoded matrix (no dataflow).

Scalar Operations

Scalar operations can be performed in parallel directly on $nzvals (and if applicable on $missing as well):

$c = 42;

$nzvals2 = $nzvals  + $c;        $missing2 = $missing  + $c;
$nzvals2 = $nzvals  - $c;        $missing2 = $missing  - $c;
$nzvals2 = $nzvals  * $c;        $missing2 = $missing  * $c;
$nzvals2 = $nzvals  / $c;        $missing2 = $missing  / $c;

$nzvals2 = $nzvals ** $c;        $missing2 = $missing ** $c;
$nzvals2 = log($nzvals);         $missing2 = log($missing);
$nzvals2 = exp($nzvals);         $missing2 = exp(missing);

$nzvals2 = $nzvals->and2($c,0);  $missing2 = $missing->and($c,0);
$nzvals2 = $nzvals->or2($c,0);   $missing2 = $missing->or2($c,0);
$nzvals2 = $nzvals->not();       $missing2 = $missing->not();

Nothing prevents scalar operations from producing new "missing" values (e.g. $nzvals*0), so you might want to re-encode your compressed data after applying the operation.

Vector Operations

ccs_OP_vector_mia

Signature: (int whichDimV(Nnz); nzvals(Nnz); vec(V); [o]nzvals_out(Nnz))

A number of row- and column-vector operations may be performed directly on encoded Nd-PDLs, without the need for decoding to a (potentially huge) dense temporary. These operations assume that "missing" values are annihilators with respect to the operation in question, i.e. that it holds for all $x in $vec that:

($missing __OP__ $x) == $missing

This is in line with the usual PDL semantics if your $missing value is BAD, but may produce unexpected results when e.g. adding a vector to a sparse PDL with $missing==0. If you really need to do something like the latter, then you're probably better off decoding to a dense PDL anyway.

Predefined function names for encoded-PDL vector operations are all of the form: ccs_${OPNAME}_ma, where ${OPNAME} is the base name of the operation:

plus       ##-- addition
minus      ##-- subtraction
mult       ##-- multiplication (NOT matrix-multiplication)
divide     ##-- division
modulo     ##-- modulo
power      ##-- potentiation

gt         ##-- greater-than
ge         ##-- greater-than-or-equal
lt         ##-- less-than
le         ##-- less-than-or-equal
eq         ##-- equality
ne         ##-- inequality
spaceship  ##-- 3-way comparison

and2       ##-- binary AND
or2        ##-- binary OR
xor        ##-- binary XOR
shiftleft  ##-- left-shift
shiftright ##-- right-shift

\&CODE = ccs_binop_vector_mia($opName, \&PDLCODE);

Returns a generic vector-operation subroutine which reports errors as $opName and uses \&PDLCODE to perform underlying computation.