(index)
| 99 | return inp, outp |
| 100 | |
| 101 | def run_index(index): |
| 102 | inp, outp = get_param(cases, index) |
| 103 | inp_tensor = [make_tensor(inpi, network) for inpi in inp] |
| 104 | |
| 105 | if test_trace and not network: |
| 106 | copied_inp = inp_tensor.copy() |
| 107 | for symbolic in [False, True]: |
| 108 | traced_func = trace(symbolic=symbolic)(func) |
| 109 | |
| 110 | for _ in range(3): |
| 111 | traced_results = traced_func(*copied_inp, **kwargs) |
| 112 | check_results(traced_results, outp) |
| 113 | |
| 114 | dumped_func = trace(symbolic=True, capture_as_const=True)(func) |
| 115 | dumped_results = dumped_func(*copied_inp, **kwargs) |
| 116 | check_results(dumped_results, outp) |
| 117 | |
| 118 | file = io.BytesIO() |
| 119 | dump_info = dumped_func.dump(file) |
| 120 | file.seek(0) |
| 121 | |
| 122 | # arg_name has pattern arg_xxx, xxx is int value |
| 123 | def take_number(arg_name): |
| 124 | return int(arg_name.split("_")[-1]) |
| 125 | |
| 126 | input_names = dump_info[4] |
| 127 | inps_np = [i.numpy() for i in copied_inp] |
| 128 | input_names.sort(key=take_number) |
| 129 | inp_dict = dict(zip(input_names, inps_np)) |
| 130 | infer_cg = cgtools.GraphInference(file) |
| 131 | |
| 132 | # assume #outputs == 1 |
| 133 | loaded_results = list(infer_cg.run(inp_dict=inp_dict).values())[0] |
| 134 | check_results(loaded_results, outp, check_shape=False) # scalar info lost |
| 135 | |
| 136 | results = func(*inp_tensor, **kwargs) |
| 137 | check_results(results, outp, check_shape=(network is None)) |
| 138 | |
| 139 | if len(cases) == 0: |
| 140 | raise ValueError("should give one case at least") |
no test coverage detected