Ngrams/Utils.pm

filter: Statementstmt 100% 15 / 15 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 18 / 18 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Ngrams.pm ↑ Summary
1 #
2 # GENERATED WITH PDL::PP from ngutils.pd! Don't modify!
3 #
4 package PDL::Ngrams::Utils;
5  
6 4 our @EXPORT_OK = qw(ng_delimit ng_undelimit );
7 4 our %EXPORT_TAGS = (Func=>\@EXPORT_OK);
8  
9 4 ▶use PDL::Core;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use PDL::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use DynaLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 4 our $VERSION = '0.12';
15 4 our @ISA = ( 'PDL::Exporter','DynaLoader' );
16 4 push @PDL::Core::PP, __PACKAGE__;
17 4 bootstrap PDL::Ngrams::Utils $VERSION;
18  
19  
20  
21  
22  
23  
24  
25  
26 #line 16 "ngutils.pd"
27  
28 use strict;
29  
30 =pod
31  
32 =head1 NAME
33  
34 PDL::Ngrams::Utils - Basic N-Gram utilities for PDL: low-level utilities
35  
36 =head1 SYNOPSIS
37  
38 use PDL;
39 use PDL::Ngrams::Utils;
40  
41 ##---------------------------------------------------------------------
42 ## ... stuff happens
43  
44 =cut
45 #line 46 "Utils.pm"
46  
47  
48 =head1 FUNCTIONS
49  
50 =cut
51  
52  
53  
54  
55  
56 #line 68 "ngutils.pd"
57  
58 =pod
59  
60 =head1 Delimiter Insertion and Removal
61  
62 =cut
63 #line 64 "Utils.pm"
64  
65  
66 =head2 ng_delimit
67  
68 =for sig
69  
70 Signature: (toks(NToks); indx boffsets(NBlocks); delims(NDelims); [o]dtoks(NDToks))
71 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
72 float double ldouble)
73  
74 =for usage
75  
76 $dtoks = ng_delimit($toks, $boffsets, $delims);
77 ng_delimit($toks, $boffsets, $delims, $dtoks); # all arguments given
78 $dtoks = $toks->ng_delimit($boffsets, $delims); # method call
79 $toks->ng_delimit($boffsets, $delims, $dtoks);
80  
81 Add block-delimiters to a raw token vector
82  
83 Splices the vector $delims into the vector $toks starting at each index
84 listed in $boffsets, returning the result as $dtoks. Values in $boffsets
85 should be in the range [0..N-1].
86  
87 For consistency, it should be the case that:
88  
89 $NDToks == $NToks + $NBlocks * $NDelims
90  
91 =pod
92  
93 Broadcasts over its inputs.
94  
95 =for bad
96  
97 C<ng_delimit> does not process bad values.
98 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
99  
100 =cut
101  
102  
103  
104  
105 sub PDL::ng_delimit {
106 my ($toks,$boffsets,$delims,$dtoks,$ndtoks) = @_;
107 barf('Usage: ng_delimit(toks(NToks), indx boffsets(NBlocks), delims(NDelims), [o]dtoks(NDToks), ndtoks=>NDToks)')
108 if (grep {!defined($_)} ($toks,$boffsets,$delims));
109 ##
110 ##-- basic data
111 my @tokdims = $toks->dims;
112 my $NToks = shift(@tokdims);
113 my $NBlocks = $boffsets->dim(0);
114 my $NDelims = $delims->dim(0);
115 ##
116 ##-- $ndtoks: maybe compute number of delimiters+tokens
117 $ndtoks = $NToks + ($NBlocks * $NDelims)
118 if ((!defined($dtoks) || $dtoks->isempty) && (!defined($ndtoks) || $ndtoks <= 0));
119 ##
120 ##-- $dtoks: maybe allocate
121 $dtoks = $toks->zeroes($toks->type, $ndtoks,@tokdims)
122 if (!defined($dtoks) || $dtoks->isempty);
123 ##
124 ##-- underlying low-level call
125 &PDL::_ng_delimit_int($toks,$boffsets,$delims,$dtoks);
126 return $dtoks;
127 }
128  
129  
130  
131 *ng_delimit = \&PDL::ng_delimit;
132  
133  
134  
135  
136  
137  
138 =head2 ng_undelimit
139  
140 =for sig
141  
142 Signature: (dtoks(NDToks); indx boffsets(NBlocks); int NDelims(); [o]toks(NToks))
143 Types: (sbyte byte short ushort long ulong indx ulonglong longlong
144 float double ldouble)
145  
146 =for usage
147  
148 $toks = ng_undelimit($dtoks, $boffsets, $NDelims);
149 ng_undelimit($dtoks, $boffsets, $NDelims, $toks); # all arguments given
150 $toks = $dtoks->ng_undelimit($boffsets, $NDelims); # method call
151 $dtoks->ng_undelimit($boffsets, $NDelims, $toks);
152  
153 Remove block-delimiters from a delimited token vector.
154  
155 Removes chunks of length $delims from the vector $toks starting at each index
156 listed in $boffsets, returning the result as $toks. Values in $boffsets
157 should be in the range [0..N-1].
158  
159 =pod
160  
161 Broadcasts over its inputs.
162  
163 =for bad
164  
165 C<ng_undelimit> does not process bad values.
166 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
167  
168 =cut
169  
170  
171  
172  
173 sub PDL::ng_undelimit {
174 my ($dtoks,$boffsets,$NDelims,$toks) = @_;
175 barf('Usage: ng_delimit(dtoks(NDToks), indx boffsets(NBlocks), NDelims(), [o]toks(NToks))')
176 if (grep {!defined($_)} ($dtoks,$boffsets,$NDelims));
177 ##
178 ##-- $toks: maybe allocate
179 if (!defined($toks) || $toks->isempty) {
180 $NDelims = PDL->topdl($NDelims);
181 my @dtokdims = $dtoks->dims;
182 my $NDToks = shift(@dtokdims);
183 my $NBlocks = $boffsets->dim(0);
184 my $NToks = $NDToks - ($NDelims->max * $NBlocks);
185 $toks = zeroes($dtoks->type, $NToks,@dtokdims);
186 }
187 ##
188 ##-- underlying low-level call
189 &PDL::_ng_undelimit_int($dtoks,$boffsets,$NDelims, $toks);
190 return $toks;
191 }
192  
193  
194  
195 *ng_undelimit = \&PDL::ng_undelimit;
196  
197  
198  
199  
200  
201 #line 218 "ngutils.pd"
202  
203 ##---------------------------------------------------------------------
204 =pod
205  
206 =head1 ACKNOWLEDGEMENTS
207  
208 Perl by Larry Wall.
209  
210 PDL by Karl Glazebrook, Tuomas J. Lukka, Christian Soeller, and others.
211  
212 =cut
213  
214 ##----------------------------------------------------------------------
215 =pod
216  
217 =head1 KNOWN BUGS
218  
219 Probably many.
220  
221 =cut
222  
223 ##---------------------------------------------------------------------
224 =pod
225  
226 =head1 AUTHOR
227  
228 Bryan Jurish E<lt>moocow@cpan.orgE<gt>
229  
230 =head2 Copyright Policy
231  
232 Copyright (C) 2007-2022, Bryan Jurish. All rights reserved.
233  
234 This package is free software, and entirely without warranty.
235 You may redistribute it and/or modify it under the same terms
236 as Perl itself.
237  
238 =head1 SEE ALSO
239  
240 perl(1), PDL(3perl)
241  
242 =cut
243 #line 244 "Utils.pm"
244  
245 # Exit with OK status
246  
247 1;
« Ngrams.pm ↑ Summary