Given set of vectors $c, generate a vector $a with the number of occurrences of each element (where an "element" is a vector of length $M ocurring in $c), and a set of vectors $b containing the unique values. As for rle(), only the elements up to the first instance of 0 in $a should be considered.

Can be used together with clump() to run-length encode "values" of arbitrary dimensions. Can be used together with rotate(), cat(), append(), and qsortvec() to count N-grams over a 1d PDL.

Given a sorted list of vectors $v, generate a vector $k containing locally unique keys for the elements of $v (where an "element" is a vector of length $M ocurring in $v).

Note that the keys returned in $k are only unique over a run of a single vector in $v, so that each unique vector in $v has at least one 0 (zero) index in $k associated with it. If you need global keys, see enumvecg().

enumvec does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

Given a sorted list of vectors $v, generate a vector $k containing globally unique keys for the elements of $v (where an "element" is a vector of length $M ocurring in $v). Basically does the same thing as:

$k = $v->vsearchvec($v->uniqvec);

... but somewhat more efficiently.

enumvecg does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

Given a vector of $c() of concatenated variable-length, variable-offset subsequences, generate a vector $a containing the length of each subsequence and a vector $b containg the subsequence offsets. As for rle(), only the elements up to the first instance of 0 in $a should be considered.

See also PDL::Slices::rle.

rleseq does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

Returns for each row-vector in $find the index along dimension N of the least row vector of $which greater or equal to it. $which should be sorted in increasing order. If the value of $find is larger than any member of $which, the index to the last element of $which is returned.

See also: PDL::Primitive::vsearch().

vsearchvec does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

The following functions are provided for lexicographic sorting of vectors, rsp. axis indices. Note that vv_qsortvec() is functionally identical to the builtin PDL function qsortvec(), but also that the latter is broken in the stock PDL-2.4.3 distribution. The version included here includes Chris Marshall's "uniqsortvec" patch, which is available here:

Set-difference ($a() \ $b()) of two vector-valued PDLs. Input PDLs $a() and $b() MUST be sorted in lexicographic order. On return, $nc() holds the actual number of vector-values in the computed vector set.

In scalar context, slices $c() to the actual number of elements in the output vector set and returns the sliced PDL.

vv_setdiff does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

The following functions are provided for set operations on flat sorted PDLs with unique values. They may be more efficient to compute than the corresponding implenentations via PDL::Primitive::setops().

Intersection of two flat sorted unique-valued PDLs. Input PDLs $a() and $b() MUST be sorted in lexicographic order and contain no duplicates. On return, $nc() holds the actual number of values in the intersection.

In scalar context, reshapes $c() to the actual number of elements in the intersection and returns it.

v_intersect does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

Set-difference ($a() \ $b()) of two flat sorted unique-valued PDLs. Input PDLs $a() and $b() MUST be sorted in lexicographic order and contain no duplicate values. On return, $nc() holds the actual number of values in the computed vector set.

In scalar context, reshapes $c() to the actual number of elements in the difference set and returns it.

v_setdiff does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

... but should be must faster to compute, and avoids allocating potentially large temporaries for the vector magnitudes. Output values in $vcos() are cosine similarities in the range [-1,1], except for zero-magnitude vectors which will result in NaN values in $vcos().

You can use PDL threading to batch-compute distances for multiple $b() vectors simultaneously:

vv_vcos() will set the bad status flag on the output piddle $vcos() if it is set on either of the input piddles $a() or $b(), but BAD values will otherwise be ignored for computing the cosine similary.

Code for rlevec() and rldvec() derived from the PDL builtin functions rle() and rld() in $PDL_SRC_ROOT/Basic/Slices/slices.pd

Code for vv_qsortvec() copied nearly verbatim from the builtin PDL functions in $PDL_SRC_ROOT/Basic/Ufunc/ufunc.pd, with Chris Marshall's "uniqsortvec" patch. Code for vv_qsortveci() based on the same.

Code for qsortvec() copyright (C) Tuomas J. Lukka 1997. Contributions by Christian Soeller (c.soeller@auckland.ac.nz) and Karl Glazebrook (kgb@aaoepp.aao.gov.au). 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.