MCPcopy Index your code
hub / github.com/lutzroeder/netron / tolist

Method tolist

source/python.js:3260–3321  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3258 return this.data;
3259 }
3260 tolist() {
3261 if (this.shape.length < 0 || this.shape.length > 1) {
3262 throw new python.Error(`Unsupported shape '${JSON.stringify(this.shape)}'.`);
3263 }
3264 const size = this.shape.reduce((a, b) => a * b, 1);
3265 const list = new Array(size);
3266 switch (this.dtype.kind) {
3267 case 'U': {
3268 const data = new Uint32Array(new Uint8Array(this.data).buffer);
3269 const itemsize = this.dtype.itemsize >> 2;
3270 let offset = 0;
3271 for (let i = 0; i < size; i++) {
3272 const buffer = data.subarray(offset, offset + itemsize);
3273 const index = buffer.indexOf(0);
3274 list[i] = Array.from(index >= 0 ? buffer.subarray(0, index) : buffer).map((c) => String.fromCodePoint(c)).join('');
3275 offset += itemsize;
3276 }
3277 return list;
3278 }
3279 case 'S': {
3280 const data = this.data;
3281 const itemsize = this.dtype.itemsize;
3282 const decoder = new TextDecoder('utf-8');
3283 let offset = 0;
3284 for (let i = 0; i < size; i++) {
3285 const buffer = data.subarray(offset, offset + itemsize);
3286 const index = buffer.indexOf(0);
3287 list[i] = decoder.decode(index >= 0 ? buffer.subarray(0, index) : buffer);
3288 offset += itemsize;
3289 }
3290 return list;
3291 }
3292 case 'V': {
3293 const itemsize = this.dtype.itemsize;
3294 let offset = 0;
3295 for (let i = 0; i < size; i++) {
3296 list[i] = this.data.slice(offset, offset + itemsize);
3297 offset += itemsize;
3298 }
3299 return list;
3300 }
3301 case 'M': {
3302 const itemsize = this.dtype.itemsize;
3303 let offset = 0;
3304 for (let i = 0; i < size; i++) {
3305 const buffer = this.data.slice(offset, offset + itemsize);
3306 list[i] = new numpy.datetime64(buffer);
3307 offset += itemsize;
3308 }
3309 return list;
3310 }
3311 case 'T': {
3312 return this.data;
3313 }
3314 case 'O': {
3315 return this.data;
3316 }
3317 default: {

Callers 7

constructorMethod · 0.80
__setstate__Method · 0.80
constructorMethod · 0.80
constructorMethod · 0.80
constructorMethod · 0.80
constructorMethod · 0.80
read_weights_numpyMethod · 0.80

Calls 6

mapMethod · 0.80
__reduce__Method · 0.80
itemsizeMethod · 0.80
decodeMethod · 0.45
storageMethod · 0.45
peekMethod · 0.45

Tested by

no test coverage detected