Fixes draw_samples() shape when testset consists of exactly one sample#56
Conversation
…when the testset consists of exactly one sample * fixes draw_samples in distribution_utils.py, flow_utils.py, and mixture_distribution_utils.py
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
There was a problem hiding this comment.
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 explicitreshape(n_samples, -1).Tpattern 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 | |||
There was a problem hiding this comment.
The torch import is unused in this test file. Consider removing it to keep imports clean.
| import torch |
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