code: def diffuse(normals, color, direction) -> torch.Tensor:
      """
      Calculate the diffuse component of light reflection using Lambert's
      cosine law.
  
      Args:
          normals: (N, ..., 3) xyz normal vectors. Normals and points are
              expected to have the same shape.
          color: (1, 3) or (N, 3) RGB color of the diffuse component of the light.
          direction: (x,y,z) direction of the light
  
      Returns:
          colors: (N, ..., 3), same shape as the input points.
  
      The normals and light direction should be in the same coordinate frame
      i.e. if the points have been transformed from world -> view space then
      the normals and direction should also be in view space.
  
      NOTE: to use with the packed vertices (i.e. no batch dimension) reformat the
      inputs in the following way.
  
      .. code-block:: python
  
          Args:
              normals: (P, 3)
              color: (N, 3)[batch_idx, :] -> (P, 3)
              direction: (N, 3)[batch_idx, :] -> (P, 3)
  
          Returns:
              colors: (P, 3)
  
          where batch_idx is of shape (P). For meshes, batch_idx can be:
          meshes.verts_packed_to_mesh_idx() or meshes.faces_packed_to_mesh_idx()
          depending on whether points refers to the vertex coordinates or
          average/interpolated face coordinates.
      """
      # TODO: handle multiple directional lights per batch element.
      # TODO: handle attenuation.
  
      # Ensure color and location have same batch dimension as normals
      normals, color, direction = convert_to_tensors_and_broadcast(
          normals, color, direction, device=normals.device
      )
  
      # Reshape direction and color so they have all the arbitrary intermediate
      # dimensions as normals. Assume first dim = batch dim and last dim = 3.
      points_dims = normals.shape[1:-1]
      expand_dims = (-1,) + (1,) * len(points_dims) + (3,)
      if direction.shape != normals.shape:
          direction = direction.view(expand_dims)
      if color.shape != normals.shape:
          color = color.view(expand_dims)
  
      # Renormalize the normals in case they have been interpolated.
      # We tried to replace the following with F.cosine_similarity, but it wasn't faster.
      normals = F.normalize(normals, p=2, dim=-1, eps=1e-6)
      direction = F.normalize(direction, p=2, dim=-1, eps=1e-6)
      angle = F.relu(torch.sum(normals * direction, dim=-1))
      return color * angle[..., None]
  
imports: import torch
  import torch.nn.functional
  from ..common.datatypes import Device
  from .utils import convert_to_tensors_and_broadcast, TensorProperties
label_desc: Use image node_id 1 for calling a global function with example usage: diffuse(normals, color, direction) and returns: unknown