Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions web/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number>): NDArray {
view(shape: Array<number>, 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"),
);
}

/**
Expand Down