Skip to content

Commit aee0831

Browse files
committed
fixed $slice->inplace->*{lin,log}vals not updating $slice
1 parent 5e5dd88 commit aee0831

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
- pdldoc database now reproducible (#542) - thanks @daym
33
- can now do pdl(cplx(1,2)) (#543) - thanks @gladilin for report
44
- add convert_flowing method
5+
- fixed $slice->inplace->*{lin,log}vals not updating $slice
56

67
2.100 2025-03-27
78
- fix Math function prototypes for GCC 15 (#528) - thanks @jplesnik for report

lib/PDL/Basic.pm

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,9 @@ sub _dimcheck {
248248
}
249249
sub _linvals {
250250
my ($pdl, $v1, $v2, $dim, $method) = @_;
251-
$pdl->$method * (($v2 - $v1) / ($dim > 1 ? ($dim-1) : 1)) + $v1;
251+
$pdl = $pdl->$method;
252+
$pdl *= (($v2 - $v1) / ($dim > 1 ? ($dim-1) : 1));
253+
$pdl += $v1;
252254
}
253255
sub PDL::xlinvals {
254256
_linvals(@_[0..2], _dimcheck($_[0], 0, 'xlinvals'), 'xvals');
@@ -264,7 +266,8 @@ sub _logvals {
264266
my ($pdl, $min, $max, $dim, $method) = @_;
265267
barf "min and max must be positive" if $min <= 0 || $max <= 0;
266268
my ($lmin,$lmax) = map log($_), $min, $max;
267-
exp($pdl->$method * (($lmax - $lmin) / ($dim > 1 ? ($dim-1) : 1)) + $lmin);
269+
$pdl = $pdl->$method;
270+
$pdl .= exp($pdl * (($lmax - $lmin) / ($dim > 1 ? ($dim-1) : 1)) + $lmin);
268271
}
269272
sub PDL::xlogvals {
270273
_logvals(@_[0..2], _dimcheck($_[0], 0, 'xlogvals'), 'xvals');

t/basic.t

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ my $byte_xvals = ones( byte, 300 )->xvals;
4141
is $byte_xvals->type, 'double', 'byte->xvals type double';
4242
is $byte_xvals->at(280), 280,'non-overflow xvals from byte ndarray';
4343
is xvals(short, 2)->type, 'short', 'xvals respects specified type';
44+
my ($base, $exp) = (zeroes(3,3), pdl('0;0.5;1'));
45+
is_pdl $base->slice('0')->inplace->ylinvals(0,1), $exp, 'inplace->linvals returns right';
46+
is_pdl $base->slice('0'), $exp, 'inplace->linvals updates input';
47+
($base, $exp) = (zeroes(3,3), pdl('1;3;9'));
48+
is_pdl $base->slice('0')->inplace->ylogvals(1,9), $exp, 'inplace->logvals returns right';
49+
is_pdl $base->slice('0'), $exp, 'inplace->logvals updates input';
4450
}
4551

4652
{

0 commit comments

Comments
 (0)