1Statistics::Basic::CompUusteerdVCeocnttorri(b3u)ted PerlStDaotciusmteinctsa:t:iBoansic::ComputedVector(3)
2
3
4

NAME

6       Statistics::Basic::ComputedVector - a class for computing filtered
7       vectors
8

SYNOPSIS

10       Invoke it this way:
11
12           my $vector   = vector(1,2,3);
13           my $computed = computed($vector)->set_filter(sub{
14               # NOTE: only interested in even numbers:
15               grep { !($_ % 2) } @_
16           });
17
18           # nearly the same, opposite order:
19
20           my $computed = computed(1,2,3)->set_filter(sub {map{$_+1}@_});
21           my $vector   = $computed->query_vector;
22

METHODS

24       new()
25           The constructor takes a single array ref or a single
26           Statistics::Basic::ComputedVector as its argument.  It returns a
27           Statistics::Basic::ComputedVector object.
28
29           If passed arguments other than Statistics::Basic::Vector objects,
30           the constructor will built an appropriate vector object -- which
31           can be queried with "query_vector()"
32
33           Note: normally you'd use the computed() constructor, rather than
34           building these by hand using "new()".
35
36       copy()
37           Creates a new computed vector object referring to the same source
38           vector and using the same filter as this one.
39
40               my $v1 = vector(1,2,3);
41               my $c1 = computed($v1); $c1->set_filter(my $s = sub {});
42
43               my $copy1 = computed($v1); $copy1->set_filter($s);
44               my $copy2 = $c1->copy; # just like $c2, but in one step
45
46           To instead create a filtered version of a filtered vector, choose
47           this form:
48
49               my $v1 = vector(1,2,3);
50               my $c1 = computed($v1); $c1->set_filter(sub {});
51               my $c2 = computed($c1); $c2->set_filter(sub {});
52
53       insert()
54           Insert new values into the input vector.  If the vector was already
55           full (see "set_size()"), this will also shift oldest elements from
56           the input vector to compensate.
57
58               $computed->insert( 4, 3 ); # insert a 3 and a 4
59
60           Note that continuing from the "SYNOPSIS" example, this would
61           certainly insert a 4 and a 3 into the input vector, but the 3
62           wouldn't be returned from a "query()" because it is odd.
63
64           This function returns the object itself, for chaining purposes.
65
66       append() ginsert()
67           Insert new values into the input vector.  If the vector was already
68           full (see "set_size()"), these functions will grow the size of the
69           input vector to accommodate the new values, rather than shifting
70           things.
71
72               $computed->append( 4, 3 ); # append a 3 and a 4
73
74           Note that continuing from the "SYNOPSIS" example, this would
75           certainly insert a 4 and a 3 into the input vector, but the 3
76           wouldn't be returned from a "query()" because it is odd.
77
78           This function returns the object itself, for chaining purposes.
79
80       query()
81           "query()" returns the contents of the computed vector (after
82           filtering) either as a list or as an arrayref.
83
84               my @copy_of_contents      = $computed->query;
85               my $reference_to_contents = $computed->query;
86
87           Note that changing the $reference_to_contents will not usefully
88           affect the contents of the vector itself, but it will adversely
89           affect any computations based on the vector.  If you need to change
90           the contents of a vector in a special way, use another
91           Statistics::Basic::ComputedVector object instead.
92
93           Keeping $reference_to_contents available long term should work
94           acceptably (since it refers to the vector contents itself).
95
96       query_vector()
97           Return the input Statistics::Basic::Vector object.
98
99       query_filled()
100           This returns true when the input vector is full (see
101           "query_filled()" in Statistics::Basic::Vector).  This is of
102           questionable usefulness on computed vectors, but is provided for
103           completeness (and internal package consistency).
104
105       query_size()
106           Return the current size of the computed vector.
107
108       set_filter()
109           Set the filtering for the computed vector.  This function takes a
110           single coderef argument -- all other arguments will be ignored.
111           The elements of the input vector are passed to your filter coderef
112           in @_ and your ref should return the calculated elements of the
113           computed vector as a list.
114
115               my $vec = vector(1,2,3);
116               my $pow = computed($vec);
117                  $pow->set_filter(sub { return map { $_ ** 2 } @_ })
118
119           If you need to call more than one filter function, concatenate them
120           together using map or an anonymous sub.
121
122               $pow->set_filter(sub { return f1(f2(f3(f4(@_)))) });
123
124           This function returns the object itself, for chaining purposes.
125
126       set_size()
127           Set the size of the input vector (not the computed vector, that
128           would make little sense).
129
130           This function returns the object itself, for chaining purposes.
131
132       set_vector()
133           Set the contents of the input vector (not the computed one).
134
135           This function returns the object itself, for chaining purposes.
136

OVERLOADS

138       This object is overloaded.  It tries to return an appropriate string
139       for the vector and raises errors in numeric context.
140
141       In boolean context, this object is always true (even when empty).
142

AUTHOR

144       Paul Miller "<jettero@cpan.org>"
145
147       Copyright 2012 Paul Miller -- Licensed under the LGPL
148

SEE ALSO

150       perl(1), Statistics::Basic, Statistics::Basic::Vector
151
152
153
154perl v5.30.1                      2020-01-3S0tatistics::Basic::ComputedVector(3)
Impressum