Skip to content

Commit

Permalink
fixed typos
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Leao authored and Eduardo Leao committed Mar 30, 2024
1 parent 8065dfa commit 31ae73b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion assets/demo/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</div>

<div class="separator" id="right-separator" style="margin-top: 10px; display: block;">
<p style="display: block; font-size: 16px; color: #292929; margin-bottom: 25px;">Welcome to <b>JS-Torch's Web Demo</b>! You can choose the <b>Model Hyperparameters</b> on the left, set tme <b>Model Layers</b> on the right (number of layers and hidden dimension on each). </p>
<p style="display: block; font-size: 16px; color: #292929; margin-bottom: 25px;">Welcome to <b>JS-Torch's Web Demo</b>! You can choose the <b>Model Hyperparameters</b> on the left, set the <b>Model Layers</b> on the right (number of layers and hidden dimension on each). </p>
<ul>
<li>This model was trained on a <b>Dummy dataset</b>, composed of <b>randomly generated images</b>. </li>
<br>
Expand Down
92 changes: 46 additions & 46 deletions src/tensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

var torch = (function(exports){

// <<< Tensor class, holds n-dimentional tensors, and multiple useful methods >>> //
// <<< Tensor class, holds n-dimensional tensors, and multiple useful methods >>> //

class Tensor {
/**
* Creates new instance of the Tensor class.
* @param {object} data - Iterable containing the data to be stored in the Tensor.
* @param {boolean} requires_grad - Wether to keep track of this tensor's gradients.
* @param {boolean} requires_grad - Whether to keep track of this tensor's gradients.
*/
constructor(data, requires_grad=false) {
if (typeof data === 'object') {
Expand Down Expand Up @@ -132,9 +132,9 @@ var torch = (function(exports){
};

/**
* Gets the sum of the Tensor over a specified dimention.
* @param {number} dim - Dimention to sum over.
* @param {boolean} keepdims - Wether to keep dimentions of original tensor.
* Gets the sum of the Tensor over a specified dimension.
* @param {number} dim - Dimension to sum over.
* @param {boolean} keepdims - Whether to keep dimensions of original tensor.
* @returns {Tensor} - Final tensor.
*/
sum(dim=-1, keepdims=false) {
Expand All @@ -143,9 +143,9 @@ var torch = (function(exports){
};

/**
* Gets the mean of the Tensor over a specified dimention.
* @param {number} dim - Dimention to get mean over.
* @param {boolean} keepdims - Wether to keep dimentions of original tensor.
* Gets the mean of the Tensor over a specified dimension.
* @param {number} dim - Dimension to get mean over.
* @param {boolean} keepdims - Whether to keep dimensions of original tensor.
* @returns {Tensor} - Final tensor.
*/
mean(dim=-1, keepdims=false) {
Expand All @@ -154,9 +154,9 @@ var torch = (function(exports){
};

/**
* Gets the variance of the Tensor over a specified dimention.
* @param {number} dim - Dimention to get variance over.
* @param {boolean} keepdims - Wether to keep dimentions of original tensor.
* Gets the variance of the Tensor over a specified dimension.
* @param {number} dim - Dimension to get variance over.
* @param {boolean} keepdims - Whether to keep dimensions of original tensor.
* @returns {Tensor} - Final tensor.
*/
variance(dim=-1, keepdims=false) {
Expand Down Expand Up @@ -791,10 +791,10 @@ var torch = (function(exports){

class Sum {
/**
* Gets the sum of a Tensor over a specified dimention.
* Gets the sum of a Tensor over a specified dimension.
* @param {Tensor} a - Tensor to sum.
* @param {dim} dim - Dimention to sum over.
* @param {keepdims} keepdims - Wether to keep dimentions of original tensor.
* @param {dim} dim - Dimension to sum over.
* @param {keepdims} keepdims - Whether to keep dimensions of original tensor.
* @returns {Tensor} - Final tensor.
*/
forward(a, dim, keepdims=false) {
Expand All @@ -805,7 +805,7 @@ var torch = (function(exports){
if (dim < 0) {
dim = a.shape.length + dim;
};
// Return error if dimention is out of bounds:
// Return error if dimension is out of bounds:
if (dim >= a.shape.length) {
throw Error('Dimension larger than array.')
};
Expand Down Expand Up @@ -845,18 +845,18 @@ var torch = (function(exports){

class Mean {
/**
* Gets the mean of a Tensor over a specified dimention.
* Gets the mean of a Tensor over a specified dimension.
* @param {Tensor} a - Tensor to get mean from.
* @param {dim} dim - Dimention to get mean over.
* @param {keepdims} keepdims - Wether to keep dimentions of original tensor.
* @param {dim} dim - Dimension to get mean over.
* @param {keepdims} keepdims - Whether to keep dimensions of original tensor.
* @returns {Tensor} - Final tensor.
*/
forward(a, dim, keepdims=false) {
// Account for negative dimension index:
if (dim < 0) {
dim = a.shape.length + dim;
};
// Return error if dimention is out of bounds:
// Return error if dimension is out of bounds:
if (dim >= a.shape.length) {
throw Error('Dimension larger than array.')
};
Expand Down Expand Up @@ -897,18 +897,18 @@ var torch = (function(exports){

class Variance {
/**
* Gets the variance of a Tensor over a specified dimention.
* Gets the variance of a Tensor over a specified dimension.
* @param {Tensor} a - Tensor to get variance of.
* @param {dim} dim - Dimention to get variance over.
* @param {keepdims} keepdims - Wether to keep dimentions of original tensor.
* @param {dim} dim - Dimension to get variance over.
* @param {keepdims} keepdims - Whether to keep dimensions of original tensor.
* @returns {Tensor} - Final tensor.
*/
forward(a, dim, keepdims=false) {
// Account for negative dimension index:
if (dim < 0) {
dim = a.shape.length + dim;
};
// Return error if dimention is out of bounds:
// Return error if dimension is out of bounds:
if (dim >= a.shape.length) {
throw Error('Dimension larger than array.');
};
Expand Down Expand Up @@ -1131,32 +1131,32 @@ var torch = (function(exports){
// <<< Tensor Operation Aliases >>> //

/**
* Gets the sum of the Tensor over a specified dimention.
* Gets the sum of the Tensor over a specified dimension.
* @param {Tensor} a - Original Tensor.
* @param {number} dim - Dimention to sum over.
* @param {boolean} keepdims - Wether to keep dimentions of original tensor.
* @param {number} dim - Dimension to sum over.
* @param {boolean} keepdims - Whether to keep dimensions of original tensor.
* @returns {Tensor} - Final tensor.
*/
function sum(a, dim=-1, keepdims=false) {
return a.sum(dim, keepdims);
};

/**
* Gets the mean of the Tensor over a specified dimention.
* Gets the mean of the Tensor over a specified dimension.
* @param {Tensor} a - Original Tensor.
* @param {number} dim - Dimention to get mean over.
* @param {boolean} keepdims - Wether to keep dimentions of original tensor.
* @param {number} dim - Dimension to get mean over.
* @param {boolean} keepdims - Whether to keep dimensions of original tensor.
* @returns {Tensor} - Final tensor.
*/
function mean(a, dim=-1, keepdims=false) {
return a.mean(dim, keepdims);
};

/**
* Gets the variance of the Tensor over a specified dimention.
* Gets the variance of the Tensor over a specified dimension.
* @param {Tensor} a - Original Tensor.
* @param {number} dim - Dimention to get variance over.
* @param {boolean} keepdims - Wether to keep dimentions of original tensor.
* @param {number} dim - Dimension to get variance over.
* @param {boolean} keepdims - Whether to keep dimensions of original tensor.
* @returns {Tensor} - Final tensor.
*/
function variance(a, dim=-1, keepdims=false) {
Expand Down Expand Up @@ -1328,7 +1328,7 @@ var torch = (function(exports){
function _sum(a, dim, keepdims) {

// In recursive call, when depth increases, subtract one from dim.
// When we reach the dimention intended (dim === 0),
// When we reach the dimension intended (dim === 0),
// we add all elements in this dimension.
if ( dim == 0 ) {
let sum = a.reduce((a,b) => _add(a, b), 0);
Expand All @@ -1347,7 +1347,7 @@ var torch = (function(exports){
function _mean(a, dim, keepdims) {

// In recursive call, when depth increases, subtract one from dim.
// When we reach the dimention intended (dim === 0),
// When we reach the dimension intended (dim === 0),
// we add all elements in this dimension.
if ( dim == 0 ) {
let reduced = _div(a.reduce((a,b) => _add(a, b), 0), a.length);
Expand All @@ -1366,7 +1366,7 @@ var torch = (function(exports){
function _variance(a, dim, keepdims) {

// In recursive call, when depth increases, subtract one from dim.
// When we reach the dimention intended (dim === 0),
// When we reach the dimension intended (dim === 0),
// we add all elements in this dimension.
if ( dim == 0 ) {
// Get mean over current dim:
Expand Down Expand Up @@ -1744,7 +1744,7 @@ var torch = (function(exports){
/**
* Creates new instance of the Tensor class.
* @param {object} data - Iterable containing the data to be stored in the Tensor.
* @param {boolean} requires_grad - Wether to keep track of this tensor's gradients.
* @param {boolean} requires_grad - Whether to keep track of this tensor's gradients.
* @returns {object} New tensor.
*/
function tensor(data, requires_grad=false) {
Expand All @@ -1754,7 +1754,7 @@ var torch = (function(exports){
/**
* Creates new instance of the Tensor class filled with only zeros.
* @param {object} shape - List containing the shape of the new tensor Tensor.
* @param {boolean} requires_grad - Wether to keep track of this tensor's gradients.
* @param {boolean} requires_grad - Whether to keep track of this tensor's gradients.
* @returns {object} New tensor.
*/
function zeros(shape, requires_grad=false) {
Expand All @@ -1764,7 +1764,7 @@ var torch = (function(exports){
/**
* Creates new instance of the Tensor class filled with only ones.
* @param {object} shape - List containing the shape of the new tensor Tensor.
* @param {boolean} requires_grad - Wether to keep track of this tensor's gradients.
* @param {boolean} requires_grad - Whether to keep track of this tensor's gradients.
* @returns {object} New tensor.
*/
function ones(shape, requires_grad=false) {
Expand All @@ -1774,7 +1774,7 @@ var torch = (function(exports){
/**
* Creates new instance of a lower-triangular 2D Tensor.
* @param {object} shape - List containing the shape of the new tensor Tensor.
* @param {boolean} requires_grad - Wether to keep track of this tensor's gradients.
* @param {boolean} requires_grad - Whether to keep track of this tensor's gradients.
* @returns {object} New tensor.
*/
function tril(shape, requires_grad=false) {
Expand All @@ -1793,7 +1793,7 @@ var torch = (function(exports){
/**
* Creates new instance of the Tensor class filled with numbers in a uniform distribution in ]0,1[.
* @param {object} shape - List containing the shape of the new tensor Tensor.
* @param {boolean} requires_grad - Wether to keep track of this tensor's gradients.
* @param {boolean} requires_grad - Whether to keep track of this tensor's gradients.
* @returns {object} New tensor.
*/
function rand(shape, requires_grad=false) {
Expand All @@ -1803,8 +1803,8 @@ var torch = (function(exports){
/**
* Creates new instance of the Tensor class filled with numbers in a normal distribution.
* @param {object} shape - List containing the shape of the new tensor Tensor.
* @param {boolean} requires_grad - Wether to keep track of this tensor's gradients.
* @param {boolean} xavier - Wether to use xavier initialization (divide by square root of first input dimension).
* @param {boolean} requires_grad - Whether to keep track of this tensor's gradients.
* @param {boolean} xavier - Whether to use xavier initialization (divide by square root of first input dimension).
* @returns {object} New tensor.
*/
function randn(shape, requires_grad=false, xavier=false,) {
Expand All @@ -1827,7 +1827,7 @@ var torch = (function(exports){
* @param {number} low - Lowest number that can be sampled.
* @param {number} high - One above highest number that can be sampled.
* @param {object} shape - List containing the shape of the new tensor Tensor.
* @param {boolean} requires_grad - Wether to keep track of this tensor's gradients.
* @param {boolean} requires_grad - Whether to keep track of this tensor's gradients.
* @returns {object} New tensor.
*/
function randint(low=0, high=1, shape=[1,], requires_grad=false) {
Expand Down Expand Up @@ -1908,10 +1908,10 @@ var torch = (function(exports){
function _broadcastSideways (out, b) {
if (b.length != out.length) {
if (b.length === 1){
// Base case, contract existing dimention:
// Base case, contract existing dimension:
return [_sum(out, 0),];
} else if (out.length === 1){
// Base case, expand existing dimention:
// Base case, expand existing dimension:
emptyArray = Array(b.length).fill(zeros);
return emptyArray.map(() => out[0]);
} else { Error(`Shapes ${utils.getShape(out)} and ${utils.getShape(b)} not broadcastable.`) };
Expand Down Expand Up @@ -1950,7 +1950,7 @@ var torch = (function(exports){
function broadcastUp (inElement, outElement) {
function _broadcastUp (inElement, outElement) {
if (utils.getShape(inElement).length + 1 === utils.getShape(outElement).length) {
// Base case, create new dimention:
// Base case, create new dimension:
emptyArray = Array(outElement.length).fill(zeros);
return emptyArray.map(() => inElement);
} else {
Expand Down

0 comments on commit 31ae73b

Please sign in to comment.