Skip to content

negative variance possible since 826ec949084d67926ca81292f575c8138f49ad9a #34

@shawnlaffan

Description

@shawnlaffan

Since commit 826ec94, PDL::Stats can return negative variance, and stdev of NA, for some cases due to floating point precision.

perl -MPDL -MPDL::Stats -E'my $x = pdl [(0.001) x 6]; say $x->var; say $x->stdv'
-1.41172157875717e-22
NaN

The easiest solution is to set the variance to zero when it is negative.

Unless there is a better way I'll prep a PR with tests in the next few days.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions