diff --git a/web/src/runtime.ts b/web/src/runtime.ts index 080003b4f0a9..fd7bcc6ab23b 100644 --- a/web/src/runtime.ts +++ b/web/src/runtime.ts @@ -519,11 +519,20 @@ export class NDArray implements Disposable { /** * Create a view of the array. * @param shape The shape of the view. + * @param dtype The data type of the new array. * @returns The new sliced ndarray. */ - view(shape: Array): NDArray { + view(shape: Array, dtype?: string): NDArray { const shapeArray = shape.map((value) => new Scalar(value, "int")); - return this.ctx.ndarrayCreateView(this, this.ctx.makeShapeTuple(...shapeArray)); + if (dtype === undefined) { + dtype = this.dtype; + } + return this.ctx.ndarrayCreateView( + this, + this.ctx.makeShapeTuple(...shapeArray), + this.dtype, + /*relative_byte_offset=*/ new Scalar(0, "int"), + ); } /**