BLAS/Legacy.pm untested

filter: Statementstmt 0.0% 0 / 75 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 12 totaltotal 0.0% 0 / 107 CC 2 SCAR 8.8
CC
2
Cov
0%
BEGIN
6.0
blas_dcopy
2.0
blas_dswap
2.0
CRAP 2.4
1 ## Math/BLAS/Legacy.pm --- original Level 1, 2, and 3 BLAS.
2  
3 # Copyright (C) 2010 Ralph Schleicher. All rights reserved.
4  
5 # This program is free software; you can redistribute it and/or
6 # modify it under the same terms as Perl itself.
7  
8 ## Code:
9  
10 package Math::BLAS::Legacy;
11  
12 use strict;
13 use warnings;
14 use Exporter qw(import);
15  
16 use Math::BLAS::Enum;
17 use Math::BLAS::PP;
18  
19 BEGIN
20 {
21 our $VERSION = '1.02';
22 our @EXPORT = ();
23 our @EXPORT_OK = ();
24 our %EXPORT_TAGS = ();
25  
26 # Named constants.
27 $EXPORT_TAGS{enum}
28 = [ @Math::BLAS::Enum::EXPORT ];
29 push (@EXPORT_OK, @{ $EXPORT_TAGS{enum} });
30 push (@EXPORT, @{ $EXPORT_TAGS{enum} });
31  
32 # Subroutines.
33 $EXPORT_TAGS{sub}
34 = [qw(blas_dcopy
35 blas_dswap
36 blas_dset
37 blas_dscal
38 blas_daxpy
39 blas_ddot
40 blas_dasum
41 blas_dnrm2
42 blas_idamax
43 blas_dgemv
44 blas_dgemm)];
45 push (@EXPORT_OK, @{ $EXPORT_TAGS{sub} });
46 push (@EXPORT, @{ $EXPORT_TAGS{sub} });
47  
48 # Define aliases.
49 if (1)
50 {
51 no strict 'refs';
52 my ($s, @bare) = ();
53  
54 foreach (@{ $EXPORT_TAGS{sub} })
55 {
56 ($s = $_) =~ s/\Ablas_//;
57  
58 *{$s} = \&{$_};
59 push (@bare, $s);
60 }
61  
62 $EXPORT_TAGS{bare} = [@bare];
63 push (@EXPORT_OK, @bare);
64 }
65  
66 $EXPORT_TAGS{all} = [ @EXPORT_OK ];
67 }
68  
69 ## Level 1.
70  
71 # Copy vector elements.
72 sub blas_dcopy ($$$$$$$)
73 {
74 my ($n, $x, $x_ind, $x_incr, $y, $y_ind, $y_incr) = @_;
75  
76 copy_d (int ($n),
77 $x,
78 int ($x_ind),
79 int ($x_incr),
80 $y,
81 int ($y_ind),
82 int ($y_incr));
83 }
84  
85 # Interchange vector elements.
86 sub blas_dswap ($$$$$$$)
87 {
88 my ($n, $x, $x_ind, $x_incr, $y, $y_ind, $y_incr) = @_;
89  
90 swap_d (int ($n),
91 $x,
92 int ($x_ind),
93 int ($x_incr),
94 $y,
95 int ($y_ind),
96 int ($y_incr));
97 }
98  
99 # Set vector elements to a constant.
100 sub blas_dset ($$$$$)
101 {
102 my ($n, $alpha, $x, $x_ind, $x_incr) = @_;
103  
104 $x_ind = int ($x_ind);
105 $x_incr = int ($x_incr);
106  
107 foreach (1 .. $n)
108 {
109 $$x[$x_ind] = $alpha;
110  
111 $x_ind += $x_incr;
112 }
113 }
114  
115 # Multiply vector elements by a constant.
116 sub blas_dscal ($$$$$)
117 {
118 my ($n, $alpha, $x, $x_ind, $x_incr) = @_;
119  
120 axpby_d (int ($n),
121 0,
122 undef,
123 0,
124 1,
125 $alpha,
126 $x,
127 int ($x_ind),
128 int ($x_incr));
129 }
130  
131 # Accumulate multiples of vector elements.
132 sub blas_daxpy ($$$$$$$$)
133 {
134 my ($n, $alpha, $x, $x_ind, $x_incr, $y, $y_ind, $y_incr) = @_;
135  
136 axpby_d (int ($n),
137 $alpha,
138 $x,
139 int ($x_ind),
140 int ($x_incr),
141 1,
142 $y,
143 int ($y_ind),
144 int ($y_incr));
145 }
146  
147 # Inner product.
148 sub blas_ddot ($$$$$$$)
149 {
150 my ($n, $x, $x_ind, $x_incr, $y, $y_ind, $y_incr) = @_;
151  
152 dot_d (int ($n),
153 1,
154 $x,
155 int ($x_ind),
156 int ($x_incr),
157 $y,
158 int ($y_ind),
159 int ($y_incr),
160 0,
161 0,
162 0);
163 }
164  
165 # Return sum of absolute values.
166 sub blas_dasum ($$$$)
167 {
168 my ($n, $x, $x_ind, $x_incr) = @_;
169  
170 norm_d (BLAS_ONE_NORM,
171 int ($n),
172 $x,
173 int ($x_ind),
174 int ($x_incr));
175 }
176  
177 # Return vector norm.
178 sub blas_dnrm2 ($$$$)
179 {
180 my ($n, $x, $x_ind, $x_incr) = @_;
181  
182 norm_d (BLAS_TWO_NORM,
183 int ($n),
184 $x,
185 int ($x_ind),
186 int ($x_incr));
187 }
188  
189 # Return index offset of first element having maximum absolute value.
190 sub blas_idamax ($$$$)
191 {
192 my ($n, $x, $x_ind, $x_incr) = @_;
193  
194 (amax_val_d (int ($n),
195 $x,
196 int ($x_ind),
197 int ($x_incr)))[0];
198 }
199  
200 ## Level 2.
201  
202 # General matrix/vector multiplication.
203 sub blas_dgemv ($$$$$$$$$$$$$$)
204 {
205 my ($a_op, $m, $n, $alpha, $a, $a_ind, $a_incr, $x, $x_ind, $x_incr, $beta, $y, $y_ind, $y_incr) = @_;
206  
207 gemv_d ($a_op,
208 int ($m),
209 int ($n),
210 $alpha,
211 $a,
212 int ($a_ind),
213 int ($a_incr),
214 $x,
215 int ($x_ind),
216 int ($x_incr),
217 $beta,
218 $y,
219 int ($y_ind),
220 int ($y_incr));
221 }
222  
223 ## Level 3.
224  
225 # General matrix/matrix multiplication.
226 sub blas_dgemm ($$$$$$$$$$$$$$$$)
227 {
228 my ($a_op, $b_op, $m, $n, $k, $alpha, $a, $a_ind, $a_incr, $b, $b_ind, $b_incr, $beta, $c, $c_ind, $c_incr) = @_;
229  
230 gemm_d ($a_op,
231 $b_op,
232 int ($m),
233 int ($n),
234 int ($k),
235 $alpha,
236 $a,
237 int ($a_ind),
238 int ($a_incr),
239 $b,
240 int ($b_ind),
241 int ($b_incr),
242 $beta,
243 $c,
244 int ($c_ind),
245 int ($c_incr));
246 }
247  
248 1;
249  
250 __END__