diff --git a/Basic/Core/Basic.pm b/Basic/Core/Basic.pm index 38df87aed..7ec8aaa9f 100644 --- a/Basic/Core/Basic.pm +++ b/Basic/Core/Basic.pm @@ -153,6 +153,7 @@ etc. see L. =for ref X axis values between endpoints (see L). +Works with dim-length of one as of 2.093. =for usage @@ -188,6 +189,7 @@ See L for more information. =for ref X axis values logarithmically spaced between endpoints (see L). +Works with dim-length of one as of 2.093. =for usage @@ -241,12 +243,12 @@ sub PDL::zvals { sub _dimcheck { my ($pdl, $whichdim, $name) = @_; my $dim = $pdl->getdim($whichdim); - barf "Must have at least two elements in dimension for $name" if $dim <= 1; + barf "Must have at least one element in dimension for $name" if $dim < 1; $dim; } sub _linvals { my ($pdl, $v1, $v2, $dim, $method) = @_; - $pdl->$method * (($v2 - $v1) / ($dim-1)) + $v1; + $pdl->$method * (($v2 - $v1) / ($dim > 1 ? ($dim-1) : 1)) + $v1; } sub PDL::xlinvals { _linvals(@_[0..2], _dimcheck($_[0], 0, 'xlinvals'), 'xvals'); @@ -262,7 +264,7 @@ sub _logvals { my ($pdl, $min, $max, $dim, $method) = @_; barf "min and max must be positive" if $min <= 0 || $max <= 0; my ($lmin,$lmax) = map log($_), $min, $max; - exp($pdl->$method * (($lmax - $lmin) / ($dim-1)) + $lmin); + exp($pdl->$method * (($lmax - $lmin) / ($dim > 1 ? ($dim-1) : 1)) + $lmin); } sub PDL::xlogvals { _logvals(@_[0..2], _dimcheck($_[0], 0, 'xlogvals'), 'xvals'); diff --git a/Changes b/Changes index 6bf1c08f6..bbb1de67e 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,5 @@ +- [xyz]{lin,log}vals now works with dim-length of one + 2.092 2024-09-07 - add Type::howbig - restore ABI (https://github.com/moocow-the-bovine/PDL-VectorValued/issues/10 https://github.com/PDLPorters/PDL-Stats/issues/33) - thanks @sebastic for report diff --git a/t/basic.t b/t/basic.t index 6c181375b..e79e77e00 100644 --- a/t/basic.t +++ b/t/basic.t @@ -46,6 +46,10 @@ ok(tapprox($z->mv(2,0)->uniqvec->flat,pdl(0..25)/5-3),"zlinvals values"); #12 $a1->inplace->xvals; my $got = $a1->slice('(10),(0),(0)'); ok tapprox($got, 10), 'inplace xvals works' or diag "got:$got"; +eval { zeroes(1)->xlinvals(5,10) }; +is $@, '', 'can have dim-length of one *linvals'; +eval { zeroes(0)->xlinvals(5,10) }; +like $@, qr/at least one/, 'cannot have zero-length dim *linvals'; } { @@ -59,6 +63,10 @@ ok(all($x->shape==$zl->shape),"zlogvals shape"); #15 ok(tapprox($xl->uniqvec->flat->log10,pdl(2..12)),"xlogvals values"); #16 ok(tapprox($yl->mv(1,0)->uniqvec->flat->log10,pdl(-3..2)),"ylogvals values"); #17 ok(tapprox($zl->mv(2,0)->uniqvec->flat->log10,pdl(-10..-3)),"zlogvals values");#18 +eval { zeroes(1)->xlogvals(5,10) }; +is $@, '', 'can have one-element *logvals'; +eval { zeroes(0)->xlogvals(5,10) }; +like $@, qr/at least one/, 'cannot have zero-element *logvals'; } #test axisvals my $z = axisvals(zeroes(3,4,5,6),3);