(data)
| 142 | } |
| 143 | |
| 144 | renderHeadline(data) { |
| 145 | if (data === null) { |
| 146 | return "None"; |
| 147 | } |
| 148 | if (typeof(data) == "boolean") { |
| 149 | const sd = String(data); |
| 150 | return sd.charAt(0).toUpperCase() + sd.slice(1); |
| 151 | } |
| 152 | if (typeof(data) == "number") { |
| 153 | return JSON.stringify(data); |
| 154 | } |
| 155 | if (typeof(data) == "string") { |
| 156 | return JSON.stringify(data); |
| 157 | } |
| 158 | if (typeof(data) != "object") { |
| 159 | throw new Error("Not an object"); |
| 160 | } |
| 161 | if (Array.isArray(data)) { |
| 162 | return "list(["; |
| 163 | } |
| 164 | if (data.__tuple_values__) { |
| 165 | return "tuple(("; |
| 166 | } |
| 167 | if (data.__is_dict__) { |
| 168 | return "dict({"; |
| 169 | } |
| 170 | if (data.__module_type__) { |
| 171 | return data.__module_type__ + "()"; |
| 172 | } |
| 173 | if (data.__tensor_v2__) { |
| 174 | const [storage, offset, size, stride, grad] = data.__tensor_v2__; |
| 175 | const [dtype, key, device, numel] = storage; |
| 176 | return this.renderTensor( |
| 177 | "tensor", dtype, key, device, numel, offset, size, stride, grad, []); |
| 178 | } |
| 179 | if (data.__qtensor__) { |
| 180 | const [storage, offset, size, stride, quantizer, grad] = data.__qtensor__; |
| 181 | const [dtype, key, device, numel] = storage; |
| 182 | let extra_parts = []; |
| 183 | if (quantizer[0] == "per_tensor_affine") { |
| 184 | extra_parts.push(`scale=${quantizer[1]}`); |
| 185 | extra_parts.push(`zero_point=${quantizer[2]}`); |
| 186 | } else { |
| 187 | extra_parts.push(`quantizer=${quantizer[0]}`); |
| 188 | } |
| 189 | return this.renderTensor( |
| 190 | "qtensor", dtype, key, device, numel, offset, size, stride, grad, extra_parts); |
| 191 | } |
| 192 | throw new Error("Can't handle data type.", data); |
| 193 | } |
| 194 | |
| 195 | renderTensor( |
| 196 | prefix, |
no test coverage detected