Does Perl PDL have an equivalent of Math::Round::nearest()?

Viewed 59

Does PDL already have a way to apply a "rounding" to the vector elements by some precision in the way that Math::Round::nearest() does? I've looked through the PDL::Math documentation but didn't see a good candidate option.

I could unpdl/re-pdl but that seems like too much overhead.

Is there already a vectorized way to do this?

I tried something like this:

$pdl = pdl [4.45, 5.55, 45];
$n = pdl [.1, .3, 10];
print rint($pdl/$n)*$n
[4.4 5.4 40]

but as as you can see it doesn't quite work because it should round up to the nearest precision. This would be the "correct" output:

[4.5 5.6 50]
1 Answers

Such a thing could be added, but would need to be specified a bit more clearly; what would it do with negative numbers? And how would it differ from floor / ceil / rint?

Related