Statistics::Basic::Vector(3pm) | User Contributed Perl Documentation | Statistics::Basic::Vector(3pm) |
Statistics::Basic::Vector - a class for handling lists of numbers
Invoke it this way:
my $vector = vector(1,2,3); my $same_vector = vector($vector); my $different = $vector->copy;
This module tracks which of the other Statistics::Basic modules use it. That's it's primary purpose. Although, it does also have overloads to print the vectors in a pretty fashion.
print "$vector\n"; # pretty printed
It returns a Statistics::Basic::Vector object.
If given a vector object argument, this function will return the argument rather than creating a new vector. This mainly used by the other Statistics::Basic modules to try to prevent duplicate calculations.
A vector's max size is set to the size of the argument or list on initialization.
Note: normally you'd use the vector() constructor, rather than building these by hand using "new()".
my $v1 = vector(3,7,9); my $v2 = $v1->copy(); # $v2 is a new object, separate vector my $v3 = vector($v1); # $v3 is the same object as $v1
$vector->insert( 4, 3 ); # insert a 3 and a 4
This function returns the object itself, for chaining purposes.
$vector->append( 4, 3 ); # append a 3 and a 4
This function returns the object itself, for chaining purposes.
my @copy_of_contents = $vector->query; my $reference_to_contents = $vector->query;
Note that changing the $reference_to_contents will not usefully affect the contents of the vector itself, but it will adversely affect any computations based on the vector. If you need to change the contents of a vector in a special way, use a Statistics::Basic::ComputedVector object instead.
Keeping $reference_to_contents available long term should work acceptably (since it refers to the vector contents itself).
my $v1 = vector(1,2,3); $v1->set_size(7); # [0, 0, 0, 0, 1, 2, 3]
Unless nofill is set, the vector will be filled with 0s (assuming the vector wouldn't otherwise be full) on the oldest side of the vector (so an insert will push off one of the filled-zeros).
This function returns the object itself, for chaining purposes.
my $v1 = vector(2 .. 5)->set_size(5); # [0, 2, 3, 4, 5]
my $v1 = vector(3,7,9); my $v2 = vector()->set_vector($v1); my $v3 = vector($v1); # $v3 is the same object as $v1
This function returns the object itself, for chaining purposes.
This object is overloaded. It tries to return an appropriate string for the vector and raises errors in numeric context.
In boolean context, this object is always true (even when empty).
Paul Miller "<jettero@cpan.org>"
Copyright 2012 Paul Miller -- Licensed under the LGPL
perl(1), Statistics::Basic
2020-12-29 | perl v5.32.0 |