File Coverage

blib/lib/PDLA/PP/Dims.pm
Criterion Covered Total %
statement 34 45 75.5
branch 5 18 27.7
condition 0 6 0.0
subroutine 10 12 83.3
pod n/a
total 49 81 60.4


line stmt bran cond sub pod time code
1             ##############################################
2             package PDLA::PP::PdlDimsObj; # Hold more dims
3 2     2   9 use Carp;
  2         4  
  2         491  
4              
5             sub new {
6 2     2   5 my($type) = @_;
7 2         9 bless {},$type;
8             }
9              
10             sub get_indobj_make {
11 2     2   5 my($this,$expr) = @_;
12 2 50       18 $expr =~ /^([a-zA-Z0-9]+)(?:=([0-9]+))?$/ or confess "Invalid index expr '$expr'\n";
13 2         5 my $name = $1; my $val = $2;
  2         5  
14 2         4 my $indobj;
15 2 50       20 if(defined $this->{$name}) {
16 0         0 $indobj = $this->{$name};
17             } else {
18 2         17 $indobj = PDLA::PP::Ind->new($name);
19 2         7 $this->{$name}=$indobj;
20             }
21 2 50       43 if(defined $val) { $indobj->add_value($val); }
  0         0  
22 2         12 return $indobj;
23             }
24              
25             #####################################################################
26             #
27             # Encapsulate one index.
28              
29             package PDLA::PP::Ind;
30 2     2   10 use Carp;
  2         4  
  2         872  
31              
32             sub new {
33 2     2   7 my($type,$name) = @_;
34 2         14 my $this = bless {Name => $name},$type;
35 2         6 return $this;
36             }
37              
38             # set the value of an index, also used by perl level threading
39             sub add_value {
40 0     0   0 my($this,$val) = @_;
41 0 0       0 croak("index values for $this->{Name} must be positive")
42             unless $val > 0;
43 0 0       0 if(defined $this->{Value}) {
44 0 0 0     0 if ($this->{Value} == -1 || $this->{Value} == 1)
    0 0        
45 0         0 { $this->{Value} = $val }
46             elsif($val != 1 && $val != $this->{Value}) {
47 0         0 croak("For index $this->{Name} conflicting values $this->{Value} and $val given\n");
48             }
49             } else {
50 0         0 $this->{Value} = $val;
51             }
52             }
53              
54             # This index will take its size value from outside parameter ...
55 0     0   0 sub set_from { my($this,$otherpar) = @_;
56 0         0 $this->{From} = $otherpar;
57             }
58              
59 14     14   113 sub name {return (shift)->{Name}}
60              
61 1     1   2 sub get_decldim { my($this) = @_;
62 1         12 return "PDLA_Indx __$this->{Name}_size;";
63             }
64              
65 1     1   2 sub get_initdim { my($this) = @_;
66 1         2 my $init = '-1';
67             $init = "\$COMP(".$this->{From}->{ProtoName}.")"
68 1 50       4 if $this->{From};
69 1 50       4 $init = $this->{Value} if defined $this->{Value};
70 1         7 "\$PRIV(__$this->{Name}_size) = $init;"
71             }
72              
73 1     1   3 sub get_copydim { my($this,$fromsub,$tosub) = @_;
74 1         4 my($iname) = "__$this->{Name}_size";
75 1         9 &$tosub($iname) ."=". &$fromsub($iname) .";" ;
76             }
77              
78 2     2   3 sub get_size { my($this) = @_;
79 2         8 "\$PRIV(__$this->{Name}_size)"
80             }
81              
82             1;