(module, resource)
| 16119 | this.zip_reader = reader; |
| 16120 | } |
| 16121 | load_pickle(module, resource) { |
| 16122 | const name = `${module.replace(/\./, '/')}/${resource}`; |
| 16123 | const stream = this.zip_reader.get_record(name); |
| 16124 | const loaded_reduces = new Map(); |
| 16125 | this.storage_context = new torch._C.DeserializationStorageContext(); |
| 16126 | const unpickler = new pickle.Unpickler(stream); |
| 16127 | unpickler.persistent_load = (saved_id) => { |
| 16128 | switch (saved_id[0]) { |
| 16129 | case 'storage': { |
| 16130 | const [, storage_type, key, , size] = saved_id; |
| 16131 | if (!this.storage_context.has_storage(key)) { |
| 16132 | const storage = new storage_type(size); |
| 16133 | if (!storage._set_cdata) { |
| 16134 | throw new python.Error(`'${storage_type.__name__}._set_cdata' is not a function.`); |
| 16135 | } |
| 16136 | const stream = this.zip_reader.get_record(`.data/${key}.storage`); |
| 16137 | const buffer = stream.peek(); |
| 16138 | storage._set_cdata(buffer); |
| 16139 | this.storage_context.add_storage(key, storage); |
| 16140 | } |
| 16141 | return this.storage_context.get_storage(key); |
| 16142 | } |
| 16143 | case 'reduce_package': { |
| 16144 | if (saved_id.length === 2) { |
| 16145 | const [, func, args] = saved_id; |
| 16146 | return execution.invoke(func, args); |
| 16147 | } |
| 16148 | const [, reduce_id, func, args] = saved_id; |
| 16149 | if (!loaded_reduces.has(reduce_id)) { |
| 16150 | const value = execution.invoke(func, [this].concat(args)); |
| 16151 | loaded_reduces.set(reduce_id, value); |
| 16152 | } |
| 16153 | return loaded_reduces.get(reduce_id); |
| 16154 | } |
| 16155 | default: { |
| 16156 | throw new python.Error(`Unknown package typename '${saved_id[0]}'.`); |
| 16157 | } |
| 16158 | } |
| 16159 | }; |
| 16160 | const obj = unpickler.load(); |
| 16161 | this.storage_context = null; |
| 16162 | return obj; |
| 16163 | } |
| 16164 | import_module(name) { |
| 16165 | return execution.import(name); |
| 16166 | } |
no test coverage detected