Skip to content

Commit

Permalink
revised constant.js
Browse files Browse the repository at this point in the history
  • Loading branch information
mei1127 committed Jan 10, 2024
1 parent 978bc00 commit 3925196
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

import {cast} from './cast.js';
import {Tensor, sizeOfShape} from '../src/lib/tensor.js';

/**
* Create a constant array of specified data type and shape,
* which contains data incrementing by step.
* @param {Number} start
* @param {Number} step
* @param {Array} outputShape
* @param {string} type
* @return {Tensor}
*/

export function constant(start, step, outputShape, type = 'float32') {
const outputElementCount = sizeOfShape(outputShape);
const resultArray = [];
const data = [];
for (let i = 0; i < outputElementCount; i++) {
resultArray.push(start + i * step);
data.push(start + i * step);
}
const resultToTensor = new Tensor(outputShape, resultArray);
const output = cast(resultToTensor, type);
return output;
const tensor = new Tensor(outputShape, data);
return cast(tensor, type);
}

0 comments on commit 3925196

Please sign in to comment.