old_contents: import treeano
  
  
  def to_shared_dict(network):
      network.build()
      vws = network[network.root_node.name].find_vws_in_subtree(is_shared=True)
      name_to_shared = {}
      for vw in vws:
          assert vw.name not in name_to_shared
          name_to_shared[vw.name] = vw.variable
      return name_to_shared
  
  
  def to_value_dict(network):
      shared_dict = to_shared_dict(network)
      return {k: v.get_value() for k, v in shared_dict.items()}
  
  
  def load_value_dict(network,
                      value_dict,
                      strict_keys=True,
                      ignore_different_shape=False):
      shared_dict = to_shared_dict(network)
      value_keys = set(value_dict.keys())
      network_keys = set(shared_dict.keys())
      if strict_keys:
          assert value_keys == network_keys
          keys = value_keys
      else:
          keys = set(value_dict.keys()) & set(shared_dict.keys())
      for k in keys:
          shared = shared_dict[k]
          old_val = shared.get_value()
          new_val = value_dict[k]
          if ignore_different_shape:
              if old_val.shape != new_val.shape:
                  continue
          else:
              assert old_val.shape == new_val.shape
          shared.set_value(new_val)
  
  
  def to_preallocated_init(network):
      return treeano.inits.PreallocatedInit(to_shared_dict(network))
  
new_contents: from __future__ import division, absolute_import
  from __future__ import print_function, unicode_literals
  import treeano
  
  
  def to_shared_dict(network):
      network.build()
      vws = network[network.root_node.name].find_vws_in_subtree(is_shared=True)
      name_to_shared = {}
      for vw in vws:
          assert vw.name not in name_to_shared
          name_to_shared[vw.name] = vw.variable
      return name_to_shared
  
  
  def to_value_dict(network):
      shared_dict = to_shared_dict(network)
      return {k: v.get_value() for k, v in shared_dict.items()}
  
  
  def load_value_dict(network,
                      value_dict,
                      strict_keys=True,
                      ignore_different_shape=False):
      shared_dict = to_shared_dict(network)
      value_keys = set(value_dict.keys())
      network_keys = set(shared_dict.keys())
      if strict_keys:
          assert value_keys == network_keys
          keys = value_keys
      else:
          keys = set(value_dict.keys()) & set(shared_dict.keys())
  
      loaded = 0
      for k in keys:
          shared = shared_dict[k]
          old_val = shared.get_value()
          new_val = value_dict[k]
          if ignore_different_shape:
              if old_val.shape != new_val.shape:
                  continue
          else:
              assert old_val.shape == new_val.shape
          shared.set_value(new_val)
          loaded += 1
      print("loaded %d keys of value dict")
  
  
  def to_preallocated_init(network):
      return treeano.inits.PreallocatedInit(to_shared_dict(network))
  
subject: print number of keys loaded