parameters: (self, slice_index=None, shape=None, opt_shard_group=None)
return_statement: return self
docstring: Get the tensor format data of this Tensor.
          The init_data function can be called once for the same tensor.
  
          Args:
              slice_index (int): Slice index of a parameter's slices.
                  It is used when initialize a slice of a parameter, it guarantees that devices
                  using the same slice can generate the same tensor. Default: None.
              shape (list[int]): Shape of the slice, it is used when initialize a slice of the parameter. Default: None.
              opt_shard_group(str): Optimizer shard group which is used in auto or semi auto parallel mode
                  to get one shard of a parameter's slice. Default: None.
  
          Returns:
              Initialized Tensor.
  
          Supported Platforms:
              ``Ascend`` ``GPU`` ``CPU``
  
          Examples:
              >>> import mindspore as ms
              >>> import mindspore.common.initializer as init
              >>> x = init.initializer(init.Constant(1), [2, 2], ms.float32)
              >>> out = x.init_data()
              >>> print(out)
              [[1. 1.]
               [1. 1.]]
docstring_summary: Get the tensor format data of this Tensor.
          The init_data function can be called once for the same tensor.
docstring_tokens: Get the tensor format data of this Tensor . The init_data function can be called once for the same tensor .
function: def init_data(self, slice_index=None, shape=None, opt_shard_group=None):
          """
          Get the tensor format data of this Tensor.
          The init_data function can be called once for the same tensor.
  
          Args:
              slice_index (int): Slice index of a parameter's slices.
                  It is used when initialize a slice of a parameter, it guarantees that devices
                  using the same slice can generate the same tensor. Default: None.
              shape (list[int]): Shape of the slice, it is used when initialize a slice of the parameter. Default: None.
              opt_shard_group(str): Optimizer shard group which is used in auto or semi auto parallel mode
                  to get one shard of a parameter's slice. Default: None.
  
          Returns:
              Initialized Tensor.
  
          Supported Platforms:
              ``Ascend`` ``GPU`` ``CPU``
  
          Examples:
              >>> import mindspore as ms
              >>> import mindspore.common.initializer as init
              >>> x = init.initializer(init.Constant(1), [2, 2], ms.float32)
              >>> out = x.init_data()
              >>> print(out)
              [[1. 1.]
               [1. 1.]]
          """
          if self.init is None:
              raise TypeError("init_data must be set Tensor.init, init can't be None")
  
          if shape is None:
              shape = self.shape
  
          try:
              arr = np.ndarray(shape, dtype=mstype.dtype_to_nptype(self.dtype))
          except ValueError:
              msg = "Error shape={}".format(shape)
              logger.critical(msg)
              raise ValueError(msg)
  
          class seed_context:
              """Set and restore seed."""
  
              def __init__(self, init):
                  self.init = init
                  from .seed import get_seed
                  global_seed = get_seed()
                  self._np_seed = np.random.get_state()[1][0]
                  self.need_set_seed = ((slice_index is not None) and (global_seed is None))
  
              def __enter__(self):
                  if self.need_set_seed:
                      self.seed = self.init.seed
                      np.random.seed(slice_index)
                      self.init.seed = slice_index
  
              def __exit__(self, ptype, value, trace):
                  if self.need_set_seed:
                      np.random.seed(self._np_seed)
                      self.init.seed, _ = self.seed
  
          with seed_context(self.init):
              self.init(arr)
          data = np.array(arr)
          if opt_shard_group:
              rank = get_rank(opt_shard_group)
              size = get_group_size(opt_shard_group)
              data = np.split(data, size)[rank]
          self.init = None
          self.assign_value(Tensor(data, dtype=self.dtype))
          return self
function_tokens: def init_data ( self , slice_index = None , shape = None , opt_shard_group = None ) : if self . init is None : raise TypeError ( "init_data must be set Tensor.init, init can't be None" ) if shape is None : shape = self . shape try : arr = np . ndarray ( shape , dtype = mstype . dtype_to_nptype ( self . dtype ) ) except ValueError : msg = "Error shape={}" . format ( shape ) logger . critical ( msg ) raise ValueError ( msg ) class seed_context : """Set and restore seed.""" def __init__ ( self , init ) : self . init = init from . seed import get_seed global_seed = get_seed ( ) self . _np_seed = np . random . get_state ( ) [ 1 ] [ 0 ] self . need_set_seed = ( ( slice_index is not None ) and ( global_seed is None ) ) def __enter__ ( self ) : if self . need_set_seed : self . seed = self . init . seed np . random . seed ( slice_index ) self . init . seed = slice_index def __exit__ ( self , ptype , value , trace ) : if self . need_set_seed : np . random . seed ( self . _np_seed ) self . init . seed , _ = self . seed with seed_context ( self . init ) : self . init ( arr ) data = np . array ( arr ) if opt_shard_group : rank = get_rank ( opt_shard_group ) size = get_group_size ( opt_shard_group ) data = np . split ( data , size ) [ rank ] self . init = None self . assign_value ( Tensor ( data , dtype = self . dtype ) ) return self