(qualified_name, enum_def)
| 13842 | this._cu.define(qualified_classname, [], [], methods, method_resolvers, self, false, this._version); |
| 13843 | } |
| 13844 | importEnum(qualified_name, enum_def) { |
| 13845 | const names_values = []; |
| 13846 | let value_type = null; |
| 13847 | const set_or_check_type = (t) => { |
| 13848 | if (!value_type) { |
| 13849 | value_type = t; |
| 13850 | } else if (value_type !== t) { |
| 13851 | throw new python.Error('Enum class with varying value types are not supported.'); |
| 13852 | } |
| 13853 | }; |
| 13854 | for (const stmt of enum_def.body) { |
| 13855 | if (stmt instanceof ast.Assign === false) { |
| 13856 | throw new python.Error('Unexpected statement in Enum class body.'); |
| 13857 | } |
| 13858 | const assign = stmt; |
| 13859 | const name = assign.targets[0].id; |
| 13860 | let ivalue = null; |
| 13861 | const rhs = assign.value; |
| 13862 | switch (rhs.type) { |
| 13863 | case 'str': |
| 13864 | ivalue = new torch._C.IValue(rhs.value, 'String'); |
| 13865 | set_or_check_type(torch.StringType.get()); |
| 13866 | break; |
| 13867 | case 'int': |
| 13868 | ivalue = new torch._C.IValue(rhs.value, 'Int'); |
| 13869 | set_or_check_type(torch.IntType.get()); |
| 13870 | break; |
| 13871 | case 'float': |
| 13872 | ivalue = new torch._C.IValue(rhs.value, 'Double'); |
| 13873 | set_or_check_type(torch.FloatType.get()); |
| 13874 | break; |
| 13875 | default: |
| 13876 | throw new python.Error(`Unsupported enum value type '${rhs.type}'.`); |
| 13877 | } |
| 13878 | names_values.push([name, ivalue]); |
| 13879 | } |
| 13880 | if (!value_type) { |
| 13881 | throw new python.Error('No enum values defined.'); |
| 13882 | } |
| 13883 | const enum_type = torch.EnumType.create(qualified_name, value_type, names_values, this._cu); |
| 13884 | this._cu.register_type(enum_type); |
| 13885 | } |
| 13886 | importNamedTuple(qualified_name, named_tuple_def) { |
| 13887 | const type_parser = new torch._C.ScriptTypeParser(this); |
| 13888 | const field_names = []; |
no test coverage detected