



import os

import numpy
import onnx






def     __a					(		__UpperCAmelCase							,  __UpperCAmelCase       ):
 a__												= a.name
 a__												= b.name

 a__												= ''''''
 a__												= ''''''

 a__												= a == b

 a__												= name_a
 a__												= name_b

 return res






def     __a					(		__UpperCAmelCase							,  __UpperCAmelCase							,  __UpperCAmelCase       ):
 for i, input_name in enumerate(node_proto.input       ):
  if input_name == name:
   node_proto.input.insert(__UpperCAmelCase							,  __UpperCAmelCase       )
   node_proto.input.pop(i + 1       )

 if node_proto.op_type == "If":
  _graph_replace_input_with(node_proto.attribute[0].g							,  __UpperCAmelCase							,  __UpperCAmelCase       )
  _graph_replace_input_with(node_proto.attribute[1].g							,  __UpperCAmelCase							,  __UpperCAmelCase       )
 if node_proto.op_type == "Loop":
  _graph_replace_input_with(node_proto.attribute[0].g							,  __UpperCAmelCase							,  __UpperCAmelCase       )






def     __a					(		__UpperCAmelCase							,  __UpperCAmelCase							,  __UpperCAmelCase       ):
 for n in graph_proto.node:
  _node_replace_input_with(__UpperCAmelCase							,  __UpperCAmelCase							,  __UpperCAmelCase       )






def     __a					(		__UpperCAmelCase							,  __UpperCAmelCase							,  __UpperCAmelCase       ):
 a__												= list(model.graph.initializer       )
 a__												= list(model_without_ext.graph.initializer       )
 for i, ref_i in ind_to_replace:
  assert inits_with_data[i].name == inits[i].name
  assert inits_with_data[ref_i].name == inits[ref_i].name
  assert i > ref_i

  a__												= inits[i].name
  a__												= inits[ref_i].name

  model_without_ext.graph.initializer.remove(inits[i]       )

  # for n in model.graph.node:
  _graph_replace_input_with(model_without_ext.graph							,  __UpperCAmelCase							,  __UpperCAmelCase       )






def     __a					(		__UpperCAmelCase       ):
 a__												= os.path.dirname(__UpperCAmelCase       )
 a__												= os.path.basename(__UpperCAmelCase       )

 a__												= onnx.load(os.path.join(__UpperCAmelCase							,  __UpperCAmelCase       )       )

 a__												= list(model.graph.initializer       )

 a__												= set()
 a__												= {}
 a__												= []

 a__												= 0

 for i in range(len(__UpperCAmelCase       )       ):
  if i in dup_set:
   continue

  for j in range(i + 1							,  len(__UpperCAmelCase       )       ):
   if j in dup_set:
    continue
   if _is_equal_tensor_proto(inits[i]							,  inits[j]       ):
    dup_set.add(__UpperCAmelCase       )
    dup_set.add(__UpperCAmelCase       )

    a__												= inits[j].data_type
    a__												= numpy.prod(inits[j].dims       )
    if dtype == 1:
     mem_size *= 4
    elif dtype == 6:
     mem_size *= 4
    elif dtype == 7 or dtype == 11:
     mem_size *= 8
    else:
     print('''unexpected data type: '''							,  __UpperCAmelCase       )
    total_reduced_size += mem_size

    a__												= inits[i].name
    a__												= inits[j].name

    if name_i in dup_map:
     dup_map[name_i].append(__UpperCAmelCase       )
    else:
     a__												= [name_j]
    ind_to_replace.append((j, i)       )

 print('''total reduced size: '''							,  total_reduced_size / 1024 / 1024 / 1024							,  '''GB'''       )

 a__												= sorted(__UpperCAmelCase       )
 _remove_dup_initializers_from_model(__UpperCAmelCase							,  __UpperCAmelCase							,  __UpperCAmelCase       )

 a__												= '''optimized_''' + model_file_name
 a__												= os.path.join(__UpperCAmelCase							,  __UpperCAmelCase       )
 onnx.save(__UpperCAmelCase							,  __UpperCAmelCase       )

 return new_model










from __future__ import annotations

import requests






def     __a					(		__UpperCAmelCase       ):
 a__												= f"https://hacker-news.firebaseio.com/v0/item/{story_id}.json?print=pretty"
 return requests.get(__UpperCAmelCase       ).json()






def     __a					(		__UpperCAmelCase = 10       ):
 a__												= '''https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty'''
 a__												= requests.get(__UpperCAmelCase       ).json()[:max_stories]
 return [get_hackernews_story(__UpperCAmelCase       ) for story_id in story_ids]






def     __a					(		__UpperCAmelCase = 10       ):
 a__												= hackernews_top_stories(__UpperCAmelCase       )
 return "\n".join('''* [{title}]({url})'''.format(**__UpperCAmelCase       ) for story in stories       )


if __name__ == "__main__":
     print(hackernews_top_stories_as_markdown())





