Statis...dVector(3pm)
๐ฆ Statis...dVector(3pm) โ like, the whole vibe ๐
okay bestie, sit down, hydrate, and let's talk about a page from the User Contributed Perl Documentation โ it's called Statis...dVector(3pm) and it's genuinely so good. this is your girl explaining filtered vectors like we're texting at 1am. no cap. ๐
โจ NAME โจ
Statistics::Basic::ComputedVector โ a whole class dedicated to computing filtered vectors. it's giving "vector but make it bespoke." ๐
๐ธ SYNOPSIS ๐ธ
so here's how you summon it, fr fr:
my $vector = vector(1,2,3);
my $computed = computed($vector)->set_filter(sub{
# NOTE: only interested in even numbers:
grep { !($_ % 2) } @_
});
# nearly the same, opposite order:
my $computed = computed(1,2,3)->set_filter(sub {map{$_+1}@_});
my $vector = $computed->query_vector;
see how the order can flip and it still eats? versatile icon behavior โจ
๐ METHODS ๐
new()
the constructor, obviously. it takes a single array ref OR a single Statistics::Basic::ComputedVector as its argument, and it hands you back a Statistics::Basic::ComputedVector object. slay.
if you pass it stuff that isn't Statistics::Basic::Vector objects, it'll build an appropriate vector object for you anyway โ and you can go grab it later with query_vector(). ๐โ๏ธ
ngl, normally you'd just use thecomputed()constructor instead of hand-building these withnew(). just saying. ๐
copy()
makes a brand new computed vector object that points at the same source vector and uses the same filter as this one. twin energy. ๐ซถ
my $v1 = vector(1,2,3);
my $c1 = computed($v1); $c1->set_filter(my $s = sub {});
my $copy1 = computed($v1); $copy1->set_filter($s);
my $copy2 = $c1->copy; # just like $c2, but in one step
but if what you actually want is a filtered version of a filtered vector, choose this form instead:
my $v1 = vector(1,2,3);
my $c1 = computed($v1); $c1->set_filter(sub {});
my $c2 = computed($c1); $c2->set_filter(sub {});
layers on layers, bestie. ๐ง
insert()
drops new values into the input vector. and if that vector was already full (peep set_size()), this will also shift the oldest elements out of the input vector to compensate. balance, babe. โ๏ธ
$computed->insert( 4, 3 ); # insert a 3 and a 4
heads up: continuing from theSYNOPSISexample, this would certainly insert a4and a3into the input vector, but the3wouldn't be returned from aquery()because it is odd. tragic. ๐
this function returns the object itself, for chaining purposes. yes queen, chain away. ๐
append() / ginsert()
same idea โ new values go into the input vector. but if the vector was already full (again: set_size()), these two will grow the size of the input vector to fit the new values, rather than shifting things out. expanding, not evicting. ๐ฑ
$computed->append( 4, 3 ); # append a 3 and a 4
same warning as before, no cap: from theSYNOPSISexample, this would certainly insert a4and a3into the input vector, but the3wouldn't be returned from aquery()because it is odd. ๐ญ
this function returns the object itself, for chaining purposes. ๐ฅ
query()
query() hands you the contents of the computed vector (after filtering), either as a list or as an arrayref. your choice, main character. ๐
my @copy_of_contents = $computed->query;
my $reference_to_contents = $computed->query;
okay so important: changing$reference_to_contentswill not usefully affect the contents of the vector itself, but it will adversely affect any computations based on the vector. so don't. if you need to change a vector's contents in a special way, use anotherStatistics::Basic::ComputedVectorobject instead. ๐ซ
keeping $reference_to_contents around long term should work acceptably, since it refers to the vector contents itself. phew. ๐
query_vector()
returns the input Statistics::Basic::Vector object. that's it, that's the whole job. ๐
query_filled()
returns true when the input vector is full (see query_filled() in Statistics::Basic::Vector). ngl this is of questionable usefulness on computed vectors, but it's provided for completeness (and internal package consistency). we love a completionist. ๐
query_size()
returns the current size of the computed vector. cute, quick, done. โจ
set_filter()
sets the filtering for the computed vector. it takes a single coderef argument โ all other arguments get straight-up ignored, no notes. the elements of the input vector get passed to your filter coderef in @_, and your ref should return the calculated elements of the computed vector as a list. ๐ฎ
my $vec = vector(1,2,3);
my $pow = computed($vec);
$pow->set_filter(sub { return map { $_ ** 2 } @_ })
and if you need more than one filter function? just concatenate them together using map or an anonymous sub:
$pow->set_filter(sub { return f1(f2(f3(f4(@_)))) });
this function returns the object itself, for chaining purposes. stack 'em up bestie. ๐
set_size()
sets the size of the input vector โ not the computed vector, because that would make little sense. ๐โโ๏ธ
this function returns the object itself, for chaining purposes. โญ
set_vector()
sets the contents of the input vector (again โ not the computed one). ๐
this function returns the object itself, for chaining purposes. ๐ฅ
๐ OVERLOADS ๐
this object is overloaded. it tries to return an appropriate string for the vector, and it raises errors in numeric context. so don't do math with it, babe. ๐ค
in boolean context, this object is always true (even when empty). yes, even then. iconic. ๐
๐ AUTHOR ๐
Paul Miller <jettero@cpan.org> โ legend behavior, honestly.
๐ธ COPYRIGHT ๐ธ
Copyright 2012 Paul Miller โ Licensed under the LGPL.
๐ฆ SEE ALSO ๐ฆ
perl(1)Statistics::BasicStatistics::Basic::Vector
and that's the whole page, bestie!! ๐ซถ this was Statis...dVector(3pm) from perl v5.36.0, dated 2022-11-19 โ yeah, vintage, but she still serves. go forth and compute your filtered vectors, you absolute icon. mwah. ๐โจ๐
๐ฆ where this page comes from
- debian bookworm: libstatistics-basic-perl 1.6611-3 ยท LGPL-2.1-only
- debian trixie: libstatistics-basic-perl 1.6611-3 ยท LGPL-2.1-only
- ubuntu noble: libstatistics-basic-perl 1.6611-3 ยท LGPL-2.1-only
- ubuntu resolute: libstatistics-basic-perl 1.6611-3 ยท LGPL-2.1-only
- ubuntu stonking: libstatistics-basic-perl 1.6611-3 ยท LGPL-2.1-only
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms