Fix: ensure step sizes and tau are passed as scalars - #263
Conversation
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
|
@claude review |
|
Claude finished @mrava87's task in 3m 5s —— View job Claude finished reviewing
SummaryThe core fix is correct: Findings1. The constant-scalar ( In all four places touched by this PR, the fix is only applied in the
e.g. if self.tau.ndim == 0:
tau = self.tau # still a 0-d (cupy) array
else:
tau = self.tau[self.iiter].item() # python scalarSince This matters because at least one other proximal operator multiplies
If tau = self.tau.item() if self.tau.ndim == 0 else self.tau[self.iiter].item()2. (Minor, unconfirmed)
Nitpicks
I was not able to run the test suite or a GPU/CuPy environment in this sandbox to confirm the failure mode directly (no cupy tests exist in |
|
@claude review again |
|
Claude finished @mrava87's task in 2m 38s —— View job Todo List
SummaryCommit
Good follow-up — thanks for addressing both. New finding
Unlike
If Suggested fix: extract a scalar Nitpicks
I was not able to run the test suite or a GPU/CuPy environment in this sandbox to reproduce the failure directly; the finding above is based on static tracing of how |
|
@claude one more review |
|
Claude finished @mrava87's task in 2m 57s —— View job Todo List
SummaryCommit New finding
ztmp = proxg.prox(
ztmp, self.tau * self.epsg[i].item() / self.weights[i].item()
)
...
x += self.weights[i].item() * self.zs[i]
This is a regression that would surface on plain NumPy/CPU as well as GPU, whenever Suggested fix: normalize Nitpicks
Note: I don't have a Python execution environment available in this sandbox (all |
|
@claude review again |
|
Claude finished @mrava87's task in 1m 48s —— View job Todo List
SummaryAll previously-reported
Remaining finding
The latest commit ( self.weights = (
np.ones(len(proxgs)) / len(proxgs) if weights is None else weights
)
if len(self.weights) != len(self.proxgs) or np.sum(self.weights) != 1.0:
...Any caller who follows the (pre-existing) type hint Suggested fix: normalize once at setup time, matching how self.weights = self.ncp.asarray(
np.ones(len(proxgs)) / len(proxgs) if weights is None else weights,
dtype=np.float32,
)This removes the need for defensive Nitpicks
I was not able to run the test suite or a GPU/CuPy environment in this sandbox (no interactive Python execution available), so the finding above is based on static tracing of |
This PR fixes a bug identified when running various solvers in GPU/CuPy mode. Whilst in NumPy mode it is possible to multiply a 1-element np.ndarray (aka scalar array) to an operator, this is not possible in CuPy mode due to the internal CuPy mul failing to cover this scenario:
This is fixed both at solver level (ensuring
.item()is calling when extracting a value for tau or step size from an iteration-dependent array) and inL2usingmath.sqrtinstead ofnp.sqrtas the latter repromotes a 1d array also when the input is a float.