Skip to content

reject variance of an empty tensor - #60

Merged
CanReader merged 1 commit into
CanReader:masterfrom
Boulea7:fix/empty-variance-20261016
Oct 16, 2026
Merged

CanReader merged 1 commit into
CanReader:masterfrom
Boulea7:fix/empty-variance-20261016

Conversation

@Boulea7

@Boulea7 Boulea7 commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

What this changes

Tensor::variance() now panics with variance() of an empty tensor before reading the data when the tensor has no elements. Non-empty variance calculation is unchanged.

Why

Empty inputs previously returned NaN. This follows the requested caller-error behavior in #47.

Fixes #47.

How it was verified

The two empty-input tests failed on unmodified master because no panic occurred, then passed with the guard. Singleton and population-variance controls passed before and after the change.

  • cargo test --locked --offline passes (CPU tests and doctests)
  • cargo clippy --locked --offline --all-targets -- -D warnings is clean
  • cargo fmt --check passes

Run on Linux with Rust 1.99. GPU runtime, Rust 1.87, release mode, and other operating systems were not tested locally.

Checklist

  • Public items have /// docs
  • No backward rule, kernel, dependency, or public signature was changed.

@Boulea7
Boulea7 requested a review from CanReader as a code owner October 15, 2026 17:43

@CanReader CanReader left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your changes, assertion check is very important for error handling and I forgot to add it while writing function! I'll check other functions. Thank you for your contributions.

@CanReader
CanReader merged commit 79eca46 into CanReader:master Oct 16, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

variance() returns NaN for an empty tensor

2 participants