(subscript, type_hint)
| 17955 | return this.emitSlice(loc, sliceable, maybe_dim, slice_exp); |
| 17956 | } |
| 17957 | emitSubscript(subscript, type_hint) { |
| 17958 | type_hint = type_hint === undefined ? null : type_hint; |
| 17959 | const sv = this.emitSugaredExpr(subscript.value, 1); |
| 17960 | const subscript_exprs = subscript.slice; |
| 17961 | const range = subscript.range(); |
| 17962 | const val_range = subscript.value; |
| 17963 | if (subscript_exprs instanceof ast.Tuple) { |
| 17964 | return new torch._C.SimpleValue(this.emitMultidimSlicing(range, sv.asValue(val_range, this.method), subscript_exprs)); |
| 17965 | } |
| 17966 | if (subscript_exprs instanceof ast.Slice) { |
| 17967 | if (sv.kind() === 'module') { |
| 17968 | const s_tuple_val = sv.asTupleValue(val_range, this.method).asValue(val_range, this.method); |
| 17969 | const [slice] = subscript_exprs; |
| 17970 | const tuple_args = []; |
| 17971 | if (slice.start().present()) { |
| 17972 | const begin = new torch._C.NamedValue(val_range, 'begin', this.emitExpr(slice.start().get())); |
| 17973 | tuple_args.push(begin); |
| 17974 | } else { |
| 17975 | tuple_args.push(null); |
| 17976 | } |
| 17977 | if (slice.end().present()) { |
| 17978 | const end = new torch._C.NamedValue(val_range, 'end', this.emitExpr(slice.end().get())); |
| 17979 | tuple_args.push(end); |
| 17980 | } else { |
| 17981 | tuple_args.push(null); |
| 17982 | } |
| 17983 | if (slice.step().present()) { |
| 17984 | const step = new torch._C.NamedValue(val_range, 'step', this.emitExpr(slice.step().get())); |
| 17985 | tuple_args.push(step); |
| 17986 | } else { |
| 17987 | tuple_args.push(null); |
| 17988 | } |
| 17989 | const tupleSliceValue = this.emitTupleSlice(val_range, s_tuple_val, tuple_args); |
| 17990 | return new torch._C.SimpleValue(tupleSliceValue); |
| 17991 | } |
| 17992 | return new torch._C.SimpleValue(this.emitBasicSlice(range, sv.asValue(val_range, this.method), subscript_exprs)); |
| 17993 | } |
| 17994 | const sliceable = sv.asValue(val_range, this.method); |
| 17995 | const subscript_sv = this.emitSugaredExpr(subscript_exprs, 1); |
| 17996 | if (subscript_sv instanceof torch._C.SliceValue) { |
| 17997 | const slice_value = subscript_sv; |
| 17998 | let dim = null; |
| 17999 | if (sliceable.type().isSubtypeOf(torch.TensorType.get())) { |
| 18000 | dim = this.method.graph().insertConstant(0, val_range); |
| 18001 | } |
| 18002 | const sliced = this.emitSliceOp(val_range, sliceable, dim, slice_value.start(), slice_value.stop(), slice_value.step()); |
| 18003 | return new torch._C.SimpleValue(sliced); |
| 18004 | } |
| 18005 | const idx = subscript_sv.asValue(val_range, this.method); |
| 18006 | if (sliceable.type() instanceof torch.TupleType) { |
| 18007 | return new torch._C.SimpleValue(this.emitTupleIndex(range, sv.asValue(val_range, this.method), idx)); |
| 18008 | } else if (sliceable.type().isSubtypeOf(torch.TensorType.get())) { |
| 18009 | return new torch._C.SimpleValue(this.emitMultidimSlicing(range, sliceable, subscript_exprs)); |
| 18010 | } |
| 18011 | return sv.getitem(range, this.method, idx, type_hint); |
| 18012 | } |
| 18013 | }); |
| 18014 | this.registerType('torch.jit.CompilationUnit', class { |
no test coverage detected