blib/lib/Perl/Structure/GSLMatrix.pm untested

filter: Statementstmt 0.0% 0 / 145 Branchbran 0.0% 0 / 32 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 20 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 206 CC 17 SCAR 38.3
CC
17
Cov
0%
gsl_matrix_CHECK
90.0
gsl_matrix_CHECKTRACE
90.0
gsl_matrix_to_arrayref_number
2.0
CRAP 46.0
1 # [[[ HEADER ]]]
2 package Perl::Structure::GSLMatrix;
3 use strict;
4 use warnings;
5 use Perl::Config; # don't use Perl::Types inside itself, in order to avoid circular includes
6 our $VERSION = 0.001_000;
7  
8 # [[[ OO INHERITANCE ]]]
9 # OO (non-procedural) data structure
10 #use parent qw(Math::GSL::Matrix Perl::Structure::Array::Reference); # NEED UPGRADE, CORRELATION #rp023: Inline::CPP support for multiple inheritance
11 use parent qw(Math::GSL::Matrix);
12 use Math::GSL::Matrix qw(:all); # we still actually use GSL in PERLOPS_PERLTYPES mode, albeit indirectly via Math::GSL::Matrix
13 #use Perl::Structure::Array::Reference; # NEED ANSWER: do we actually inherit or use any part of Array::Reference? is this inheritance actually correct logically?
14  
15 # [[[ CRITICS ]]]
16 ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls) # USER DEFAULT 1: allow numeric values & print operator
17 ## no critic qw(RequireInterpolationOfMetachars) # USER DEFAULT 2: allow single-quoted control characters & sigils
18 ## no critic qw(Capitalization ProhibitMultiplePackages ProhibitReusedNames) # SYSTEM DEFAULT 3: allow multiple & lower case package names
19 ## no critic qw(ProhibitAutomaticExportation) # SYSTEM SPECIAL 14: allow global exports from Config.pm & elsewhere
20  
21 # [[[ EXPORTS ]]]
22 use Exporter 'import';
23 our @EXPORT = qw(
24 gsl_matrix_CHECK
25 gsl_matrix_CHECKTRACE
26 gsl_matrix_to_arrayref_number
27 gsl_matrix_to_arrayref_arrayref_number
28 gsl_matrix_to_string
29 arrayref_number_to_gsl_matrix
30 );
31 our @EXPORT_OK = qw(
32 gsl_matrix_typetest0
33 gsl_matrix_typetest1
34 gsl_matrix_typetest99
35 );
36  
37 # [[[ INCLUDES ]]]
38 #use RPerl::Operation::Expression::Operator::GSLFunctions; # NEED UPDATE, RPERL REFACTOR
39 use Perl::Type::Number;
40  
41 # [[[ SUB-TYPES ]]]
42  
43 # non-OO (procedural) data structure
44 package gsl_matrix;
45 use strict;
46 use warnings;
47 #use parent qw(Math::GSL::Matrix::gsl_matrix); # there is no such file as Math/GSL/Matrix/gsl_matrix.pm
48 our @ISA = qw(Math::GSL::Matrix::gsl_matrix);
49  
50 # [[[ SWITCH CONTEXT BACK TO PRIMARY PACKAGE ]]]
51 package Perl::Structure::GSLMatrix;
52 use strict;
53 use warnings;
54  
55 # [[[ TYPE-CHECKING ]]]
56 sub gsl_matrix_CHECK {
57 { my void $RETURN_TYPE };
58 ( my $possible_gsl_matrix ) = @ARG;
59  
60 # Perl::diag("in PERLOPS_PERLTYPES gsl_matrix_CHECK(), top of subroutine\n");
61  
62 if ( not( defined $possible_gsl_matrix ) ) {
63 die( "\nERROR EMAV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nMath::GSL::Matrix::gsl_matrix external wrapper value expected but undefined/null value found,\ndying\n" );
64 }
65 if ( not( main::PerlTypes_SvHROKp($possible_gsl_matrix) ) ) {
66 die("\nERROR EMAV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nMath::GSL::Matrix::gsl_matrix external wrapper value expected but non-hashref value found,\ndying\n");
67 }
68 my string $classname = main::class($possible_gsl_matrix);
69 if ( not defined $classname ) {
70 die( "\nERROR EMAV02, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nMath::GSL::Matrix::gsl_matrix external wrapper value expected but non-object (blessed hashref) value found,\ndying\n" );
71 }
72 if ( not( UNIVERSAL::isa( $possible_gsl_matrix, 'Math::GSL::Matrix::gsl_matrix' ) ) ) {
73 die( "\nERROR EMAV03, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nMath::GSL::Matrix::gsl_matrix external wrapper value expected but non-Math::GSL::Matrix::gsl_matrix-derived object value found,\ndying\n" );
74 }
75 if ( $classname ne 'Math::GSL::Matrix::gsl_matrix' ) {
76 die( "\nERROR EMAV04, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nMath::GSL::Matrix::gsl_matrix external wrapper value expected but non-Math::GSL::Matrix::gsl_matrix object value found,\ndying" );
77 }
78  
79 # if ( not exists $possible_gsl_matrix->{data} ) {
80 # die( "\nERROR EMAV05, MISSING HASH ENTRY, PERLOPS_PERLTYPES:\nMath::GSL::Matrix::gsl_matrix internal wrapped object in hash entry expected at key 'value' but no hash entry exists,\ndying\n" );
81 # }
82 if ( not defined $possible_gsl_matrix->{data} ) {
83 die( "\nERROR EMAV06, MISSING HASH ENTRY, PERLOPS_PERLTYPES:\nMath::GSL::Matrix::gsl_matrix internal wrapped object in hash entry expected at key 'value' but no hash entry defined;\nOR\nERROR EMAV07, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nMath::GSL::Matrix::gsl_matrix internal wrapped value expected but undefined/null value found,\ndying\n" );
84 }
85 if ( not defined main::class( $possible_gsl_matrix->{data} ) ) {
86 die( "\nERROR EMAV08, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nMath::GSL::Matrix::gsl_matrix internal wrapped value expected but non-object (blessed hashref) value found,\ndying\n" );
87 }
88 if ( not( UNIVERSAL::isa( $possible_gsl_matrix->{data}, '_p_double' ) ) ) {
89 die( "\nERROR EMAV09, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nMath::GSL::Matrix::gsl_matrix _p_double internal wrapped value expected but non-_p_double object value found,\ndying\n" );
90 }
91  
92 # Perl::diag("in PERLOPS_PERLTYPES gsl_matrix_CHECK(), bottom of subroutine\n");
93 return;
94 }
95  
96 sub gsl_matrix_CHECKTRACE {
97 { my void $RETURN_TYPE };
98 ( my $possible_gsl_matrix, my $variable_name, my $subroutine_name ) = @ARG;
99  
100 # Perl::diag("in PERLOPS_PERLTYPES gsl_matrix_CHECKTRACE(), top of subroutine\n");
101 # Perl::diag('in PERLOPS_PERLTYPES gsl_matrix_CHECKTRACE(), received $variable_name = ' . $variable_name . "\n");
102 # Perl::diag('in PERLOPS_PERLTYPES gsl_matrix_CHECKTRACE(), received $subroutine_name = ' . $subroutine_name . "\n");
103  
104 if ( not( defined $possible_gsl_matrix ) ) {
105 die( "\nERROR EMAV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nMath::GSL::Matrix::gsl_matrix external wrapper value expected but undefined/null value found,\nin variable " . $variable_name . " from subroutine " . $subroutine_name . ",\ndying\n" );
106 }
107 if ( not( main::PerlTypes_SvHROKp($possible_gsl_matrix) ) ) {
108 die("\nERROR EMAV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nMath::GSL::Matrix::gsl_matrix external wrapper value expected but non-hashref value found,\nin variable " . $variable_name . " from subroutine " . $subroutine_name . ",\ndying\n" );
109 }
110 my string $classname = main::class($possible_gsl_matrix);
111 if ( not defined $classname ) {
112 die( "\nERROR EMAV02, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nMath::GSL::Matrix::gsl_matrix external wrapper value expected but non-object (blessed hashref) value found,\nin variable " . $variable_name . " from subroutine " . $subroutine_name . ",\ndying\n" );
113 }
114 if ( not( UNIVERSAL::isa( $possible_gsl_matrix, 'Math::GSL::Matrix::gsl_matrix' ) ) ) {
115 die( "\nERROR EMAV03, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nMath::GSL::Matrix::gsl_matrix external wrapper value expected but non-Math::GSL::Matrix::gsl_matrix-derived object value found,\nin variable " . $variable_name . " from subroutine " . $subroutine_name . ",\ndying\n" );
116 }
117 if ( $classname ne 'Math::GSL::Matrix::gsl_matrix' ) {
118 die( "\nERROR EMAV04, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nMath::GSL::Matrix::gsl_matrix external wrapper value expected but non-Math::GSL::Matrix::gsl_matrix object value found,\nin variable " . $variable_name . " from subroutine " . $subroutine_name . ",\ndying\n" );
119 }
120  
121 # Math::GSL::Matrix::gsl_matrix is a tied object, not a real hash, so $my_gsl_matrix->{data} is not actually a Perl hash value retrieval;
122 # Math::GSL::Matrix::gsl_matrix does not currently have an exists() method, so we will get the following error by calling hv_exists():
123 # Can't locate object method "EXISTS" via package "Math::GSL::Matrix::gsl_matrix"
124 # if ( not exists $possible_gsl_matrix->{data} ) {
125 # die( "\nERROR EMAV05, MISSING HASH ENTRY, PERLOPS_PERLTYPES:\nMath::GSL::Matrix::gsl_matrix internal wrapped object in hash entry expected at key 'value' but no hash entry exists,\nin variable " . $variable_name . " from subroutine " . $subroutine_name . ",\ndying\n" );
126 # }
127 if ( not defined $possible_gsl_matrix->{data} ) {
128 die( "\nERROR EMAV06, MISSING HASH ENTRY, PERLOPS_PERLTYPES:\nMath::GSL::Matrix::gsl_matrix internal wrapped object in hash entry expected at key 'value' but no hash entry defined;\nOR\nERROR EMAV07, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nMath::GSL::Matrix::gsl_matrix internal wrapped value expected but undefined/null value found,\nin variable " . $variable_name . " from subroutine " . $subroutine_name . ",\ndying\n" );
129 }
130 if ( not defined main::class( $possible_gsl_matrix->{data} ) ) {
131 die( "\nERROR EMAV08, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nMath::GSL::Matrix::gsl_matrix internal wrapped value expected but non-object (blessed hashref) value found,\nin variable " . $variable_name . " from subroutine " . $subroutine_name . ",\ndying\n" );
132 }
133 if ( not( UNIVERSAL::isa( $possible_gsl_matrix->{data}, '_p_double' ) ) ) {
134 die( "\nERROR EMAV09, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nMath::GSL::Matrix::gsl_matrix _p_double internal wrapped value expected but non-_p_double object value found,\nin variable " . $variable_name . " from subroutine " . $subroutine_name . ",\ndying\n" );
135 }
136  
137 # Perl::diag("in PERLOPS_PERLTYPES gsl_matrix_CHECKTRACE(), bottom of subroutine\n");
138 return;
139 }
140  
141 # [[[ ARRAYIFY ]]]
142  
143 # DEV NOTE, CORRELATION #rp052: gsl_matrix_to_*() and gsl_matrix_rows() and gsl_matrix_cols() are RPerl subroutines
144 sub gsl_matrix_to_arrayref_number {
145 { my arrayref::number $RETURN_TYPE };
146 ( my gsl_matrix $input_gsl_matrix ) = @ARG;
147  
148 # gsl_matrix_CHECK($input_gsl_matrix);
149 gsl_matrix_CHECKTRACE( $input_gsl_matrix, '$input_gsl_matrix', 'gsl_matrix_to_arrayref_number()' );
150  
151 my arrayref::number $retval = [];
152  
153 # NEED UPGRADE: use gsl_matrix_get_col() or something else faster than loops
154 foreach my integer $i (0 .. (gsl_matrix_rows($input_gsl_matrix) - 1)) {
155 foreach my integer $j (0 .. (gsl_matrix_cols($input_gsl_matrix) - 1)) {
156 push @{$retval}, gsl_matrix_get($input_gsl_matrix, $i, $j);
157 }
158 }
159  
160 return $retval;
161 }
162  
163 sub gsl_matrix_to_arrayref_arrayref_number {
164 { my arrayref::arrayref::number $RETURN_TYPE };
165 ( my gsl_matrix $input_gsl_matrix ) = @ARG;
166  
167 # gsl_matrix_CHECK($input_gsl_matrix);
168 gsl_matrix_CHECKTRACE( $input_gsl_matrix, '$input_gsl_matrix', 'gsl_matrix_to_arrayref_arrayref_number()' );
169  
170 # NEED ADD CODE EVENTUALLY
171  
172 die 'DUMMY CODE STUB, NEED REAL CODE!' . "\n" . 'dying';
173 }
174  
175 # [[[ STRINGIFY ]]]
176  
177 sub gsl_matrix_to_string {
178 { my string $RETURN_TYPE };
179 ( my gsl_matrix $input_gsl_matrix ) = @ARG;
180 Perl::diag('in PERLOPS_PERLTYPES gsl_matrix_to_string(), top of subroutine', "\n");
181
182 # gsl_matrix_CHECK($input_gsl_matrix);
183 gsl_matrix_CHECKTRACE( $input_gsl_matrix, '$input_gsl_matrix', 'gsl_matrix_to_string()' );
184  
185 # Perl::diag('in PERLOPS_PERLTYPES gsl_matrix_to_string(), have $input_gsl_matrix = ', Dumper($input_gsl_matrix), "\n");
186 # Perl::diag('in PERLOPS_PERLTYPES gsl_matrix_to_string(), have gsl_matrix_get($input_gsl_matrix, 0, 0) = ', gsl_matrix_get($input_gsl_matrix, 0, 0), "\n");
187 # Perl::diag('in PERLOPS_PERLTYPES gsl_matrix_to_string(), have gsl_matrix_get($input_gsl_matrix, 0, 1) = ', gsl_matrix_get($input_gsl_matrix, 0, 1), "\n");
188 # Perl::diag('in PERLOPS_PERLTYPES gsl_matrix_to_string(), have gsl_matrix_get($input_gsl_matrix, 1, 0) = ', gsl_matrix_get($input_gsl_matrix, 1, 0), "\n");
189 # Perl::diag('in PERLOPS_PERLTYPES gsl_matrix_to_string(), have gsl_matrix_get($input_gsl_matrix, 1, 1) = ', gsl_matrix_get($input_gsl_matrix, 1, 1), "\n");
190  
191 my string $retval = q{};
192 my integer $i_max = gsl_matrix_rows($input_gsl_matrix) - 1;
193 my integer $j_max = gsl_matrix_cols($input_gsl_matrix) - 1;
194  
195 # my integer $i_max = 1;
196 # my integer $j_max = 1;
197 # Perl::diag('in PERLOPS_PERLTYPES gsl_matrix_to_string(), have $i_max = ', $i_max, ', $j_max = ', $j_max, "\n");
198  
199 for my integer $i (0 .. $i_max) {
200 # Perl::diag('in PERLOPS_PERLTYPES gsl_matrix_to_string(), have $i = ', $i, "\n");
201 for my integer $j (0 .. $j_max) {
202 # Perl::diag('in PERLOPS_PERLTYPES gsl_matrix_to_string(), have $j = ', $j, "\n");
203 $retval .= number_to_string(gsl_matrix_get($input_gsl_matrix, $i, $j)) . "\t";
204 }
205 $retval .= "\n";
206 }
207 $retval .= "\n";
208 return $retval;
209 }
210  
211 # [[[ GSL MATRIXIFY ]]]
212 # DEV NOTE: keep all these *_to_gsl_matrix() conversion subroutines here instead of spread throughout the other RPerl/Data*/*.pm files,
213 # so that loading will all be controlled by the 'use perlgsl;' directive
214  
215 sub arrayref_number_to_gsl_matrix {
216 { my gsl_matrix $RETURN_TYPE };
217 ( my arrayref::number $input_arrayref_number, my integer $rows, my integer $cols ) = @ARG;
218 # Perl::diag('in PERLOPS_PERLTYPES arrayref_number_to_gsl_matrix(), top of subroutine', "\n");
219  
220 # ::arrayref_number_CHECK($input_arrayref_number);
221 ::arrayref_number_CHECKTRACE( $input_arrayref_number, '$input_arrayref_number', 'arrayref_number_to_gsl_matrix()' );
222  
223 # Perl::diag('in PERLOPS_PERLTYPES arrayref_number_to_gsl_matrix(), received $rows = ', $rows, ', $cols = ', $cols, "\n");
224  
225 my gsl_matrix $retval = gsl_matrix_alloc($rows, $cols);
226  
227 for my integer $i (0 .. ($rows - 1)) {
228 for my integer $j (0 .. ($cols - 1)) {
229 gsl_matrix_set($retval, $i, $j, $input_arrayref_number->[($i * $cols) + $j]);
230 }
231 }
232 # Perl::diag('in PERLOPS_PERLTYPES arrayref_number_to_gsl_matrix(), bottom of subroutine', "\n");
233 return $retval;
234 }
235  
236 # [[[ TYPE TESTING ]]]
237  
238 sub gsl_matrix_typetest0 {
239 { my gsl_matrix $RETURN_TYPE };
240 Perl::diag('in PERLOPS_PERLTYPES gsl_matrix_typetest0(), top of subroutine' . "\n");
241  
242 my gsl_matrix $retval = gsl_matrix_alloc(21, 12);
243 gsl_matrix_set($retval, 0, 0, (main::Perl__Type__Integer__MODE_ID() + 23));
244 return ($retval);
245 }
246  
247 sub gsl_matrix_typetest1 {
248 { my gsl_matrix $RETURN_TYPE };
249 ( my gsl_matrix $lucky_gsl_matrix ) = @ARG;
250 Perl::diag('in PERLOPS_PERLTYPES gsl_matrix_typetest1(), top of subroutine' . "\n");
251  
252 # ::gsl_matrix_CHECK($lucky_gsl_matrix);
253 ::gsl_matrix_CHECKTRACE( $lucky_gsl_matrix, '$lucky_gsl_matrix', 'gsl_matrix_typetest1()' );
254  
255 Perl::diag('in PERLOPS_PERLTYPES gsl_matrix_typetest1(), received $lucky_gsl_matrix = ', "\n", gsl_matrix_to_string($lucky_gsl_matrix), "\n");
256  
257 gsl_matrix_add_constant($lucky_gsl_matrix, main::Perl__Type__Integer__MODE_ID());
258  
259 Perl::diag('in PERLOPS_PERLTYPES gsl_matrix_typetest1(), about to return $lucky_gsl_matrix = ', "\n", gsl_matrix_to_string($lucky_gsl_matrix), "\n");
260 return $lucky_gsl_matrix;
261 }
262  
263 sub gsl_matrix_typetest99 {
264 { my integer $RETURN_TYPE };
265 return 23;
266 }
267  
268 1; # end of class