~ubuntu-branches/ubuntu/natty/libstatistics-basic-perl/natty

« back to all changes in this revision

Viewing changes to lib/Statistics/Basic/Vector.pod

  • Committer: Bazaar Package Importer
  • Author(s): Ryan Niebur, Nathan Handler, Ryan Niebur
  • Date: 2009-07-01 20:22:06 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 karmic)
  • Revision ID: james.westby@ubuntu.com-20090701202206-0co1izn0pj047x4i
Tags: 1.6600-1
[ Nathan Handler ]
* debian/watch: Update to ignore development releases.

[ Ryan Niebur ]
* New upstream release
* Debian Policy 3.8.2
* enable author tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
=head1 NAME
2
2
 
3
 
Statistics::Basic::Vector - a class for handling arrays of numbers
 
3
Statistics::Basic::Vector - a class for handling lists of numbers
4
4
 
5
5
=head1 SYNOPSIS
6
6
 
11
11
    my $different   = $vector->copy;
12
12
 
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.
15
16
 
16
17
    print "$vector\n"; # pretty printed
17
18
 
18
 
The full details are probably in the base module.  If you have questions, just
19
 
let me know.
 
19
=head1 METHODS
 
20
 
 
21
=over 4
 
22
 
 
23
=item B<new()>
 
24
 
 
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
 
27
values.
 
28
 
 
29
It returns a L<Statistics::Basic::Vector> object.
 
30
 
 
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.
 
34
 
 
35
A vector's max size is set to the size of the argument or list on initialization.
 
36
 
 
37
Note: normally you'd use the L<vector()|Statistics::Basic/vector()> constructor,
 
38
rather than building these by hand using C<new()>.
 
39
 
 
40
=item B<copy()>
 
41
 
 
42
Creates a new vector object with the same contents and size as this one and returns it.
 
43
 
 
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
 
47
 
 
48
=item B<insert()>
 
49
 
 
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
 
52
compensate.
 
53
 
 
54
    $vector->insert( 4, 3 ); # insert a 3 and a 4
 
55
 
 
56
This function returns the object itself, for chaining purposes.
 
57
 
 
58
=item B<append()> B<ginsert()>
 
59
 
 
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.
 
63
 
 
64
    $vector->append( 4, 3 ); # append a 3 and a 4
 
65
 
 
66
This function returns the object itself, for chaining purposes.
 
67
 
 
68
=item B<query()>
 
69
 
 
70
C<query()> returns the contents of the vector either as a list or as an
 
71
arrayref.
 
72
 
 
73
    my @copy_of_contents      = $vector->query;
 
74
    my $reference_to_contents = $vector->query;
 
75
 
 
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.
 
80
 
 
81
Keeping C<$reference_to_contents> available long term should work acceptably
 
82
(since it refers to the vector contents itself).
 
83
 
 
84
=item B<query_filled()>
 
85
 
 
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.
 
89
 
 
90
=item B<query_size()>
 
91
 
 
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.
 
95
 
 
96
=item B<set_size()>
 
97
 
 
98
Sets the max size of the vector.
 
99
 
 
100
    my $v1 = vector(1,2,3);
 
101
       $v1->set_size(7); # [0, 0, 0, 0, 1, 2, 3]
 
102
 
 
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).
 
106
 
 
107
This function returns the object itself, for chaining purposes.
 
108
 
 
109
    my $v1 = vector(2 .. 5)->set_size(5);
 
110
    # [0, 2, 3, 4, 5]
 
111
 
 
112
=item B<set_vector()>
 
113
 
 
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.
 
117
 
 
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
 
121
 
 
122
This function returns the object itself, for chaining purposes.
 
123
 
 
124
=back
 
125
 
 
126
=head1 OVERLOADS
 
127
 
 
128
This object is overloaded.  It tries to return an appropriate string for the
 
129
vector and raises errors in numeric context.
 
130
 
 
131
In boolean context, this object is always true (even when empty).
20
132
 
21
133
=head1 AUTHOR
22
134