(self, X, left_open, right_open, eps, ub, lb, gc, dc)
| 92 | **hu.gcs_cpu_only |
| 93 | ) |
| 94 | def test_bounded_grad_proj(self, X, left_open, right_open, eps, ub, lb, gc, dc): |
| 95 | if ub - (eps if right_open else 0.) < lb + (eps if left_open else 0.): |
| 96 | return |
| 97 | param = core.BlobReference("X") |
| 98 | workspace.FeedBlob(param, X) |
| 99 | train_init_net, train_net = self.get_training_nets() |
| 100 | reg = regularizer.BoundedGradientProjection( |
| 101 | lb=lb, ub=ub, left_open=left_open, right_open=right_open, epsilon=eps |
| 102 | ) |
| 103 | output = reg(train_net, train_init_net, param, by=RegularizationBy.ON_LOSS) |
| 104 | reg( |
| 105 | train_net, |
| 106 | train_init_net, |
| 107 | param, |
| 108 | grad=None, |
| 109 | by=RegularizationBy.AFTER_OPTIMIZER, |
| 110 | ) |
| 111 | workspace.RunNetOnce(train_init_net) |
| 112 | workspace.RunNetOnce(train_net) |
| 113 | |
| 114 | def ref(X): |
| 115 | return np.clip( |
| 116 | X, lb + (eps if left_open else 0.), ub - (eps if right_open else 0.) |
| 117 | ) |
| 118 | |
| 119 | assert output is None |
| 120 | npt.assert_allclose(workspace.blobs[param], ref(X), atol=1e-7) |
| 121 | |
| 122 | @given( |
| 123 | output_dim=st.integers(1, 10), |
nothing calls this directly
no test coverage detected