Core.pm (PDL-2.080) | : | Core.pm (PDL-2.081) | ||
---|---|---|---|---|
skipping to change at line 31 | skipping to change at line 31 | |||
# If "D" is available for pack(). | # If "D" is available for pack(). | |||
our $CAN_PACK_D = !! eval { my $packed = pack "D", 0; 1 }; | our $CAN_PACK_D = !! eval { my $packed = pack "D", 0; 1 }; | |||
our @EXPORT = qw( piddle pdl null barf ); # Only stuff always exported! | our @EXPORT = qw( piddle pdl null barf ); # Only stuff always exported! | |||
my @convertfuncs = map $_->convertfunc, PDL::Types::types(); | my @convertfuncs = map $_->convertfunc, PDL::Types::types(); | |||
my @exports_internal = qw(howbig broadcastids topdl); | my @exports_internal = qw(howbig broadcastids topdl); | |||
my @exports_normal = (@EXPORT, | my @exports_normal = (@EXPORT, | |||
@convertfuncs, | @convertfuncs, | |||
qw(nelem dims shape null | qw(nelem dims shape null | |||
empty dup dupN | empty dup dupN inflateN | |||
convert inplace zeroes zeros ones nan inf i list listindices unpdl | convert inplace zeroes zeros ones nan inf i list listindices unpdl | |||
set at flows broadcast_define over reshape dog cat barf type | set at flows broadcast_define over reshape dog cat barf type | |||
thread_define dummy mslice approx flat sclr squeeze | thread_define dummy mslice approx flat sclr squeeze | |||
get_autopthread_targ set_autopthread_targ get_autopthread_actual | get_autopthread_targ set_autopthread_targ get_autopthread_actual | |||
get_autopthread_dim get_autopthread_size set_autopthread_size) ); | get_autopthread_dim get_autopthread_size set_autopthread_size) ); | |||
our @EXPORT_OK = (@exports_internal, @exports_normal); | our @EXPORT_OK = (@exports_internal, @exports_normal); | |||
our %EXPORT_TAGS = ( | our %EXPORT_TAGS = ( | |||
Func => [@exports_normal], | Func => [@exports_normal], | |||
Internal => [@exports_internal] ); | Internal => [@exports_internal] ); | |||
skipping to change at line 1523 | skipping to change at line 1523 | |||
=head2 dupN | =head2 dupN | |||
=for ref | =for ref | |||
Duplicates an ndarray along several dimensions | Duplicates an ndarray along several dimensions | |||
=for example | =for example | |||
$x = sequence(3,2); | $x = sequence(3,2); | |||
$y = $x->dupN(2, 3); # doubles along first dimension, triples along second | $y = $x->dupN(2, 3); # doubles along first dimension, triples along second | |||
# [ | ||||
# [0 1 2 0 1 2] | ||||
# [3 4 5 3 4 5] | ||||
# [0 1 2 0 1 2] | ||||
# [3 4 5 3 4 5] | ||||
# ] | ||||
=cut | =cut | |||
sub PDL::dupN { | sub PDL::dupN { | |||
my ($this, @times) = @_; | my ($this, @times) = @_; | |||
return $this->copy if !grep $_ != 1, @times; | return $this->copy if !grep $_ != 1, @times; | |||
my $sl = join ',', map ":,*$_", @times; # insert right-size dummy after each r eal | my $sl = join ',', map ":,*$_", @times; # insert right-size dummy after each r eal | |||
$this = $this->slice($sl); | $this = $this->slice($sl); | |||
$this = $this->clump($_, $_+1) for 0..$#times; | $this = $this->clump($_, $_+1) for 0..$#times; | |||
$this; | $this; | |||
} | } | |||
=head2 inflateN | ||||
=for ref | ||||
Inflates an ndarray along several dimensions, useful for e.g. Kronecker products | ||||
cf L</dupN> | ||||
=for example | ||||
$x = sequence(3,2); | ||||
$y = $x->inflateN(2, 2); # doubles along first two dimensions | ||||
# [ | ||||
# [0 0 1 1 2 2] | ||||
# [0 0 1 1 2 2] | ||||
# [3 3 4 4 5 5] | ||||
# [3 3 4 4 5 5] | ||||
# ] | ||||
=cut | ||||
sub PDL::inflateN { | ||||
my ($this, @times) = @_; | ||||
return $this->copy if !grep $_ != 1, @times; | ||||
my $sl = join ',', map "*$_,:", @times; | ||||
$this = $this->slice($sl); | ||||
$this = $this->clump($_, $_+1) for 0..$#times; | ||||
$this; | ||||
} | ||||
=head2 clump | =head2 clump | |||
=for ref | =for ref | |||
"clumps" several dimensions into one large dimension | "clumps" several dimensions into one large dimension | |||
If called with one argument C<$n> clumps the first C<$n> | If called with one argument C<$n> clumps the first C<$n> | |||
dimensions into one. For example, if C<$x> has dimensions | dimensions into one. For example, if C<$x> has dimensions | |||
C<(5,3,4)> then after | C<(5,3,4)> then after | |||
End of changes. 3 change blocks. | ||||
1 lines changed or deleted | 37 lines changed or added |