code: def test_ridge_regression(reg_lambda, use_woodbury, scale, bias):
      # Numpy
      num_classes = 3
      embeddings_np = np.random.randn(5, 7).astype(np.float32)
      targets_np = np.random.randint(0, num_classes, size=(5,))
  
      # PyTorch
      embeddings_th = torch.as_tensor(embeddings_np)
      targets_th = torch.as_tensor(targets_np)
      model = MetaLinear(7, 3, bias=bias)
  
      solution = ridge_regression(
          embeddings_th,
          targets_th,
          reg_lambda,
          num_classes,
          use_woodbury=use_woodbury,
          scale=scale,
          bias=bias,
      )
  
      assert solution.weight.shape == (3, 7)
      if bias:
          assert solution.bias is not None
          assert solution.bias.shape == (3,)
      else:
          assert solution.bias is None
  
      # Optimality criterion
      # Check if the gradient of the L2-regularized MSE at the solution
      # is close to 0
      params = OrderedDict(
          [("weight", solution.weight.requires_grad_())]
      )
      if bias:
          params["bias"] = solution.bias.requires_grad_()
  
      logits = model(embeddings_th, params=params)
      targets_binary = F.one_hot(
          targets_th, num_classes=num_classes
      ).float()
  
      # Least-square
      loss = F.mse_loss(logits, targets_binary, reduction="sum")
      if scale:
          loss /= embeddings_th.size(0)
  
      # L2-regularization
      loss += reg_lambda * torch.sum(solution.weight**2)
      if bias:
          loss += reg_lambda * torch.sum(solution.bias**2)
      loss.backward()
  
      np.testing.assert_allclose(
          solution.weight.grad.numpy(), 0.0, atol=1e-4
      )
      if bias:
          np.testing.assert_allclose(
              solution.bias.grad.numpy(), 0.0, atol=1e-4
          )
  
file_path: pytorch-meta/torchmeta/tests/utils/test_r2d2.py
imports: import pytest
  import numpy
  import torch
  import torch.nn.functional
  from collections import OrderedDict
  from torchmeta.modules import MetaLinear
  from torchmeta.utils.r2d2 import ridge_regression
label_desc: Use image node_id 1 for calling a global function with example usage: test_ridge_regression(reg_lambda, use_woodbury, scale, bias) without return types