@@ -8428,7 +8428,7 @@ python.Execution = class {
8428
8428
insertNode(node) {
8429
8429
return node.insertBefore(this._insert_before);
8430
8430
}
8431
- insertConstant(val) {
8431
+ insertConstant(val, loc ) {
8432
8432
const n = this.create('prim::Constant');
8433
8433
this.insertNode(n);
8434
8434
let type = null;
@@ -8442,22 +8442,29 @@ python.Execution = class {
8442
8442
n.ss_('value', val);
8443
8443
type = torch.ListType.create(torch.StringType.get());
8444
8444
} else if (typeof val === 'boolean') {
8445
- // return value;
8446
8445
n.i_('value', val === true ? 1 : 0);
8447
8446
type = torch.BoolType.get();
8448
8447
} else if (Number.isInteger(val)) {
8449
8448
n.i_('value', val);
8450
8449
type = torch.IntType.get();
8451
8450
} else if (typeof val === 'number') {
8452
- // return value;
8453
8451
n.f_('value', val);
8454
8452
type = torch.FloatType.get();
8453
+ } else if (val instanceof torch.Tensor) {
8454
+ n.t_('value', val);
8455
+ type = torch.TensorType.get();
8456
+ } else if (val instanceof torch.ScriptObject) {
8457
+ n.ival_('value', val);
8458
+ type = val.type();
8455
8459
} else {
8456
8460
throw new python.Error(`Unsupported value type '${typeof value}'.`);
8457
8461
}
8458
8462
if (type) {
8459
8463
n.output().setType(type);
8460
8464
}
8465
+ if (loc) {
8466
+ n.setSourceRange(loc);
8467
+ }
8461
8468
return n.output();
8462
8469
}
8463
8470
insertMethodCall(method_name, matched) {
@@ -8768,6 +8775,12 @@ python.Execution = class {
8768
8775
f(name) {
8769
8776
return this._values.get(name)[0];
8770
8777
}
8778
+ t_(name, value) {
8779
+ this._values.set(name, [value, 't']);
8780
+ }
8781
+ t(name) {
8782
+ return this._values.get(name)[0];
8783
+ }
8771
8784
tys_(name, value) {
8772
8785
this._values.set(name, [value, 'tys']);
8773
8786
}
@@ -8860,9 +8873,10 @@ python.Execution = class {
8860
8873
this._type = type;
8861
8874
}
8862
8875
set value(value) { // remove
8863
- if (value instanceof torch.Value === false ) {
8864
- this._value = value;
8876
+ if (value instanceof torch.Value) {
8877
+ throw new python.Error('Value cannot be a value.') ;
8865
8878
}
8879
+ this._value = value;
8866
8880
}
8867
8881
get value() { // remove
8868
8882
return this._value;
0 commit comments