docstr: Given a tensor-level `val`, calculate the chunk-level `val`.
  Consider both the cases that `val` could be a tensor or ndarray.
  
  :param val: tensor-level `val`
  :diag_idx: chunk index on the diagonal direction
  :cum_sizes: accumulative chunk sizes on the diagonal direction
docstr_tok: ["Given","a","tensor-level","`","val","`",",","calculate","the","chunk-level","`","val","`",".","Consider","both","the","cases","that","`","val","`","could","be","a","tensor","or","ndarray",".",":","param","val",":","tensor-level","`","val","`",":","diag_idx",":","chunk","index","on","the","diagonal","direction",":","cum_sizes",":","accumulative","chunk","sizes","on","the","diagonal","direction"]
code: def _gen_val(val, diag_idx, cum_sizes):
      """
      Given a tensor-level `val`, calculate the chunk-level `val`.
      Consider both the cases that `val` could be a tensor or ndarray.
  
      :param val: tensor-level `val`
      :diag_idx: chunk index on the diagonal direction
      :cum_sizes: accumulative chunk sizes on the diagonal direction
      """
      from .slice import TensorSlice
  
      if val.ndim == 0:
          if isinstance(val, TENSOR_TYPE):
              return val.chunks[0]
          else:
              return val
  
      if isinstance(val, TENSOR_TYPE):
          start, stop = cum_sizes[diag_idx], cum_sizes[diag_idx + 1]
          slc = slice(start, stop)
          slc_op = TensorSlice(slices=[slc], dtype=val.dtype)
          return slc_op.new_chunk(
              [val.chunks[0]],
              shape=(stop - start,),
              order=val.order,
              index=(diag_idx,),
          )
      else:
          return val[cum_sizes[diag_idx] : cum_sizes[diag_idx + 1]]
  
imports: import numpy
  from ...None import opcodes
  from ...core import ENTITY_TYPE, recursive_tile
  from ...serialization.serializables import KeyField, AnyField, BoolField, Int32Field
  from ...utils import has_unknown_shape, ceildiv
  from ..operands import TensorOperand, TensorOperandMixin
  from ..datasource import tensor
  from ..array_utils import as_same_device, device
  from ..core import Tensor, TENSOR_TYPE
  from ..utils import decide_unify_split
label_desc: Use image node_id 9 for calling the TensorFillDiagonal obj's underlying member method code with example usage: obj._gen_val(val, diag_idx, cum_sizes) and returns: slc_op, val, val, val