11
11
my $different = $vector->copy;
13
13
This module tracks which of the other L<Statistics::Basic> modules I<use> it.
14
That's it's primary purpose. It does have interpolation though...
14
That's it's primary purpose. Although, it does also have overloads to print the
15
vectors in a pretty fashion.
16
17
print "$vector\n"; # pretty printed
18
The full details are probably in the base module. If you have questions, just
25
The constructor can take a single array ref or a single
26
L<Statistics::Basic::Vector> as its argument. It can also take a list of
29
It returns a L<Statistics::Basic::Vector> object.
31
If given a vector object argument, this function will return the argument rather
32
than creating a new vector. This mainly used by the other L<Statistics::Basic>
33
modules to try to prevent duplicate calculations.
35
A vector's max size is set to the size of the argument or list on initialization.
37
Note: normally you'd use the L<vector()|Statistics::Basic/vector()> constructor,
38
rather than building these by hand using C<new()>.
42
Creates a new vector object with the same contents and size as this one and returns it.
44
my $v1 = vector(3,7,9);
45
my $v2 = $v1->copy(); # $v2 is a new object, separate vector
46
my $v3 = vector($v1); # $v3 is the same object as $v1
50
Insert new values into the vector. If the vector was already full (see
51
L</set_size()>), this will also shift oldest elements from the vector to
54
$vector->insert( 4, 3 ); # insert a 3 and a 4
56
This function returns the object itself, for chaining purposes.
58
=item B<append()> B<ginsert()>
60
Insert new values into the vector. If the vector was already full (see
61
L</set_size()>), these functions will grow the size of the vector to accommodate
62
the new values, rather than shifting things. C<ginsert()> does the same thing.
64
$vector->append( 4, 3 ); # append a 3 and a 4
66
This function returns the object itself, for chaining purposes.
70
C<query()> returns the contents of the vector either as a list or as an
73
my @copy_of_contents = $vector->query;
74
my $reference_to_contents = $vector->query;
76
Note that changing the C<$reference_to_contents> will not usefully affect the
77
contents of the vector itself, but it will adversely affect any computations
78
based on the vector. If you need to change the contents of a vector in a
79
special way, use a L<Statistics::Basic::ComputedVector> object instead.
81
Keeping C<$reference_to_contents> available long term should work acceptably
82
(since it refers to the vector contents itself).
84
=item B<query_filled()>
86
Returns true when the vector is the same size as the max size set by
87
L</set_size()>. This function isn't useful unless operating under the effects
88
of the L<nofill|Statistics::Basic/nofill> setting.
92
Returns the current number of elements in the vector object (not the size set
93
with L</set_size()>). This is almost never false unless you're using the
94
L<nofill|Statistics::Basic/nofill> setting.
98
Sets the max size of the vector.
100
my $v1 = vector(1,2,3);
101
$v1->set_size(7); # [0, 0, 0, 0, 1, 2, 3]
103
Unless L<nofill|Statistics::Basic/nofill> is set, the vector will be
104
filled with C<0>s (assuming the vector wouldn't otherwise be full) on the oldest
105
side of the vector (so an insert will push off one of the filled-zeros).
107
This function returns the object itself, for chaining purposes.
109
my $v1 = vector(2 .. 5)->set_size(5);
112
=item B<set_vector()>
114
Given a vector or array ref, this will set the contents (and size) of the input
115
vector to match the argument. If given a vector object argument, this will make
116
the two vectors match, while still remaining separate objects.
118
my $v1 = vector(3,7,9);
119
my $v2 = vector()->set_vector($v1);
120
my $v3 = vector($v1); # $v3 is the same object as $v1
122
This function returns the object itself, for chaining purposes.
128
This object is overloaded. It tries to return an appropriate string for the
129
vector and raises errors in numeric context.
131
In boolean context, this object is always true (even when empty).