API2/Matrix.pm

filter: Statementstmt 91.8% 45 / 49 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 4 totaltotal 84.1% 53 / 63 SCAR 23.2
CC
10
Cov
89%
multiply
4.1
transpose
4.0
new
3.1
CRAP 10.1
« API2/Resource/ColorSpace/Indexed/Hue.pm ↑ Summary API2/Resource/ColorSpace/Indexed/ACTFile.pm »
1 package PDF::API2::Matrix;
2  
3 38 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 38 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 38 our $VERSION = '2.044'; # VERSION
8  
9 sub new {
10 132 ▶ my $type = shift();
Subroutine new: called CC=3 SCAR=11.4
Pod undocumented
11 132 my $self = [];
12 132 my $col_count = scalar(@{$_[0]});
13 132 foreach my $row (@_) {
14 396 ▶ unless (scalar(@$row) == $col_count) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$row == $col_count) 0 396 396
15 0 carp 'Inconsistent column count in matrix';
16 0 return;
17 }
18 396 push @$self, [@$row];
19 }
20  
21 132 return bless($self, $type);
22 }
23  
24 sub transpose {
25 39 ▶ my $self = shift();
Subroutine transpose: called CC=4 SCAR=13.9
Pod undocumented
26 39 my @result;
27 my $m;
28  
29 39 for my $col (@{$self->[0]}) {
30 117 push @result, [];
31 }
32 39 for my $row (@$self) {
33 117 $m = 0;
34 117 for my $col (@$row) {
35 351 push @{$result[$m++]}, $col;
36 }
37 }
38  
39 39 return PDF::API2::Matrix->new(@result);
40 }
41  
42 sub vector_product {
43 351 ▶ my ($a, $b) = @_;
Subroutine vector_product: called CC=2 SCAR=6.9
Pod undocumented
44 351 my $result = 0;
45  
46 351 for my $i (0 .. $#{$a}) {
47 1053 $result += $a->[$i] * $b->[$i];
48 }
49  
50 351 return $result;
51 }
52  
53 sub multiply {
54 39 ▶ my $self = shift();
Subroutine multiply: called CC=4 SCAR=14.1
Pod undocumented
55 39 my $other = shift->transpose();
56 39 my @result;
57  
58 39 ▶ unless ($#{$self->[0]} == $#{$other->[0]}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($#{$$self[0];} == $#{$$other[0];}) 0 39 39
59 0 carp 'Mismatched dimensions in matrix multiplication';
60 0 return;
61 }
62 39 for my $row (@$self) {
63 117 my $result_col = [];
64 117 for my $col (@$other) {
65 351 push @$result_col, vector_product($row, $col);
66 }
67 117 push @result, $result_col;
68 }
69  
70 39 return PDF::API2::Matrix->new(@result);
71 }
72  
73 38 1;
« API2/Resource/ColorSpace/Indexed/Hue.pm ↑ Summary API2/Resource/ColorSpace/Indexed/ACTFile.pm »