| 1 | package ICC::Support::ratfunc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = 0.10; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # revised 2016-10-26 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # Copyright © 2004-2018 by William B. Birkett | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # add development directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use lib 'lib'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # inherit from Shared | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use parent qw(ICC::Shared); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # enable static variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use feature 'state'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | =encoding utf-8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | This module implements a simple rational function ('ratfunc') transform for 3-channel data. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | The transform is explained in the document 'rational_function_color_transform.txt'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | The primary application is converting RGB camera/scanner data to XYZ. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | We often use a 3x4 matrix to do this, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | | a11, a12, a13, a14 | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | | a21, a22, a23, a24 | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | | a31, a32, a33, a34 | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | To use this matrix, we add a column containing '1' to the input data, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | [R, G, B] => [R, G, B, 1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | Then we use matrix multiplication to compute the XYZ values from these augmented RGB values. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | [X, Y, Z] = [3x4 matrix] x [R, G, B, 1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | If the camera or scanner has RGB spectral sensitivities derived from color matching functions (Luther-Ives condition), the accuracy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | of this simple transform will be excellent. However, the spectral sensitivity curves are not always optimal. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | We may be able to achieve slightly better results using rational functions. A rational function is the ratio of two polynomial | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | functions. We use extremely simple, linear functions of RGB. We extend the 3x4 matrix by adding three rows to get a 6x4 matrix, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | | a11, a12, a13, a14 | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | | a21, a22, a23, a24 | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | | a31, a32, a33, a34 | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | | a41, a42, a43, 1 | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | | a51, a52, a53, 1 | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | | a61, a62, a63, 1 | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | Now, when we multiply by the augmented RGB matrix, we get, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | [Xn, Yn, Zn, Xd, Yd, Zd] = [6x4 matrix] x [R, G, B, 1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | Then we reduce these values to ratios, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | [X, Y, Z] = [Xn/Xd, Yn/Yd, Zn/Zd] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | If the added coefficients, a41, a42, ... a63, are all zero, the denominators will all be 1, and the transform is the same as the 3x3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | matrix with offsets. If these coefficients are non-zero, the X, Y, Z functions will be non-linear, which may improve the accuracy of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | the transform. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | The advantage of this transform is that it provides some additional degrees of freedom compared to the 3x3 matrix. This allows us to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 'fix' some points to improve the reproduction of a particular original. The transform may have some curvature, but it is smooth and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | gradual, so congruence is maintained. This transform cannot improve the color quality of the sensor, but it can be used to fine tune | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | images. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | The object's matrix is compatible with the XS function 'ICC::Support::Image::ratfunc_transform_float'. The intention is to optimize | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | the matrix using the 'ratfunc.pm' object, then transform images using the XS function. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | The size of the object's matrix is always 6x4. If we attempt to make a larger matrix, an error occurs. If we supply a smaller matrix, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | the missing coefficients are those of the identity matrix. The identity matrix looks like this, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | | 1, 0, 0, 0 | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | | 0, 1, 0, 0 | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | | 0, 0, 1, 0 | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | | 0, 0, 0, 1 | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | | 0, 0, 0, 1 | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | | 0, 0, 0, 1 | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | For example, a 3x3 matrix will be copied to the first three rows and columns of the above identity matrix. In that case, the 'ratfunc' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | transform will be the same as the 'matf' transform (straight matrix multiplication). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # create new ratfunc object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # returns an empty object with no parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # hash keys are: ('header', 'matrix', 'offset') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # 'header' value is a hash reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # 'matrix' value is a 2D array reference -or- Math::Matrix object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # returns identity object with an empty hash ({}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # when the parameters are input and output arrays, the 'fit' method is called on the object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # parameter: () | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # parameter: ({}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # parameter: (ref_to_attribute_hash) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # parameter: (matf_object) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # parameters: (ref_to_input_array, ref_to_output_array) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # returns: (ref_to_object) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # get object class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | ▶ | my $class = shift(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=9 SCAR=38.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # create empty ratfunc object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | my $self = [ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | {}, # header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | [], # matrix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # local parameter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | my ($info); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # if there are parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # if one parameter, a hash reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if (@_ == 1 && ref($_[0]) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
@_ == 1 and ref $_[0] eq "HASH"
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1
ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # make new ratfunc object from attribute hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | _new_from_hash($self, shift()); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # if one parameter, a 'matf' object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | ▶ | } elsif (@_ == 1 && UNIVERSAL::isa(ref($_[0]), 'ICC::Profile::matf')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
@_ == 1 and UNIVERSAL::isa(ref $_[0], "ICC::Profile::matf")
MC/DC0%0/2
@_ == 1 and UNIVERSAL::isa(ref $_[0], "ICC::Profile::matf")
@_ == 1
UNIVERSAL::isa(ref $_[0], "ICC::Profile::matf")
Truth table0%0/3
A and B
A= @_ == 1B= UNIVERSAL::isa(ref $_[0], "ICC::Profile::matf")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # make new ratfunc object from 'matf' object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | _new_from_matf($self, shift()); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # if two or three parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | ▶ | } elsif (@_ == 2 || @_ == 3) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
@_ == 2 or @_ == 3
MC/DC0%0/2
@_ == 2 or @_ == 3
@_ == 2
@_ == 3
Truth table0%0/3
A or B
A= @_ == 2B= @_ == 3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # fit the object to data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | ($info = fit($self, @_)) && croak("\'fit\' routine failed with error $info"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | croak('\'ratfunc\' invalid parameter(s)'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # bless object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | bless($self, $class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | # return object reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | return($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # get/set reference to header hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # parameters: ([ref_to_new_hash]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # returns: (ref_to_hash) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | sub header { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # get object reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
header: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # if there are parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | # if one parameter, a hash reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | if (@_ == 1 && ref($_[0]) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ == 1 and ref $_[0] eq "HASH"
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1
ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # set header to new hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $self->[0] = {%{shift()}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | croak('\'header\' attribute must be a hash reference'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | # return reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | return($self->[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # get/set reference to matrix array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # parameters: ([ref_to_new_array]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # returns: (ref_to_array) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | sub matrix { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # get object reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
matrix: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # if there are parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # if one parameter, a reference to a 2-D array -or- Math::Matrix object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | if (@_ == 1 && ((ref($_[0]) eq 'ARRAY' && @{$_[0]} == grep {ref() eq 'ARRAY'} @{$_[0]}) || UNIVERSAL::isa($_[0], 'Math::Matrix'))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
@_ == 1 and ref $_[0] eq "ARRAY" && @{$_[0];} == grep({ref $_ eq "ARRAY";} @{$_[0];}) || UNIVERSAL::isa($_[0], "Math::Matrix")
ref $_[0] eq "ARRAY" and @{$_[0];} == grep({ref $_ eq "ARRAY";} @{$_[0];}) or UNIVERSAL::isa($_[0], "Math::Matrix")
ref $_[0] eq "ARRAY" and @{$_[0];} == grep({ref $_ eq "ARRAY";} @{$_[0];})
MC/DC0%0/4
@_ == 1 and ref $_[0] eq "ARRAY" && @{$_[0];} == grep({ref $_ eq "ARRAY";} @{$_[0];}) || UNIVERSAL::isa($_[0], "Math::Matrix")
@_ == 1
ref $_[0] eq "ARRAY"
@{$_[0];} == grep({ref $_ eq "ARRAY";} @{$_[0];})
UNIVERSAL::isa($_[0], "Math::Matrix")
Truth table0%0/6
A and B and C or D
A= @_ == 1B= ref $_[0] eq "ARRAY"C= @{$_[0];} == grep({ref $_ eq "ARRAY";} @{$_[0];})D= UNIVERSAL::isa($_[0], "Math::Matrix")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # verify number of rows | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | ($#{$_[0]} < 6) or croak('\'matrix\' array has more than 6 rows'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # make identity matrix (6x4) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | $self->[1] = bless([ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | [1, 0, 0, 0], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | [0, 1, 0, 0], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | [0, 0, 1, 0], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | [0, 0, 0, 1], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | [0, 0, 0, 1], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | [0, 0, 0, 1], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | ], 'Math::Matrix'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | # for each row | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | for my $i (0 .. $#{$_[0]}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # verify number of columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | ($#{$_[0]->[$i]} < 4) or croak('\'matrix\' array has more than 4 columns'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # for each column | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | for my $j (0 .. $#{$_[0]->[$i]}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # verify matrix element is a number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | (Scalar::Util::looks_like_number($_[0]->[$i][$j])) or croak('\'matrix\' element not numeric'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # copy matrix element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | $self->[1][$i][$j] = $_[0]->[$i][$j]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | # error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | croak('\'matrix\' attribute must be a 2-D array reference or Math::Matrix object'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | # return object reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | return($self->[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | # fit ratfunc object to data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # uses LAPACK dgels function to perform a least-squares fit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # fitting is done with or without offset, according to offset_flag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # input and output are 2D array references -or- Math::Matrix objects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | # parameters: (ref_to_input_array, ref_to_output_array, [offset_flag]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | # returns: (dgels_info_value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | sub fit { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | # get parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | my ($self, $in, $out, $oflag) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fit: not called CC=19 SCAR=59.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | # local variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | my ($info, $ab); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | # check if ICC::Support::Lapack module is loaded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | state $lapack = defined($INC{'ICC/Support/Lapack.pm'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | # verify ICC::Support::Lapack module is loaded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | ($lapack) or croak('\'fit\' method requires ICC::Support::Lapack module'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | # resolve offset flag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | $oflag = 0 if (! defined($oflag)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # verify input array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | (ref($in) eq 'ARRAY' && ref($in->[0]) eq 'ARRAY' && ! ref($in->[0][0])) || UNIVERSAL::isa($in, 'Math::Matrix') or croak('fit input not a 2-D array reference'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
ref $in eq "ARRAY" and ref $in->[0] eq "ARRAY" and not ref $in->[0][0] or UNIVERSAL::isa($in, "Math::Matrix")
ref $in eq "ARRAY" and ref $in->[0] eq "ARRAY" and not ref $in->[0][0]
ref $in eq "ARRAY" and ref $in->[0] eq "ARRAY"
MC/DC0%0/4
ref $in eq "ARRAY" and ref $in->[0] eq "ARRAY" and not ref $in->[0][0] or UNIVERSAL::isa($in, "Math::Matrix")
ref $in eq "ARRAY"
ref $in->[0] eq "ARRAY"
not ref $in->[0][0]
UNIVERSAL::isa($in, "Math::Matrix")
Truth table0%0/7
A and B and not(C) or D
A= ref $in eq "ARRAY"B= ref $in->[0] eq "ARRAY"C= not ref $in->[0][0]D= UNIVERSAL::isa($in, "Math::Matrix")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | # verify output array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | (ref($out) eq 'ARRAY' && ref($out->[0]) eq 'ARRAY' && ! ref($out->[0][0])) || UNIVERSAL::isa($out, 'Math::Matrix') or croak('fit output not a 2-D array reference'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
ref $out eq "ARRAY" and ref $out->[0] eq "ARRAY" and not ref $out->[0][0] or UNIVERSAL::isa($out, "Math::Matrix")
ref $out eq "ARRAY" and ref $out->[0] eq "ARRAY" and not ref $out->[0][0]
ref $out eq "ARRAY" and ref $out->[0] eq "ARRAY"
MC/DC0%0/4
ref $out eq "ARRAY" and ref $out->[0] eq "ARRAY" and not ref $out->[0][0] or UNIVERSAL::isa($out, "Math::Matrix")
ref $out eq "ARRAY"
ref $out->[0] eq "ARRAY"
not ref $out->[0][0]
UNIVERSAL::isa($out, "Math::Matrix")
Truth table0%0/7
A and B and not(C) or D
A= ref $out eq "ARRAY"B= ref $out->[0] eq "ARRAY"C= not ref $out->[0][0]D= UNIVERSAL::isa($out, "Math::Matrix")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # verify array dimensions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | ($#{$in} == $#{$out}) or croak('input and output arrays have different number of rows'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | ($#{$in->[0]} == 2) or croak('input samples must have 3 elements'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | ($#{$out->[0]} == 2) or croak('output samples must have 3 elements'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | # fit the matrix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ($info, $ab) = ICC::Support::Lapack::matf_fit($in, $out, $oflag); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | # check result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | carp('fit failed - bad parameter when calling dgels') if ($info < 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | carp('fit failed - A matrix not full rank') if ($info > 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # initialize matrix object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | $self->[1] = bless([], 'Math::Matrix'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # for each row | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | for my $i (0 .. 2) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # for each column | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | for my $j (0 .. 2) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # set matrix element (transposing) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | $self->[1][$i][$j] = $ab->[$j][$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | # set offset value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | $self->[1][$i][3] = $oflag ? $ab->[3][$i] : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | # set divisor row | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | $self->[1][$i + 3] = [0, 0, 0, 1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | # return info value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | return($info); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | # transform data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | # supported input types: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | # parameters: (list, [hash]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | # parameters: (vector, [hash]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | # parameters: (matrix, [hash]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # parameters: (Math::Matrix_object, [hash]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | # parameters: (structure, [hash]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | # returns: (same_type_as_input) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | sub transform { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | # set hash value (0 or 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | my $h = ref($_[-1]) eq 'HASH' ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
transform: not called CC=12 SCAR=50.5
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | # if input a 'Math::Matrix' object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | if (@_ == $h + 2 && UNIVERSAL::isa($_[1], 'Math::Matrix')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
@_ == $h + 2 and UNIVERSAL::isa($_[1], "Math::Matrix")
MC/DC0%0/2
@_ == $h + 2 and UNIVERSAL::isa($_[1], "Math::Matrix")
@_ == $h + 2
UNIVERSAL::isa($_[1], "Math::Matrix")
Truth table0%0/3
A and B
A= @_ == $h + 2B= UNIVERSAL::isa($_[1], "Math::Matrix")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | # call matrix transform | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | &_trans2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | # if input an array reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | ▶ | } elsif (@_ == $h + 2 && ref($_[1]) eq 'ARRAY') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
@_ == $h + 2 and ref $_[1] eq "ARRAY"
MC/DC0%0/2
@_ == $h + 2 and ref $_[1] eq "ARRAY"
@_ == $h + 2
ref $_[1] eq "ARRAY"
Truth table0%0/3
A and B
A= @_ == $h + 2B= ref $_[1] eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | # if array contains numbers (vector) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | if (! ref($_[1][0]) && @{$_[1]} == grep {Scalar::Util::looks_like_number($_)} @{$_[1]}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
not ref $_[1][0] and @{$_[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$_[1];})
MC/DC0%0/2
not ref $_[1][0] and @{$_[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$_[1];})
not ref $_[1][0]
@{$_[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$_[1];})
Truth table0%0/3
not(A) and B
A= not ref $_[1][0]B= @{$_[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$_[1];})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | # call vector transform | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | &_trans1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | # if array contains vectors (2-D array) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | } elsif (ref($_[1][0]) eq 'ARRAY' && @{$_[1]} == grep {ref($_) eq 'ARRAY' && Scalar::Util::looks_like_number($_->[0])} @{$_[1]}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $_[1][0] eq "ARRAY" and @{$_[1];} == grep({ref $_ eq "ARRAY" and &Scalar::Util::looks_like_number($_->[0]);} @{$_[1];})
MC/DC0%0/2
ref $_[1][0] eq "ARRAY" and @{$_[1];} == grep({ref $_ eq "ARRAY" and &Scalar::Util::looks_like_number($_->[0]);} @{$_[1];})
ref $_[1][0] eq "ARRAY"
@{$_[1];} == grep({ref $_ eq "ARRAY" and &Scalar::Util::looks_like_number($_->[0]);} @{$_[1];})
Truth table0%0/3
A and B
A= ref $_[1][0] eq "ARRAY"B= @{$_[1];} == grep({ref $_ eq "ARRAY" and &Scalar::Util::looks_like_number($_->[0]);} @{$_[1];})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | # call matrix transform | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | &_trans2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | # call structure transform | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | &_trans3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | # if input a list (of numbers) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | } elsif (@_ == $h + 1 + grep {Scalar::Util::looks_like_number($_)} @_) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | # call list transform | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | &_trans0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | # error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | croak('invalid transform input'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | # inverse transform | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | # note: number of undefined output values must equal number of defined input values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | # note: input array contains the final calculated input values upon return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | # parameters: (ref_to_input_array, ref_to_output_array) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | sub inverse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | # get parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | my ($self, $in, $out) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | # local variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | my ($i, $j, @si, @so); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | my ($int, $info, $delta, $sys, $res, $mat); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | # check if ICC::Support::Lapack module is loaded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | state $lapack = defined($INC{'ICC/Support/Lapack.pm'}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | # initialize indices | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | $i = $j = -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | # build slice arrays while validating input and output arrays | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | ((grep {$i++; defined() && push(@si, $i)} @{$in}) == (grep {$j++; ! defined() && push(@so, $j)} @{$out})) or croak('wrong number of undefined values'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | # for each undefined output value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | for my $i (@so) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | # set to 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | $out->[$i] = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | # if ICC::Support::Lapack module is loaded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | if ($lapack) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | # compute initial transform values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | $int = ICC::Support::Lapack::matf_vec_trans($out, $self->[1]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | # for each input | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | for my $i (0 .. $#si) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | # for each output | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | for my $j (0 .. $#so) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | # copy Jacobian value to system matrix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | $sys->[$i][$j] = $self->[1][$si[$i]][$so[$j]]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | # compute residual value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | $res->[$i][0] = $in->[$si[$i]] - $int->[$si[$i]]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | # solve for delta values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | ($info, $delta) = ICC::Support::Lapack::solve($sys, $res); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | # report linear system error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | ($info) && print "ratfunc inverse error $info: @{$in}\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | # for each output value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | for my $i (0 .. $#so) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | # add delta value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | $out->[$so[$i]] += $delta->[$i][0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | # compute final transform values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | @{$in} = @{ICC::Support::Lapack::matf_vec_trans($out, $self->[1])}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | # compute initial transform values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | $int = [_trans0($self, @{$out})]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | # for each input | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | for my $i (0 .. $#si) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | # for each output | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | for my $j (0 .. $#so) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | # copy Jacobian value to solution matrix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | $mat->[$i][$j] = $self->[1][$si[$i]][$so[$j]]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | # save residual value to solution matrix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | $mat->[$i][$#si + 1] = $in->[$si[$i]] - $int->[$si[$i]]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | # bless Matrix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | bless($mat, 'Math::Matrix'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | # solve for delta values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | $delta = $mat->solve || print "ratfunc inverse error: @{$in}\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | # for each output value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | for my $i (0 .. $#so) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | # add delta value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | $out->[$so[$i]] += $delta->[$i][0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | # compute final transform values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | @{$in} = _trans0($self, @{$out}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | # compute Jacobian matrix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | # note: input values only required for output values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | # parameters: ([input_vector]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | # returns: (ref_to_Jacobian_matrix, [output_vector]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | sub jacobian { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | # get object reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | my $self = shift(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | # if output values wanted | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | if (wantarray) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | # return Jacobian and output values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | return(bless(Storable::dclone($self->[1]), 'Math::Matrix'), _trans1($self, $_[0])); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | # return Jacobian only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | return(bless(Storable::dclone($self->[1]), 'Math::Matrix')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | # get number of input channels | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | # returns: (number) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | sub cin { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | # get object reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cin: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | # return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | return(3); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | # get number of output channels | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | # returns: (number) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | sub cout { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | # get object reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cout: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | # return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | return(3); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | # print object contents to string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | # format is an array structure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | # parameter: ([format]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | # returns: (string) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | sub sdump { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | # get parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | ▶ | my ($self, $p) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sdump: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | # local variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | my ($fmt, $s, $rows, $fn); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | # resolve parameter to an array reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | ▶ | $p = defined($p) ? ref($p) eq 'ARRAY' ? $p : [$p] : []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | # get format string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | ▶ | $fmt = defined($p->[0]) && ! ref($p->[0]) ? $p->[0] : 'm'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $p->[0] and not ref $p->[0]
MC/DC0%0/2
defined $p->[0] and not ref $p->[0]
defined $p->[0]
not ref $p->[0]
Truth table0%0/3
A and not(B)
A= defined $p->[0]B= not ref $p->[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | # set string to object ID | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | # get matrix rows | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | $rows = $#{$self->[1]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | # if empty object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | ▶ | if ($rows < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | # append string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | $s .= "<empty object>\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | # append string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | $s .= "matrix values\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | # for each row | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | for my $i (0 .. $rows) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | # make number format | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | $fn = ' %10.5f' x @{$self->[1][$i]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | # append matrix row | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | $s .= sprintf("$fn\n", @{$self->[1][$i]}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | # return string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | return($s); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | # recursive transform | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | # array structure is traversed until scalar arrays are found and transformed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | # parameters: (ref_to_object, subroutine_reference, input_array_reference, output_array_reference) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | sub _crawl { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | # get parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | ▶ | my ($self, $sub, $in, $out) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_crawl: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | # if input is a vector (reference to a numeric array) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | ▶ | if (@{$in} == grep {Scalar::Util::looks_like_number($_)} @{$in}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | # transform input vector and copy to output | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | @{$out} = @{$sub->($self, $in)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | # for each input element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | for my $i (0 .. $#{$in}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | # if an array reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | ▶ | if (ref($in->[$i]) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | # transform next level | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | _crawl($self, $sub, $in->[$i], $out->[$i] = []); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | # error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 0 | croak('invalid input structure'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | # transform list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | # parameters: (object_reference, list, [hash]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | # returns: (list) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | sub _trans0 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | # local variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 0 | ▶ | my ($self, $hash, @out, $den); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_trans0: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | # get object reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | $self = shift(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | # get optional hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | ▶ | $hash = pop() if (ref($_[-1]) eq 'HASH'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | # validate number of input channels | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | ▶ | (@_ == 3) or croak('input samples must have 3 channels'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | # augment input sample | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 0 | push(@_, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | # for each output | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | for my $i (0 .. 2) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | # compute denominator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | $den = ICC::Shared::dotProduct(\@_, $self->[1][$i + 3]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | # add matrix value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 0 | ▶ | $out[$i] = ($den == 0) ? 'inf' : ICC::Shared::dotProduct(\@_, $self->[1][$i])/$den; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | # return output data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | return(@out); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | # transform vector | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | # parameters: (object_reference, vector, [hash]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | # returns: (vector) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | sub _trans1 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | # get parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | ▶ | my ($self, $in, $hash) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_trans1: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | # check if ICC::Support::Lapack module is loaded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 0 | state $lapack = defined($INC{'ICC/Support/Lapack.pm'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | # validate number of input channels | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 0 | ▶ | (@{$in} == 3) or croak('input samples must have 3 channels'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | # if ICC::Support::Lapack module is loaded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | ▶ | if ($lapack) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | # compute output vector using BLAS dgemv function | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | return(ICC::Support::Lapack::ratfunc_vec_trans($in, $self->[1])); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | # return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | return([_trans0($self, @{$in})]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | # transform matrix (2-D array -or- Math::Matrix object) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | # parameters: (object_reference, matrix, [hash]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | # returns: (matrix) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | sub _trans2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | # get parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 0 | ▶ | my ($self, $in, $hash) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_trans2: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | # local variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 0 | my ($info, $out, $aug, $den); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | # check if ICC::Support::Lapack module is loaded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | state $lapack = defined($INC{'ICC/Support/Lapack.pm'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | # validate number of input channels | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 0 | ▶ | (@{$in->[0]} == 3) or croak('input samples must have 3 channels'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | # if ICC::Support::Lapack module is loaded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 0 | ▶ | if ($lapack) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | # compute output matrix using BLAS dgemm function | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | $out = ICC::Support::Lapack::ratfunc_mat_trans($in, $self->[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | # for each row | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 0 | for my $i (0 .. $#{$in}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | # augment input sample | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | $aug = [@{$in->[$i]}, 1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | # for each column | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | for my $j (0 .. 2) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | # compute denominator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 0 | $den = ICC::Shared::dotProduct($aug, $self->[1][$j + 3]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | # add dot product | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | ▶ | $out->[$i][$j] = ($den == 0) ? 'inf' : ICC::Shared::dotProduct($aug, $self->[1][$j])/$den; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | # return output matrix (Math::Matrix object or 2-D array) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 0 | ▶ | return(UNIVERSAL::isa($in, 'Math::Matrix') ? bless($out, 'Math::Matrix') : $out); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | # transform structure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | # parameters: (object_reference, structure, [hash]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | # returns: (structure) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | sub _trans3 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | # get parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 0 | ▶ | my ($self, $in, $hash) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_trans3: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | # transform the array structure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 0 | _crawl($self, \&_trans1, $in, my $out = []); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | # return output structure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | return($out); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | # make new ratfunc object from matf object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | # parameters: (ref_to_object, matf_object) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | sub _new_from_matf { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | # get parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 0 | ▶ | my ($self, $matf) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new_from_matf: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | # local variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 0 | my ($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | # make identity matrix (6x4) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 0 | $self->[1] = bless([ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | [1, 0, 0, 0], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | [0, 1, 0, 0], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | [0, 0, 1, 0], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | [0, 0, 0, 1], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | [0, 0, 0, 1], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | [0, 0, 0, 1], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | ], 'Math::Matrix'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | # get 'matf' matrix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 0 | $value = $matf->matrix; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | # verify number of rows | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 0 | ▶ | ($#{$value} < 6) or croak('\'matf\' matrix has more than 6 rows'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | # for each row | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | for my $i (0 .. $#{$value}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | # verify number of columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 0 | ▶ | ($#{$value->[$i]} < 3) or croak('\'matf\' matrix has more than 3 columns'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | # for each column | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 0 | for my $j (0 .. $#{$value->[$i]}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | # verify matrix element is a number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 0 | ▶ | (Scalar::Util::looks_like_number($value->[$i][$j])) or croak('\'matf\' matrix element not numeric'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | # copy matrix element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 0 | $self->[1][$i][$j] = $value->[$i][$j]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | # get 'matf' offset | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 0 | $value = $matf->offset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | # verify number of elements | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 0 | ▶ | ($#{$value} < 3) or croak('\'matf\' offset has more than 3 elements'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | # for each element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 0 | for my $i (0 .. $#{$value}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | # verify array element is a number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 0 | ▶ | (Scalar::Util::looks_like_number($value->[$i])) or croak('\'matf\' offset element not numeric'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | # copy offset to object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 0 | $self->[1][$i][3] = $value->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | # make new ratfunc object from attribute hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | # hash keys are: ('header', 'matrix', 'offset') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | # object elements not specified in the hash are unchanged | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | # parameters: (ref_to_object, ref_to_attribute_hash) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | sub _new_from_hash { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | # get parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 0 | ▶ | my ($self, $hash) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new_from_hash: not called CC=18 SCAR=58.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | # local variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 0 | my ($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | # make identity matrix (6x4) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 0 | $self->[1] = bless([ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | [1, 0, 0, 0], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | [0, 1, 0, 0], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | [0, 0, 1, 0], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | [0, 0, 0, 1], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | [0, 0, 0, 1], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | [0, 0, 0, 1], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | ], 'Math::Matrix'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | # if 'header' key defined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 0 | ▶ | if (defined($hash->{'header'})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | # if reference to hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 0 | ▶ | if (ref($hash->{'header'}) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | # set object element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 0 | $self->[0] = {%{$hash->{'header'}}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | # wrong data type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 0 | croak('wrong \'header\' data type'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | # if 'matrix' key defined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 0 | ▶ | if (defined($hash->{'matrix'})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | # get value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 0 | $value = $hash->{'matrix'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | # if a reference to a 2-D array -or- Math::Matrix object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | 0 | ▶ | if ((ref($value) eq 'ARRAY' && @{$value} == grep {ref() eq 'ARRAY'} @{$value}) || UNIVERSAL::isa($value, 'Math::Matrix')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
ref $value eq "ARRAY" and @{$value;} == grep({ref $_ eq "ARRAY";} @{$value;}) or UNIVERSAL::isa($value, "Math::Matrix")
ref $value eq "ARRAY" and @{$value;} == grep({ref $_ eq "ARRAY";} @{$value;})
MC/DC0%0/3
ref $value eq "ARRAY" and @{$value;} == grep({ref $_ eq "ARRAY";} @{$value;}) or UNIVERSAL::isa($value, "Math::Matrix")
ref $value eq "ARRAY"
@{$value;} == grep({ref $_ eq "ARRAY";} @{$value;})
UNIVERSAL::isa($value, "Math::Matrix")
Truth table0%0/5
A and B or C
A= ref $value eq "ARRAY"B= @{$value;} == grep({ref $_ eq "ARRAY";} @{$value;})C= UNIVERSAL::isa($value, "Math::Matrix")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | # verify number of rows | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | 0 | ▶ | ($#{$value} < 6) or croak('\'matrix\' array has more than 6 rows'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | # for each row | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | 0 | for my $i (0 .. $#{$value}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | # verify number of columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 0 | ▶ | ($#{$value->[$i]} < 4) or croak('\'matrix\' array has more than 4 columns'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | # for each column | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | 0 | for my $j (0 .. $#{$value->[$i]}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | # verify matrix element is a number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | 0 | ▶ | (Scalar::Util::looks_like_number($value->[$i][$j])) or croak('\'matrix\' element not numeric'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | # copy matrix element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 0 | $self->[1][$i][$j] = $value->[$i][$j]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | # wrong data type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | 0 | croak('wrong \'matrix\' data type'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | # if 'offset' key defined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | 0 | ▶ | if (defined($hash->{'offset'})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | # get value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 0 | $value = $hash->{'offset'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | # if a reference to an array of scalars | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 0 | ▶ | if (ref($value) eq 'ARRAY' && @{$value} == grep {! ref()} @{$value}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $value eq "ARRAY" and @{$value;} == grep({not ref $_;} @{$value;})
MC/DC0%0/2
ref $value eq "ARRAY" and @{$value;} == grep({not ref $_;} @{$value;})
ref $value eq "ARRAY"
@{$value;} == grep({not ref $_;} @{$value;})
Truth table0%0/3
A and B
A= ref $value eq "ARRAY"B= @{$value;} == grep({not ref $_;} @{$value;})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | # verify number of elements | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | 0 | ▶ | ($#{$value} < 3) or croak('\'offset\' array has more than 3 elements'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | # for each element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | 0 | for my $i (0 .. $#{$value}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | # verify array element is a number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | 0 | ▶ | (Scalar::Util::looks_like_number($value->[$i])) or croak('\'offset\' element not numeric'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | # copy offset to object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | 0 | $self->[1][$i][3] = $value->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | # wrong data type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 0 | croak('wrong \'offset\' data type'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||