Skip to content

Fixes draw_samples() shape when testset consists of exactly one sample#56

Merged
StatMixedML merged 1 commit intoStatMixedML:masterfrom
nucflash:20251205-fix-draw_samples
Dec 9, 2025
Merged

Fixes draw_samples() shape when testset consists of exactly one sample#56
StatMixedML merged 1 commit intoStatMixedML:masterfrom
nucflash:20251205-fix-draw_samples

Conversation

@nucflash
Copy link

@nucflash nucflash commented Dec 6, 2025

Attempt to address #55

  • adds unit test that exposes in the output shape of drawing samples when the testset consists of exactly one sample

  • fixes draw_samples in distribution_utils.py, flow_utils.py, and mixture_distribution_utils.py

…when the testset consists of exactly one sample

* fixes draw_samples in distribution_utils.py, flow_utils.py, and mixture_distribution_utils.py
@StatMixedML
Copy link
Owner

@claude

@claude
Copy link

claude bot commented Dec 9, 2025

Claude encountered an error —— View job

Failed with exit code 128

I'll analyze this and get back to you.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a shape bug in the draw_samples() method that occurred when the test set contains exactly one observation. The issue stemmed from using .squeeze(), which removes all dimensions of size 1, causing shape (n_samples, 1) to collapse to (n_samples,) and breaking subsequent transpose operations.

Key Changes:

  • Replaced .squeeze() with explicit reshape(n_samples, -1).T pattern to preserve 2D structure
  • Added parametrized unit tests to verify correct behavior for both single (n_obs=1) and multiple (n_obs=5) observations
  • Applied consistent fix across all three distribution utility modules

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
tests/test_distribution_utils/test_draw_samples.py Added parametrized tests (n_obs=1 and n_obs=5) with shape validation assertions
lightgbmlss/distributions/distribution_utils.py Fixed shape handling by replacing .squeeze().T with .reshape(n_samples, -1).T
lightgbmlss/distributions/flow_utils.py Applied same reshape fix for flow-based distributions
lightgbmlss/distributions/mixture_distribution_utils.py Applied same reshape fix for mixture distributions
Comments suppressed due to low confidence (1)

tests/test_distribution_utils/test_draw_samples.py:1

  • Import of 'torch' is not used.
import torch

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -1,30 +1,46 @@
import torch
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

The torch import is unused in this test file. Consider removing it to keep imports clean.

Suggested change
import torch

Copilot uses AI. Check for mistakes.
@StatMixedML StatMixedML merged commit b728ff8 into StatMixedML:master Dec 9, 2025
8 of 10 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.

3 participants