code: def is_legal(v):
      """
      Checks that tensor is not NaN or Inf.
  
      Inputs:
          v (tensor): tensor to be checked
  
      """
      legal = not torch.isnan(v).any() and not torch.isinf(v)
  
      return legal
  
imports: from copy import deepcopy
  from functools import reduce
  import matplotlib.pyplot
  import numpy
  import torch
  from torch.optim import Optimizer
label_desc: Use image node_id 1 for calling a global function with example usage: is_legal(v) and returns: legal