code: def setup(self, optimize=False):
      if optimize:
          for func in list(self.functions.values()):
              # remove identity layer
              if (
                  func.function_instance.name[0:8] == "Identity"
                  and not func.persistent
              ):
                  assert len(func.inputs) == 1
                  assert len(func.outputs) == 1
                  # if the identity function is not terminal (keep terminal
                  # identity function)
                  if func.outputs[0] in self.variable_outputs:
                      next_functions = self.variable_outputs[
                          func.outputs[0]
                      ]
                      self.variable_outputs[func.inputs[0]].remove(func)
                      self.variable_outputs[func.inputs[0]].extend(
                          next_functions
                      )
                      for next_function in next_functions:
                          next_function.inputs = [
                              func.inputs[0]
                              if v == func.outputs[0]
                              else v
                              for v in next_function.inputs
                          ]
                      del self.functions[func.name]
                      del self.variables[func.outputs[0].name]
  
      # create variable instances
      for variable in self.variables.values():
          if variable.variable_instance.shape != variable.shape:
              if hasattr(variable.variable_instance, "reset_shape"):
                  variable.variable_instance.reset_shape(
                      variable.shape, force=True
                  )
              else:
                  variable.variable_instance.reshape(
                      variable.shape, force=True
                  )
  
      # setup functions
      for i, func in enumerate(self.functions.values()):
          func.variable_inputs = [
              v.variable_instance for v in func.inputs
          ]
          func.variable_outputs = [
              v.variable_instance for v in func.outputs
          ]
          try:
              self.setup_function(func)
          except:
              print_network_traceback(
                  list(self.functions.values())[max(0, i - 4) : i + 1]
              )
              raise
  
      # set link structure to each layer
      from itertools import chain
  
      for func in self.functions.values():
          func.input_functions = list(
              chain.from_iterable(
                  [
                      self.variable_inputs[v]
                      for v in func.inputs
                      if v in self.variable_inputs
                  ]
              )
          )
          func.output_functions = list(
              chain.from_iterable(
                  [
                      self.variable_outputs[v]
                      for v in func.outputs
                      if v in self.variable_outputs
                  ]
              )
          )
          logger.debug(func.name)
          logger.debug(
              "  in: {}".format([f.name for f in func.input_functions])
          )
          logger.debug(
              " out: {}".format([f.name for f in func.output_functions])
          )
  
file_path: nnabla/python/test/core/legacy_network.py
imports: from nnabla.logger import logger
  import nnabla.function
label_desc: Use image node_id 11 for calling the Network obj's underlying member method code with example usage: obj.setup(optimize) without return types