class_docstr: Change of Basis class.
docstr: Apply a change of basis to a tensor.
  
  Args:
      tensor (torch.Tensor): Tensor to apply the change of basis to.
      return_basis (bool, optional): Whether to return the change of
      basis matrix as well.
code: def __call__(self, tensor: torch.Tensor, return_basis: bool = False):
      """Apply a change of basis to a tensor.
  
      Args:
          tensor (torch.Tensor): Tensor to apply the change of basis to.
          return_basis (bool, optional): Whether to return the change of
          basis matrix as well.
      """
      cob_prob = torch.rand(1).item()
      if cob_prob > self.cob_prob:
          return tensor
      random_cob = torch.randint(low=0, high=self.n_cob, size=(1,))
      cob_matrix = torch.load(
          f"{self.tmp_dir}/cob_matrix_{int(random_cob)}.pt"
      ).to(self.device)
  
      # apply change of basis to each tensor dimension
      inner_tensor = tensor[0, 0]
      tensor_size = inner_tensor.shape[-1]
      original_shape = inner_tensor.shape
      cob_matrix = cob_matrix.transpose(0, 1)
      inner_tensor = torch.matmul(
          inner_tensor.reshape(-1, tensor_size), cob_matrix
      ).reshape(original_shape)
      inner_tensor = inner_tensor.permute(0, 2, 1)
      inner_tensor = torch.matmul(
          inner_tensor.reshape(-1, tensor_size), cob_matrix
      ).reshape(original_shape)
      inner_tensor = inner_tensor.permute(2, 1, 0)
      inner_tensor = torch.matmul(
          inner_tensor.reshape(-1, tensor_size), cob_matrix
      ).reshape(original_shape)
      inner_tensor = inner_tensor.permute(2, 0, 1)
      tensor[0, 0] = inner_tensor
      if return_basis:
          return tensor, cob_matrix.transpose(0, 1)
      return tensor
  
file_path: nebuly/optimization/open_alpha_tensor/open_alpha_tensor/core/data/basis_change.py
imports: from pathlib import Path
  from typing import Callable
  import numpy
  import torch
label_desc: Use image node_id 2 for calling the ChangeOfBasis obj's underlying member method code with example usage: obj.__call__(tensor, return_basis) and returns: tensor, tensor, tensor,  cob_matrix