Libtensorflow/ImportGraphDefResults.pm untested

filter: Statementstmt 0.0% 0 / 66 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod n/a totaltotal 0.0% 0 / 76 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package AI::TensorFlow::Libtensorflow::ImportGraphDefResults;
2 # ABSTRACT: Results from importing a graph definition
3 $AI::TensorFlow::Libtensorflow::ImportGraphDefResults::VERSION = '0.0.7';
4 use strict;
5 use warnings;
6 use namespace::autoclean;
7 use AI::TensorFlow::Libtensorflow::Lib qw(arg);
8 use FFI::Platypus::Buffer qw(buffer_to_scalar window);
9 use List::Util ();
10  
11 my $ffi = AI::TensorFlow::Libtensorflow::Lib->ffi;
12 $ffi->mangler(AI::TensorFlow::Libtensorflow::Lib->mangler_default);
13  
14 $ffi->attach( [ 'DeleteImportGraphDefResults' => 'DESTROY' ] => [
15 arg TF_ImportGraphDefResults => 'results',
16 ] => 'void' );
17  
18 $ffi->attach( [ 'ImportGraphDefResultsReturnOutputs' => 'ReturnOutputs' ] => [
19 arg TF_ImportGraphDefResults => 'results',
20 arg 'int*' => 'num_outputs',
21 arg 'opaque*' => { id => 'outputs', type => 'TF_Output_struct_array*' },
22 ] => 'void' => sub {
23 my ($xs, $results) = @_;
24 my $num_outputs;
25 my $outputs_array = undef;
26 $xs->($results, \$num_outputs, \$outputs_array);
27 return [] if $num_outputs == 0;
28  
29 my $sizeof_output = $ffi->sizeof('TF_Output');
30 window(my $outputs_packed, $outputs_array, $sizeof_output * $num_outputs );
31 # due to unpack, these are copies (no longer owned by $results)
32 my @outputs = map bless(\$_, "AI::TensorFlow::Libtensorflow::Output"),
33 unpack "(a${sizeof_output})*", $outputs_packed;
34 return \@outputs;
35 });
36  
37 $ffi->attach( [ 'ImportGraphDefResultsReturnOperations' => 'ReturnOperations' ] => [
38 arg TF_ImportGraphDefResults => 'results',
39 arg 'int*' => 'num_opers',
40 arg 'opaque*' => { id => 'opers', type => 'TF_Operation_array*' },
41 ] => 'void' => sub {
42 my ($xs, $results) = @_;
43 my $num_opers;
44 my $opers_array = undef;
45 $xs->($results, \$num_opers, \$opers_array);
46 return [] if $num_opers == 0;
47  
48 my $opers_array_base_packed = buffer_to_scalar($opers_array,
49 $ffi->sizeof('opaque') * $num_opers );
50 my @opers = map {
51 $ffi->cast('opaque', 'TF_Operation', $_ )
52 } unpack "(@{[ AI::TensorFlow::Libtensorflow::Lib::_pointer_incantation ]})*", $opers_array_base_packed;
53 return \@opers;
54 } );
55  
56 $ffi->attach( [ 'ImportGraphDefResultsMissingUnusedInputMappings' => 'MissingUnusedInputMappings' ] => [
57 arg TF_ImportGraphDefResults => 'results',
58 arg 'int*' => 'num_missing_unused_input_mappings',
59 arg 'opaque*' => { id => 'src_names', ctype => 'const char***' },
60 arg 'opaque*' => { id => 'src_indexes', ctype => 'int**' },
61 ] => 'void' => sub {
62 my ($xs, $results) = @_;
63 my $num_missing_unused_input_mappings;
64 my $src_names;
65 my $src_indexes;
66 $xs->($results,
67 \$num_missing_unused_input_mappings,
68 \$src_names, \$src_indexes
69 );
70 my $src_names_str = $ffi->cast('opaque',
71 "string[$num_missing_unused_input_mappings]", $src_names);
72 my $src_indexes_int = $ffi->cast('opaque',
73 "int[$num_missing_unused_input_mappings]", $src_indexes);
74 return [ List::Util::zip($src_names_str, $src_indexes_int) ];
75 });
76  
77 1;
78  
79 __END__