Dims.pm (PDL-2.081) | : | Dims.pm (PDL-2.082) | ||
---|---|---|---|---|
skipping to change at line 13 | skipping to change at line 13 | |||
use strict; | use strict; | |||
use warnings; | use warnings; | |||
use Carp; | use Carp; | |||
sub new { | sub new { | |||
my($type) = @_; | my($type) = @_; | |||
bless {},$type; | bless {},$type; | |||
} | } | |||
sub get_indobj_make { | sub get_indobj_make { | |||
my($this,$expr) = @_; | my($this,$expr) = @_; | |||
$expr =~ /^([a-zA-Z0-9]+)(?:=([0-9]+))?$/ or confess "Invalid index expr | my ($name, $val) = $expr =~ /^([a-zA-Z0-9]+)(?:=([0-9]+))?$/ or confess "Inval | |||
'$expr'\n"; | id index expr '$expr'\n"; | |||
my $name = $1; my $val = $2; | my $indobj = $this->{$name} //= PDL::PP::Ind->new($name); | |||
my $indobj; | $indobj->add_value($val) if defined $val; | |||
if(defined $this->{$name}) { | return $indobj; | |||
$indobj = $this->{$name}; | ||||
} else { | ||||
$indobj = PDL::PP::Ind->new($name); | ||||
$this->{$name}=$indobj; | ||||
} | ||||
if(defined $val) { $indobj->add_value($val); } | ||||
return $indobj; | ||||
} | } | |||
##################################################################### | ##################################################################### | |||
# | # | |||
# Encapsulate one index. | # Encapsulate one index. | |||
package PDL::PP::Ind; | package PDL::PP::Ind; | |||
use Carp; | use Carp; | |||
sub new { | sub new { | |||
skipping to change at line 56 | skipping to change at line 49 | |||
$this->{Value} == -1 or | $this->{Value} == -1 or | |||
$this->{Value} == 1; | $this->{Value} == 1; | |||
croak "For index $this->{Name} conflicting values $this->{Value} and $val given\n" if $val != 1 && $val != $this->{Value}; | croak "For index $this->{Name} conflicting values $this->{Value} and $val given\n" if $val != 1 && $val != $this->{Value}; | |||
} | } | |||
# This index will take its size value from outside parameter ... | # This index will take its size value from outside parameter ... | |||
sub set_from { my($this,$otherpar) = @_; | sub set_from { my($this,$otherpar) = @_; | |||
$this->{From} = $otherpar; | $this->{From} = $otherpar; | |||
} | } | |||
sub name {$_[0]->{Name}} | sub name {$_[0]{Name}} | |||
# where it occurs in the C arrays that track it (at least name and size) | # where it occurs in the C arrays that track it (at least name and size) | |||
sub set_index { | sub set_index { | |||
my ($this, $i) = @_; | my ($this, $i) = @_; | |||
$this->{Index} = $i; | $this->{Index} = $i; | |||
} | } | |||
sub get_index {$_[0]->{Index}} | sub get_index {$_[0]{Index} // confess "unknown index for $_[0]{Name}"} | |||
sub get_initdim { my($this) = @_; | sub get_initdim { my($this) = @_; | |||
my $init = $this->{Value} // | my $init = $this->{Value} // | |||
($this->{From} ? "\$COMP(".$this->{From}{ProtoName}.")" : undef); | ($this->{From} ? "\$COMP(".$this->{From}{ProtoName}.")" : undef); | |||
return if !defined $init; | return if !defined $init; | |||
$this->get_size." = $init;" | $this->get_size." = $init;" | |||
} | } | |||
sub get_size { my($this) = @_; | sub get_size { my($this) = @_; | |||
"\$PRIV(ind_sizes)[@{[$this->get_index]}]" | "\$PRIV(ind_sizes)[@{[$this->get_index]}]" | |||
End of changes. 3 change blocks. | ||||
15 lines changed or deleted | 8 lines changed or added |