Skip to content

Commit

Permalink
[Web] Add dtype and offset for CreateView in runtime (#17028)
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlieFRuan authored May 26, 2024
1 parent 4f1e2df commit 27a3b90
Showing 1 changed file with 11 additions and 2 deletions.
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

0 comments on commit 27a3b90

Please sign in to comment.