(ll, type_hint)
| 17731 | throw new python.Error(`Unsupported constant type.`); |
| 17732 | } |
| 17733 | emitListLiteral(ll, type_hint) { |
| 17734 | type_hint = type_hint || null; |
| 17735 | const values = this.getValues(ll.elts, true); |
| 17736 | if (values.length === 0 && type_hint === null) { |
| 17737 | throw new python.Error('Not implemented.'); |
| 17738 | } |
| 17739 | let inferred_elem_type = torch.TensorType.get(); |
| 17740 | const refined_type_hint = { _: type_hint }; |
| 17741 | const annotated_union_type = refined_type_hint._ && refined_type_hint._.isUnionType() ? refined_type_hint._ : null; |
| 17742 | const all_candidates = { _: [] }; |
| 17743 | if (refined_type_hint._) { |
| 17744 | const do_if_type_match = () => { |
| 17745 | inferred_elem_type = refined_type_hint._.expect(torch.ListType).getElementType(); |
| 17746 | }; |
| 17747 | const type_match = (t) => t.isSubtypeOf(torch.Type.get('AnyListType')); |
| 17748 | this.refineAndSetUnionTypeHintOrPopulateCandidatesVector(type_hint, refined_type_hint, all_candidates, 'List', ll, type_match, do_if_type_match, do_if_type_match); |
| 17749 | if (all_candidates._.length > 0 && values.len === 0) { |
| 17750 | throw new python.Error('Cannot assign an empty list.'); |
| 17751 | } |
| 17752 | } |
| 17753 | if (values.length !== 0) { |
| 17754 | const types = values.map((v) => v.type()); |
| 17755 | const elem_type_hint = refined_type_hint._ && refined_type_hint._.kind() === 'ListType' ? refined_type_hint._.getElementType() : null; |
| 17756 | const unified_elem_type = torch._C.unifyTypeList(types, null /*nowhere*/, /*default_to_union=*/true, elem_type_hint); |
| 17757 | if (!refined_type_hint._ && unified_elem_type.kind() === 'UnionType') { |
| 17758 | throw new python.Error('Not implemented.'); |
| 17759 | } |
| 17760 | if (all_candidates._.length === 0 && refined_type_hint._ && !unified_elem_type.isSubtypeOf(inferred_elem_type)) { |
| 17761 | throw new python.Error('Not implemented.'); |
| 17762 | } |
| 17763 | if (all_candidates._.length !== 0) { |
| 17764 | this.refineAndSetListTypeHintFromCandidatesVector(all_candidates, type_hint, refined_type_hint._, unified_elem_type, ll); |
| 17765 | inferred_elem_type = refined_type_hint._.expect(torch.ListType).getElementType(); |
| 17766 | } |
| 17767 | if (!refined_type_hint._) { |
| 17768 | inferred_elem_type = unified_elem_type; |
| 17769 | } |
| 17770 | } |
| 17771 | let result = this.graph.insertNode(this.graph.createList(inferred_elem_type, values)); |
| 17772 | if (annotated_union_type) { |
| 17773 | const n = this.graph.insertNode(this.graph.create('prim::unchecked_cast', [result.output()])); |
| 17774 | n.output().setType(annotated_union_type); |
| 17775 | result = n; |
| 17776 | } |
| 17777 | return result.output(); |
| 17778 | } |
| 17779 | insertRefinements(loc, ref) { |
| 17780 | for (const r of ref.activeRefinements()) { |
| 17781 | const v = this.environment_stack.getVar(r.identifier(), loc); |
no test coverage detected