code: 
  '''simple docstring'''
  
  from typing import Any, Dict, List, Mapping
  
  import numpy as np
  import torch
  
  from ...utils import is_cython_available, requires_backends
  
  
  if is_cython_available():
        import pyximport
  
        pyximport.install(setup_args={"""include_dirs""": np.get_include()})
        from . import algos_graphormer  # noqa E402
  
  
  def 	_UpperCAmelCase				(  _lowerCamelCase						:       Optional[int]  ,      _lowerCamelCase						:       int = 5_12		)    ->						Dict:
    _lowerCAmelCase       :  List[Any]   				=					x.shape[1] if len(x.shape		) > 1 else 1
    _lowerCAmelCase       :  int   				=					1 + np.arange(0  ,      feature_num * offset  ,      _lowerCamelCase  ,      dtype=np.intaa		)
    _lowerCAmelCase       :  Tuple   				=					x + feature_offset
    return x
  
  
  def 	_UpperCAmelCase				(  _lowerCamelCase						:       Optional[int]  ,      _lowerCamelCase						:       int=True		)    ->						Optional[int]:
    requires_backends(_lowerCamelCase  ,      ["""cython"""]		)
  
    if keep_features and "edge_attr" in item.keys():  # edge_attr
      _lowerCAmelCase       :  Tuple   				=					np.asarray(item["""edge_attr"""]  ,      dtype=np.intaa		)
    else:
      _lowerCAmelCase       :  Tuple   				=					np.ones((len(item["""edge_index"""][0]		), 1)  ,      dtype=np.intaa		)  # same embedding for all
  
    if keep_features and "node_feat" in item.keys():  # input_nodes
      _lowerCAmelCase       :  Dict   				=					np.asarray(item["""node_feat"""]  ,      dtype=np.intaa		)
    else:
      _lowerCAmelCase       :  Optional[int]   				=					np.ones((item["""num_nodes"""], 1)  ,      dtype=np.intaa		)  # same embedding for all
  
    _lowerCAmelCase       :  str   				=					np.asarray(item["""edge_index"""]  ,      dtype=np.intaa		)
  
    _lowerCAmelCase       :  str   				=					convert_to_single_emb(_lowerCamelCase		) + 1
    _lowerCAmelCase       :  Tuple   				=					item["""num_nodes"""]
  
    if len(edge_attr.shape		) == 1:
      _lowerCAmelCase       :  Tuple   				=					edge_attr[:, None]
    _lowerCAmelCase       :  List[str]   				=					np.zeros([num_nodes, num_nodes, edge_attr.shape[-1]]  ,      dtype=np.intaa		)
    _lowerCAmelCase       :  Any   				=					convert_to_single_emb(_lowerCamelCase		) + 1
  
    # node adj matrix [num_nodes, num_nodes] bool
    _lowerCAmelCase       :  str   				=					np.zeros([num_nodes, num_nodes]  ,      dtype=_lowerCamelCase		)
    _lowerCAmelCase       :  int   				=					True
  
    _lowerCAmelCase       :  Union[str, Any]   				=					algos_graphormer.floyd_warshall(_lowerCamelCase		)
    _lowerCAmelCase       :  List[str]   				=					np.amax(_lowerCamelCase		)
  
    _lowerCAmelCase       :  Tuple   				=					algos_graphormer.gen_edge_input(_lowerCamelCase  ,      _lowerCamelCase  ,      _lowerCamelCase		)
    _lowerCAmelCase       :  Tuple   				=					np.zeros([num_nodes + 1, num_nodes + 1]  ,      dtype=np.single		)  # with graph token
  
    # combine
    _lowerCAmelCase       :  Optional[int]   				=					input_nodes + 1  # we shift all indices by one for padding
    _lowerCAmelCase       :  int   				=					attn_bias
    _lowerCAmelCase       :  Dict   				=					attn_edge_type
    _lowerCAmelCase       :  Tuple   				=					shortest_path_result.astype(np.intaa		) + 1  # we shift all indices by one for padding
    _lowerCAmelCase       :  str   				=					np.sum(_lowerCamelCase  ,      axis=1		).reshape(-1		) + 1  # we shift all indices by one for padding
    _lowerCAmelCase       :  Any   				=					item["""in_degree"""]  # for undirected graph
    _lowerCAmelCase       :  str   				=					input_edges + 1  # we shift all indices by one for padding
    if "labels" not in item:
      _lowerCAmelCase       :  Tuple   				=					item["""y"""]
  
    return item
  
  
  
  class   a_  :
  
  
  
  
         def __init__(     self   ,   snake_case_=2_0   ,   snake_case_=False  ):
           if not is_cython_available():
             raise ImportError("""Graphormer preprocessing needs Cython (pyximport)"""  )
  
           _lowerCAmelCase       :  Union[str, Any]   				=					spatial_pos_max
           _lowerCAmelCase       :  Tuple   				=					on_the_fly_processing
  
  
  
  
  
  
  
         def __call__(     self   ,   snake_case_  ):
           if self.on_the_fly_processing:
             _lowerCAmelCase       :  Any   				=					[preprocess_item(snake_case_  ) for i in features]
  
           if not isinstance(features[0]   ,   snake_case_  ):
             _lowerCAmelCase       :  int   				=					[vars(snake_case_  ) for f in features]
           _lowerCAmelCase       :  Union[str, Any]   				=					{}
  
           _lowerCAmelCase       :  str   				=					max(len(i["""input_nodes"""]  ) for i in features  )
           _lowerCAmelCase       :  Tuple   				=					len(features[0]["""input_nodes"""][0]  )
           _lowerCAmelCase       :  Optional[int]   				=					len(features[0]["""attn_edge_type"""][0][0]  )
           _lowerCAmelCase       :  int   				=					max(len(i["""input_edges"""][0][0]  ) for i in features  )
           _lowerCAmelCase       :  Tuple   				=					len(features[0]["""input_edges"""][0][0][0]  )
           _lowerCAmelCase       :  Tuple   				=					len(snake_case_  )
  
           _lowerCAmelCase       :  List[Any]   				=					torch.zeros(snake_case_   ,   max_node_num + 1   ,   max_node_num + 1   ,   dtype=torch.float  )
           _lowerCAmelCase       :  Optional[int]   				=					torch.zeros(snake_case_   ,   snake_case_   ,   snake_case_   ,   snake_case_   ,   dtype=torch.long  )
           _lowerCAmelCase       :  Optional[int]   				=					torch.zeros(snake_case_   ,   snake_case_   ,   snake_case_   ,   dtype=torch.long  )
           _lowerCAmelCase       :  Optional[Any]   				=					torch.zeros(snake_case_   ,   snake_case_   ,   dtype=torch.long  )
           _lowerCAmelCase       :  Any   				=					torch.zeros(snake_case_   ,   snake_case_   ,   snake_case_   ,   dtype=torch.long  )
           _lowerCAmelCase       :  Dict   				=					torch.zeros(
               snake_case_   ,   snake_case_   ,   snake_case_   ,   snake_case_   ,   snake_case_   ,   dtype=torch.long  )
  
           for ix, f in enumerate(snake_case_  ):
             for k in ["attn_bias", "attn_edge_type", "spatial_pos", "in_degree", "input_nodes", "input_edges"]:
               _lowerCAmelCase       :  Dict   				=					torch.tensor(f[k]  )
  
             if len(f["""attn_bias"""][1:, 1:][f["""spatial_pos"""] >= self.spatial_pos_max]  ) > 0:
               _lowerCAmelCase       :  List[Any]   				=					float("""-inf"""  )
  
             _lowerCAmelCase       :  Union[str, Any]   				=					f["""attn_bias"""]
             _lowerCAmelCase       :  Any   				=					f[
                 """attn_edge_type"""
             ]
             _lowerCAmelCase       :  Tuple   				=					f["""spatial_pos"""]
             _lowerCAmelCase       :  Any   				=					f["""in_degree"""]
             _lowerCAmelCase       :  Optional[int]   				=					f["""input_nodes"""]
             _lowerCAmelCase       :  str   				=					f["""input_edges"""]
  
           _lowerCAmelCase       :  Tuple   				=					batch["""in_degree"""]
  
           _lowerCAmelCase       :  List[str]   				=					features[0]["""labels"""]
           if len(snake_case_  ) == 1:  # one task
             if isinstance(sample[0]   ,   snake_case_  ):  # regression
               _lowerCAmelCase       :  Optional[Any]   				=					torch.from_numpy(np.concatenate([i["""labels"""] for i in features]  )  )
             else:  # binary classification
               _lowerCAmelCase       :  Any   				=					torch.from_numpy(np.concatenate([i["""labels"""] for i in features]  )  )
           else:  # multi task classification, left to float to keep the NaNs
             _lowerCAmelCase       :  Optional[Any]   				=					torch.from_numpy(np.stack([i["""labels"""] for i in features]   ,   axis=0  )  )
  
           return batch
  
  
  
style_context: 
  '''simple docstring'''
  
  from typing import TYPE_CHECKING
  
  from ...utils import (
      OptionalDependencyNotAvailable,
      _LazyModule,
      is_flax_available,
      is_tf_available,
      is_torch_available,
  )
  
  
  UpperCamelCase_     			=       {
      """configuration_gptsan_japanese""": ["""GPTSAN_JAPANESE_PRETRAINED_CONFIG_ARCHIVE_MAP""", """GPTSanJapaneseConfig"""],
      """tokenization_gptsan_japanese""": ["""GPTSanJapaneseTokenizer"""],
  }
  
  try:
       if not is_torch_available():
            raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
       pass
  else:
       UpperCamelCase_     			=       [
           """GPTSAN_JAPANESE_PRETRAINED_MODEL_ARCHIVE_LIST""",
           """GPTSanJapaneseForConditionalGeneration""",
           """GPTSanJapaneseModel""",
           """GPTSanJapanesePreTrainedModel""",
       ]
       UpperCamelCase_     			=       [
           """GPTSanJapaneseTokenizer""",
       ]
  
  
  if TYPE_CHECKING:
       from .configuration_gptsan_japanese import GPTSAN_JAPANESE_PRETRAINED_CONFIG_ARCHIVE_MAP, GPTSanJapaneseConfig
       from .tokenization_gptsan_japanese import GPTSanJapaneseTokenizer
  
       try:
            if not is_torch_available():
                 raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
            pass
       else:
            from .modeling_gptsan_japanese import (
                GPTSAN_JAPANESE_PRETRAINED_MODEL_ARCHIVE_LIST,
                GPTSanJapaneseForConditionalGeneration,
                GPTSanJapaneseModel,
                GPTSanJapanesePreTrainedModel,
            )
            from .tokenization_gptsan_japanese import GPTSanJapaneseTokenizer
  
  
  else:
       import sys
  
       UpperCamelCase_     			=       _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)
  
  
  