class_docstr: Tests for :mod:`pykeen.utils`.
class_docstr_tok: ["Tests","for",":","mod",":","`","pykeen.utils","`","."]
docstr: Test  clamp_norm() .
docstr_tok: ["Test","clamp_norm","(",")","."]
code: def test_clamp_norm(self):
      """Test  clamp_norm() ."""
      max_norm = 1.0
      gen = torch.manual_seed(42)
      eps = 1.0e-06
      for p in [1, 2, float("inf")]:
          for _ in range(10):
              x = torch.rand(10, 20, 30, generator=gen)
              for dim in range(x.ndimension()):
                  x_c = clamp_norm(x, maxnorm=max_norm, p=p, dim=dim)
  
                  # check maximum norm constraint
                  assert (
                      x_c.norm(p=p, dim=dim) <= max_norm + eps
                  ).all()
  
                  # unchanged values for small norms
                  norm = x.norm(p=p, dim=dim)
                  mask = torch.stack(
                      [(norm < max_norm)] * x.shape[dim], dim=dim
                  )
                  assert (x_c[mask] == x[mask]).all()
  
imports: import functools
  import itertools
  import operator
  import random
  import string
  import timeit
  import unittest
  from typing import Iterable, Tuple
  import numpy
  import pytest
  import torch
  from pykeen.utils import _weisfeiler_lehman_iteration, _weisfeiler_lehman_iteration_approx, calculate_broadcasted_elementwise_result_shape, clamp_norm, combine_complex, compact_mapping, compose, estimate_cost_of_sequence, flatten_dictionary, get_optimal_sequence, get_until_first_blank, iter_weisfeiler_lehman, logcumsumexp, project_entity, set_random_seed, split_complex, tensor_product, tensor_sum
label_desc: Use image node_id 2 for calling the TestUtils obj's underlying member method code with example usage: obj.test_clamp_norm() without return types