def test_view_setattr_machinery(attr, subset_func, subset_func2):
    # Tests that setting attributes on a view doesn't mess anything up too bad
    adata = gen_adata((10, 10))
    view = adata[subset_func(adata.obs_names), subset_func2(adata.var_names)]

    actual = view.copy()
    setattr(view, attr, getattr(actual, attr))
    assert_equal(actual, view, exact=True)
def _compute_reg_grads(gen_grads, disc_vars):
  """Compute gradients norm (this is an upper-bpund of the full-batch norm)."""
  gen_norm = tf.accumulate_n([tf.reduce_sum(u * u) for u in gen_grads])
  disc_reg_grads = tf.gradients(gen_norm, disc_vars)
  return disc_reg_grads