(handle: Pointer, lib: FFILibrary, ctx: RuntimeContext, isView: boolean)
| 518 | private dlDataType: DLDataType; |
| 519 | |
| 520 | constructor(handle: Pointer, lib: FFILibrary, ctx: RuntimeContext, isView: boolean) { |
| 521 | // if the array is a view, we need to create a new object with a null handle |
| 522 | // so dispose won't trigger memory free |
| 523 | const objectHandle = isView ? 0 : handle; |
| 524 | super(objectHandle, lib, ctx); |
| 525 | this.isView = isView; |
| 526 | if (this.isView) { |
| 527 | this.dltensor = handle; |
| 528 | } else { |
| 529 | this.dltensor = this.getDLTensorFromArrayHandle(this.handle); |
| 530 | } |
| 531 | // constant offsets. |
| 532 | const arrayOffsetData = 0; |
| 533 | const arrayOffsetContext = arrayOffsetData + this.lib.sizeofPtr(); |
| 534 | const arrayOffsetDevType = arrayOffsetContext; |
| 535 | const arrayOffsetDevId = arrayOffsetContext + SizeOf.I32; |
| 536 | const arrayOffsetNdim = arrayOffsetContext + SizeOf.DLDevice; |
| 537 | const arrayOffsetDtype = arrayOffsetNdim + SizeOf.I32; |
| 538 | const arrayOffsetDtypeCode = arrayOffsetDtype; |
| 539 | const arrayOffsetDtypeBits = arrayOffsetDtype + SizeOf.U8; |
| 540 | const arrayOffsetDtypeLanes = arrayOffsetDtypeBits + SizeOf.U8; |
| 541 | const arrayOffsetShape = arrayOffsetDtype + SizeOf.DLDataType; |
| 542 | const arrayOffsetStrides = arrayOffsetShape + this.lib.sizeofPtr(); |
| 543 | const arrayOffsetByteOffset = arrayOffsetStrides + this.lib.sizeofPtr(); |
| 544 | // dataPtr |
| 545 | this.dataPtr = lib.memory.loadPointer(this.dltensor); |
| 546 | // ndim |
| 547 | this.ndim = lib.memory.loadI32(this.dltensor + arrayOffsetNdim); |
| 548 | // shape |
| 549 | const cshapePtr = lib.memory.loadPointer(this.dltensor + arrayOffsetShape); |
| 550 | this.shape = []; |
| 551 | for (let i = 0; i < this.ndim; ++i) { |
| 552 | this.shape.push(lib.memory.loadI64(cshapePtr + i * SizeOf.I64)); |
| 553 | } |
| 554 | // dtype |
| 555 | const code = lib.memory.loadU8(this.dltensor + arrayOffsetDtypeCode); |
| 556 | const bits = lib.memory.loadU8(this.dltensor + arrayOffsetDtypeBits); |
| 557 | const lanes = lib.memory.loadU16(this.dltensor + arrayOffsetDtypeLanes); |
| 558 | this.dlDataType = new DLDataType(code, bits, lanes); |
| 559 | this.dtype = this.dlDataType.toString(); |
| 560 | |
| 561 | // device |
| 562 | const deviceType = lib.memory.loadI32(this.dltensor + arrayOffsetDevType); |
| 563 | const deviceId = lib.memory.loadI32(this.dltensor + arrayOffsetDevId); |
| 564 | this.device = new DLDevice(deviceType, deviceId, lib); |
| 565 | |
| 566 | // byte_offset |
| 567 | this.byteOffset = lib.memory.loadI64(this.dltensor + arrayOffsetByteOffset); |
| 568 | } |
| 569 | |
| 570 | /** |
| 571 | * Create a view of the array. |
nothing calls this directly
no test coverage detected